Search in sources :

Example 1 with CallGraph

use of org.evosuite.setup.callgraph.CallGraph in project evosuite by EvoSuite.

the class CBranchFitnessFactory method getCoverageGoals.

/* (non-Javadoc)
	 * @see org.evosuite.coverage.TestFitnessFactory#getCoverageGoals()
	 */
@Override
public List<CBranchTestFitness> getCoverageGoals() {
    // TODO this creates duplicate goals. Momentary fixed using a Set, but it should be optimised
    Set<CBranchTestFitness> goals = new HashSet<>();
    // retrieve set of branches
    BranchCoverageFactory branchFactory = new BranchCoverageFactory();
    List<BranchCoverageTestFitness> branchGoals = branchFactory.getCoverageGoals();
    CallGraph callGraph = DependencyAnalysis.getCallGraph();
    // try to find all occurrences of this branch in the call tree
    for (BranchCoverageTestFitness branchGoal : branchGoals) {
        logger.info("Adding context branches for " + branchGoal.toString());
        for (CallContext context : callGraph.getMethodEntryPoint(branchGoal.getClassName(), branchGoal.getMethod())) {
            goals.add(new CBranchTestFitness(branchGoal.getBranchGoal(), context));
        }
    }
    logger.info("Created " + goals.size() + " goals");
    return new ArrayList<CBranchTestFitness>(goals);
}
Also used : BranchCoverageTestFitness(org.evosuite.coverage.branch.BranchCoverageTestFitness) BranchCoverageFactory(org.evosuite.coverage.branch.BranchCoverageFactory) CallGraph(org.evosuite.setup.callgraph.CallGraph) ArrayList(java.util.ArrayList) CallContext(org.evosuite.setup.CallContext) HashSet(java.util.HashSet)

Example 2 with CallGraph

use of org.evosuite.setup.callgraph.CallGraph in project evosuite by EvoSuite.

the class IBranchFitnessFactory method getCoverageGoals.

/* (non-Javadoc)
	 * @see org.evosuite.coverage.TestFitnessFactory#getCoverageGoals()
	 */
@Override
public List<IBranchTestFitness> getCoverageGoals() {
    // TODO this creates duplicate goals. Momentary fixed using a Set.
    Set<IBranchTestFitness> goals = new HashSet<IBranchTestFitness>();
    // retrieve set of branches
    BranchCoverageFactory branchFactory = new BranchCoverageFactory();
    List<BranchCoverageTestFitness> branchGoals = branchFactory.getCoverageGoalsForAllKnownClasses();
    CallGraph callGraph = DependencyAnalysis.getCallGraph();
    // try to find all occurrences of this branch in the call tree
    for (BranchCoverageTestFitness branchGoal : branchGoals) {
        logger.info("Adding context branches for " + branchGoal.toString());
        for (CallContext context : callGraph.getAllContextsFromTargetClass(branchGoal.getClassName(), branchGoal.getMethod())) {
            // if is not possible to reach this branch from the target class, continue.
            if (context.isEmpty())
                continue;
            goals.add(new IBranchTestFitness(branchGoal.getBranchGoal(), context));
        }
    }
    assert (goals.size() >= branchFactory.getCoverageGoals().size());
    logger.info("Created " + goals.size() + " goals");
    return new ArrayList<IBranchTestFitness>(goals);
}
Also used : BranchCoverageTestFitness(org.evosuite.coverage.branch.BranchCoverageTestFitness) BranchCoverageFactory(org.evosuite.coverage.branch.BranchCoverageFactory) CallGraph(org.evosuite.setup.callgraph.CallGraph) ArrayList(java.util.ArrayList) CallContext(org.evosuite.setup.CallContext) HashSet(java.util.HashSet)

Example 3 with CallGraph

use of org.evosuite.setup.callgraph.CallGraph in project evosuite by EvoSuite.

the class DependencyAnalysis method analyze.

private static void analyze(String className, List<String> classPath) throws RuntimeException, ClassNotFoundException {
    if (!inheritanceTree.hasClass(Properties.TARGET_CLASS)) {
        throw new ClassNotFoundException("Target class not found in inheritance tree");
    }
    logger.debug("Calculate call tree");
    CallGraph callGraph = CallGraphGenerator.analyze(className);
    callGraphs.put(className, callGraph);
    loadCallTreeClasses(callGraph);
    // include all the project classes in the inheritance tree and in the callgraph.
    if (ArrayUtil.contains(Properties.CRITERION, Criterion.IBRANCH) || Properties.INSTRUMENT_CONTEXT) {
        for (String classn : inheritanceTree.getAllClasses()) {
            if (isTargetProject(classn)) {
                CallGraphGenerator.analyzeOtherClasses(callGraph, classn);
            }
        }
    }
    // TODO: Need to make sure that all classes in calltree are instrumented
    logger.debug("Update call tree with calls to overridden methods");
    CallGraphGenerator.update(callGraph, inheritanceTree);
    logger.debug("Create test cluster");
    // if a class is not instrumented but part of the callgraph, the
    // generateCluster method will instrument it
    // update: we instrument only classes reachable from the class
    // under test, the callgraph is populated with all classes, but only the
    // set of relevant ones are instrumented - mattia
    TestGenerationContext.getInstance().getTestClusterGenerator().generateCluster(callGraph);
    gatherStatistics();
}
Also used : CallGraph(org.evosuite.setup.callgraph.CallGraph)

Aggregations

CallGraph (org.evosuite.setup.callgraph.CallGraph)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 BranchCoverageFactory (org.evosuite.coverage.branch.BranchCoverageFactory)2 BranchCoverageTestFitness (org.evosuite.coverage.branch.BranchCoverageTestFitness)2 CallContext (org.evosuite.setup.CallContext)2