Search in sources :

Example 11 with RawControlFlowGraph

use of org.evosuite.graphs.cfg.RawControlFlowGraph in project evosuite by EvoSuite.

the class PrimePathInstrumentation method analyze.

/* (non-Javadoc)
	 * @see org.evosuite.cfg.MethodInstrumentation#analyze(org.objectweb.asm.tree.MethodNode, org.jgrapht.Graph, java.lang.String, java.lang.String, int)
	 */
/**
 * {@inheritDoc}
 */
@Override
public void analyze(ClassLoader classLoader, MethodNode mn, String className, String methodName, int access) {
    RawControlFlowGraph graph = GraphPool.getInstance(classLoader).getRawCFG(className, methodName);
    Queue<PrimePath> path_queue = new LinkedList<PrimePath>();
    for (BytecodeInstruction vertex : graph.vertexSet()) {
        if (graph.inDegreeOf(vertex) == 0) {
            PrimePath initial = new PrimePath(className, methodName);
            initial.append(vertex);
            path_queue.add(initial);
        }
    }
    while (!path_queue.isEmpty()) {
        PrimePath current = path_queue.poll();
        for (ControlFlowEdge edge : graph.outgoingEdgesOf(current.getLast())) {
            if (!current.contains(graph.getEdgeTarget(edge))) {
                PrimePath next = current.getAppended(graph.getEdgeTarget(edge));
                path_queue.add(next);
            }
        }
        if (current.getLast().isReturn() || current.getLast().isThrow()) {
            logger.warn("New path:");
            for (int i = 0; i < current.getSize(); i++) {
                if (current.get(i).isBranch() || current.get(i).isLabel())
                    logger.warn(" -> " + current.get(i));
            }
            logger.warn(current.toString());
            PrimePathPool.add(current);
        }
    }
    logger.info("Found " + PrimePathPool.getSize() + " prime paths");
}
Also used : ControlFlowEdge(org.evosuite.graphs.cfg.ControlFlowEdge) PrimePath(org.evosuite.coverage.path.PrimePath) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) LinkedList(java.util.LinkedList) RawControlFlowGraph(org.evosuite.graphs.cfg.RawControlFlowGraph)

Aggregations

RawControlFlowGraph (org.evosuite.graphs.cfg.RawControlFlowGraph)11 BytecodeInstruction (org.evosuite.graphs.cfg.BytecodeInstruction)9 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)4 LinkedList (java.util.LinkedList)2 ClassCallNode (org.evosuite.graphs.ccg.ClassCallNode)2 AnnotatedLabel (org.evosuite.runtime.instrumentation.AnnotatedLabel)2 InsnList (org.objectweb.asm.tree.InsnList)2 LabelNode (org.objectweb.asm.tree.LabelNode)2 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Branch (org.evosuite.coverage.branch.Branch)1 LineCoverageFactory (org.evosuite.coverage.line.LineCoverageFactory)1 LineCoverageTestFitness (org.evosuite.coverage.line.LineCoverageTestFitness)1 Mutation (org.evosuite.coverage.mutation.Mutation)1 PrimePath (org.evosuite.coverage.path.PrimePath)1