Search in sources :

Example 1 with ClassCallNode

use of org.evosuite.graphs.ccg.ClassCallNode in project evosuite by EvoSuite.

the class AllUsesAnalysis method preAnalyzeMethods.

/**
 * Checks if there are methods in the CCG that dont call any other methods
 * except for maybe itself. For these we can predetermine free uses and
 * activeDefs prior to looking for inter_method_pairs. After that we can
 * even repeat this process for methods we now have determined free uses and
 * activeDefs! that way you can save a lot of computation. Map activeDefs
 * and freeUses according to the variable so you can easily determine which
 * defs will be active and which uses are free once you encounter a
 * methodCall to that method without looking at its part of the CCFG
 */
private Set<DefUseCoverageTestFitness> preAnalyzeMethods() {
    // TODO after preanalyze, order the remaining methods as follows:
    // first order each method by the number of instructions within them in
    // ascending order. after that for each method check if there is a
    // method that calls this one and also has to be analyzed still. if you
    // find such a pair move the calling method in front of the called one
    Set<DefUseCoverageTestFitness> r = new HashSet<DefUseCoverageTestFitness>();
    LinkedList<ClassCallNode> toAnalyze = new LinkedList<ClassCallNode>();
    toAnalyze.addAll(getInitialPreAnalyzeableMethods());
    while (!toAnalyze.isEmpty()) {
        ClassCallNode currentMethod = toAnalyze.poll();
        CCFGMethodEntryNode analyzeableEntry = ccfg.getMethodEntryNodeForClassCallNode(currentMethod);
        if (analyzedMethods.contains(analyzeableEntry))
            continue;
        r.addAll(determineIntraInterMethodPairs(analyzeableEntry));
        // check if we can pre-analyze further methods now
        Set<ClassCallNode> parents = ccfg.getCcg().getParents(currentMethod);
        for (ClassCallNode parent : parents) {
            if (toAnalyze.contains(parent))
                // will be analyzed anyway
                continue;
            if (analyzedMethods.contains(ccfg.getMethodEntryNodeForClassCallNode(parent)))
                // was already analyzed
                continue;
            Set<ClassCallNode> parentsChildren = ccfg.getCcg().getChildren(parent);
            boolean canAnalyzeNow = true;
            for (ClassCallNode parentsChild : parentsChildren) {
                if (parentsChild == null)
                    continue;
                if (!parentsChild.equals(parent) && !(toAnalyze.contains(parentsChild) || analyzedMethods.contains(ccfg.getMethodEntryNodeForClassCallNode(parentsChild)))) {
                    // found child of parent that will not be pre-analyzed
                    canAnalyzeNow = false;
                    break;
                }
            }
            if (canAnalyzeNow) {
                toAnalyze.offer(parent);
            }
        }
    }
    return r;
}
Also used : CCFGFieldClassCallNode(org.evosuite.graphs.ccfg.CCFGFieldClassCallNode) ClassCallNode(org.evosuite.graphs.ccg.ClassCallNode) DefUseCoverageTestFitness(org.evosuite.coverage.dataflow.DefUseCoverageTestFitness) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) CCFGMethodEntryNode(org.evosuite.graphs.ccfg.CCFGMethodEntryNode)

Example 2 with ClassCallNode

use of org.evosuite.graphs.ccg.ClassCallNode in project evosuite by EvoSuite.

the class ClassControlFlowGraph method connectPublicMethodsToFrame.

/**
 * Adds a CCFGFrameEdge from the CCFGFrameNode CALL to the
 * CCFGMethodEntryNode of each public method and from their
 * CCFGMethodExitNode to the CCFGFrameNode RETURN.
 */
private void connectPublicMethodsToFrame() {
    for (ClassCallNode ccgNode : ccg.vertexSet()) {
        RawControlFlowGraph cfg = getRCFG(ccgNode);
        if (cfg.isPublicMethod()) {
            addEdge(getFrameNode(FrameNodeType.CALL), methodEntries.get(ccgNode.getMethod()), new CCFGFrameEdge());
            addEdge(methodExits.get(ccgNode.getMethod()), getFrameNode(FrameNodeType.RETURN), new CCFGFrameEdge());
            publicMethods.add(methodEntries.get(ccgNode.getMethod()));
        }
    }
}
Also used : ClassCallNode(org.evosuite.graphs.ccg.ClassCallNode) RawControlFlowGraph(org.evosuite.graphs.cfg.RawControlFlowGraph)

Example 3 with ClassCallNode

use of org.evosuite.graphs.ccg.ClassCallNode in project evosuite by EvoSuite.

the class ClassControlFlowGraph method importCFGs.

private void importCFGs() {
    Map<RawControlFlowGraph, Map<BytecodeInstruction, CCFGCodeNode>> tempMap = new HashMap<RawControlFlowGraph, Map<BytecodeInstruction, CCFGCodeNode>>();
    // replace each class call node with corresponding CFG
    for (ClassCallNode ccgNode : ccg.vertexSet()) {
        RawControlFlowGraph cfg = getRCFG(ccgNode);
        tempMap.put(cfg, importCFG(cfg));
    }
    connectCFGs(tempMap);
}
Also used : HashMap(java.util.HashMap) ClassCallNode(org.evosuite.graphs.ccg.ClassCallNode) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) HashMap(java.util.HashMap) Map(java.util.Map) RawControlFlowGraph(org.evosuite.graphs.cfg.RawControlFlowGraph)

Aggregations

ClassCallNode (org.evosuite.graphs.ccg.ClassCallNode)3 RawControlFlowGraph (org.evosuite.graphs.cfg.RawControlFlowGraph)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 DefUseCoverageTestFitness (org.evosuite.coverage.dataflow.DefUseCoverageTestFitness)1 CCFGFieldClassCallNode (org.evosuite.graphs.ccfg.CCFGFieldClassCallNode)1 CCFGMethodEntryNode (org.evosuite.graphs.ccfg.CCFGMethodEntryNode)1 BytecodeInstruction (org.evosuite.graphs.cfg.BytecodeInstruction)1