Search in sources :

Example 26 with BytecodeInstruction

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

the class PrimePath method condensate.

/**
 * <p>condensate</p>
 */
public void condensate() {
    for (int position = 0; position < nodes.size(); position++) {
        BytecodeInstruction node = nodes.get(position);
        if (node.isBranch() && position < (nodes.size() - 1)) {
            PathEntry entry = new PathEntry();
            entry.branch = BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchForInstruction(node);
            if (nodes.get(position + 1).getInstructionId() == (node.getInstructionId() + 1)) {
                logger.info("FALSE: Next ID is " + nodes.get(position + 1).getInstructionId() + " / " + (node.getInstructionId() + 1));
                entry.value = false;
            } else {
                logger.info("TRUE: Next ID is " + nodes.get(position + 1).getInstructionId() + " / " + (node.getInstructionId() + 1));
                entry.value = true;
            }
            branches.add(entry);
        }
    }
}
Also used : BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction)

Example 27 with BytecodeInstruction

use of org.evosuite.graphs.cfg.BytecodeInstruction 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)

Example 28 with BytecodeInstruction

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

the class LCSAJGraph method generate.

/**
 * <p>
 * generate
 * </p>
 *
 * @param file
 *            a {@link java.io.File} object.
 */
public void generate(File file) {
    if (fitnessGraph)
        System.out.println("Generating Graph for uncoverd LCSAJ No: " + lcsaj.getID() + " in " + lcsaj.getClassName() + "/" + lcsaj.getMethodName());
    else
        System.out.println("Generating Graph for LCSAJ No: " + lcsaj.getID() + " in " + lcsaj.getClassName() + "/" + lcsaj.getMethodName());
    Graph lcsaj_graph = new Graph();
    ArrayList<Node> allNodes = new ArrayList<Node>();
    for (BytecodeInstruction b : graph.vertexSet()) {
        Node n = new Node().attr("label", b.toString());
        lcsaj_graph = lcsaj_graph.node(n);
        allNodes.add(n);
    }
    for (ControlFlowEdge edge : graph.edgeSet()) for (Node source : allNodes) for (Node target : allNodes) {
        BytecodeInstruction b1 = graph.getEdgeSource(edge);
        BytecodeInstruction b2 = graph.getEdgeTarget(edge);
        if (source.attr("label").equals(b1.toString()) && target.attr("label").equals(b2.toString())) {
            if (b1.isBranch()) {
                Edge newEdge = new Edge(source, target).attr("label", edge.toString());
                lcsaj_graph.edge(newEdge);
            } else
                lcsaj_graph.edge(source, target);
        }
    }
    BytecodeInstruction l1 = lcsaj.getStartBranch().getInstruction();
    BytecodeInstruction l2 = lcsaj.getLastBranch().getInstruction();
    if (fitnessGraph)
        l2 = lcsaj.getBranch(lcsaj.getdPositionReached()).getInstruction();
    for (Node source : allNodes) for (Node target : allNodes) {
        if (source.attr("label").equals(l1.toString()) && target.attr("label").equals(l2.toString())) {
            if (!fitnessGraph || lcsaj.getdPositionReached() == lcsaj.length() - 1) {
                Edge newEdge = new Edge(source, target).attr("color", "green").attr("label", "LCSAJ No." + lcsaj.getID());
                lcsaj_graph.edge(newEdge);
            } else {
                Edge newEdge = new Edge(source, target).attr("color", "red").attr("label", " LCSAJ No." + lcsaj.getID() + ". Covered till:");
                lcsaj_graph.edge(newEdge);
            }
        }
    }
    ArrayList<String> commandos = new ArrayList<String>();
    commandos.add("dot");
    try {
        lcsaj_graph.generateTo(commandos, file);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Graph(org.kohsuke.graphviz.Graph) RawControlFlowGraph(org.evosuite.graphs.cfg.RawControlFlowGraph) ControlFlowEdge(org.evosuite.graphs.cfg.ControlFlowEdge) Node(org.kohsuke.graphviz.Node) ArrayList(java.util.ArrayList) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) IOException(java.io.IOException) Edge(org.kohsuke.graphviz.Edge) ControlFlowEdge(org.evosuite.graphs.cfg.ControlFlowEdge)

Aggregations

BytecodeInstruction (org.evosuite.graphs.cfg.BytecodeInstruction)28 RawControlFlowGraph (org.evosuite.graphs.cfg.RawControlFlowGraph)10 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)6 ControlDependency (org.evosuite.graphs.cfg.ControlDependency)5 InsnList (org.objectweb.asm.tree.InsnList)5 HashSet (java.util.HashSet)4 LabelNode (org.objectweb.asm.tree.LabelNode)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Branch (org.evosuite.coverage.branch.Branch)3 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 CCFGCodeNode (org.evosuite.graphs.ccfg.CCFGCodeNode)2 ControlDependenceGraph (org.evosuite.graphs.cdg.ControlDependenceGraph)2 BasicBlock (org.evosuite.graphs.cfg.BasicBlock)2 ControlFlowEdge (org.evosuite.graphs.cfg.ControlFlowEdge)2 AnnotatedLabel (org.evosuite.runtime.instrumentation.AnnotatedLabel)2 Label (org.objectweb.asm.Label)2 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)2