Search in sources :

Example 1 with ClassControlFlowGraph

use of org.evosuite.graphs.ccfg.ClassControlFlowGraph in project evosuite by EvoSuite.

the class DefUseCoverageFactory method categorizeFieldMethodCalls.

/**
 * Determines for all method calls on fields of the CUT whether the call is
 * to a pure or impure method. For these calls Uses and Definitions are
 * created respectively.
 *
 * Since purity analysis is used here and requires all classes along the
 * call tree to be completely analyzed this part of the CUT analysis can not
 * be done in the CFGMethodAdapter like the rest of it.
 */
private static void categorizeFieldMethodCalls() {
    Set<BytecodeInstruction> fieldMethodCalls = DefUsePool.retrieveFieldMethodCalls();
    LoggingUtils.getEvoLogger().info("Categorizing field method calls: " + fieldMethodCalls.size());
    for (BytecodeInstruction fieldMethodCall : fieldMethodCalls) {
        if (GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).canMakeCCFGForClass(fieldMethodCall.getCalledMethodsClass())) {
            ClassControlFlowGraph ccfg = GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getCCFG(fieldMethodCall.getCalledMethodsClass());
            if (ccfg.isPure(fieldMethodCall.getCalledMethod())) {
                if (!DefUsePool.addAsUse(fieldMethodCall))
                    throw new IllegalStateException("unable to register field method call as a use " + fieldMethodCall.toString());
            } else {
                if (!DefUsePool.addAsDefinition(fieldMethodCall))
                    throw new IllegalStateException("unable to register field method call as a definition " + fieldMethodCall.toString());
            }
        } else {
            String toAnalyze = fieldMethodCall.getCalledMethodsClass() + "." + fieldMethodCall.getCalledMethodName();
            if (toAnalyze != null && toAnalyze.startsWith("java.")) {
                Type[] parameters = org.objectweb.asm.Type.getArgumentTypes(fieldMethodCall.getMethodCallDescriptor());
                String newParams = "";
                if (parameters.length != 0) {
                    for (Type i : parameters) {
                        newParams = newParams + "," + i.getClassName();
                    }
                    newParams = newParams.substring(1, newParams.length());
                }
                toAnalyze = fieldMethodCall.getCalledMethodsClass() + "." + fieldMethodCall.getCalledMethodName() + "(" + newParams + ")";
                if (JdkPureMethodsList.instance.checkPurity(toAnalyze)) {
                    if (!DefUsePool.addAsUse(fieldMethodCall))
                        throw new IllegalStateException("unable to register field method call as a use " + fieldMethodCall.toString());
                } else {
                    if (!DefUsePool.addAsDefinition(fieldMethodCall))
                        throw new IllegalStateException("unable to register field method call as a definition " + fieldMethodCall.toString());
                }
            } else {
                if (!DefUsePool.addAsUse(fieldMethodCall))
                    throw new IllegalStateException("unable to register field method call as a use " + fieldMethodCall.toString());
            }
        }
    }
}
Also used : ClassControlFlowGraph(org.evosuite.graphs.ccfg.ClassControlFlowGraph) DefUsePairType(org.evosuite.coverage.dataflow.DefUseCoverageTestFitness.DefUsePairType) Type(org.objectweb.asm.Type) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction)

Example 2 with ClassControlFlowGraph

use of org.evosuite.graphs.ccfg.ClassControlFlowGraph in project evosuite by EvoSuite.

the class DefUseCoverageFactory method getCCFGPairs.

private static Set<DefUseCoverageTestFitness> getCCFGPairs() {
    ClassControlFlowGraph ccfg = GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getCCFG(Properties.TARGET_CLASS);
    AllUsesAnalysis aua = new AllUsesAnalysis(ccfg);
    Set<DefUseCoverageTestFitness> r = aua.determineDefUsePairs();
    return r;
}
Also used : AllUsesAnalysis(org.evosuite.coverage.dataflow.analysis.AllUsesAnalysis) ClassControlFlowGraph(org.evosuite.graphs.ccfg.ClassControlFlowGraph)

Example 3 with ClassControlFlowGraph

use of org.evosuite.graphs.ccfg.ClassControlFlowGraph in project evosuite by EvoSuite.

the class GraphPool method computeCCFG.

/**
 * Computes the CCFG for the given class
 *
 * If no CFG is known for the given class, an IllegalArgumentException is
 * thrown
 *
 * @param className
 *            a {@link java.lang.String} object.
 * @return a {@link org.evosuite.graphs.ccfg.ClassControlFlowGraph} object.
 */
private ClassControlFlowGraph computeCCFG(String className) {
    if (rawCFGs.get(className) == null)
        throw new IllegalArgumentException("can't compute CCFG, don't know CFGs for class " + className);
    ClassCallGraph ccg = new ClassCallGraph(classLoader, className);
    if (Properties.WRITE_CFG)
        ccg.toDot();
    ClassControlFlowGraph ccfg = new ClassControlFlowGraph(ccg);
    if (Properties.WRITE_CFG)
        ccfg.toDot();
    return ccfg;
}
Also used : ClassControlFlowGraph(org.evosuite.graphs.ccfg.ClassControlFlowGraph) ClassCallGraph(org.evosuite.graphs.ccg.ClassCallGraph)

Aggregations

ClassControlFlowGraph (org.evosuite.graphs.ccfg.ClassControlFlowGraph)3 DefUsePairType (org.evosuite.coverage.dataflow.DefUseCoverageTestFitness.DefUsePairType)1 AllUsesAnalysis (org.evosuite.coverage.dataflow.analysis.AllUsesAnalysis)1 ClassCallGraph (org.evosuite.graphs.ccg.ClassCallGraph)1 BytecodeInstruction (org.evosuite.graphs.cfg.BytecodeInstruction)1 Type (org.objectweb.asm.Type)1