Search in sources :

Example 6 with ControlFlowDistance

use of org.evosuite.coverage.ControlFlowDistance in project evosuite by EvoSuite.

the class ControlFlowDistanceCalculator method getNonRootDistance.

private static ControlFlowDistance getNonRootDistance(ExecutionResult result, Branch branch, boolean value) {
    if (branch == null)
        throw new IllegalStateException("expect this method only to be called if this goal does not try to cover the root branch");
    String className = branch.getClassName();
    String methodName = branch.getMethodName();
    ControlFlowDistance r = new ControlFlowDistance();
    r.setApproachLevel(branch.getInstruction().getActualCFG().getDiameter() + 1);
    // Minimal distance between target node and path
    for (MethodCall call : result.getTrace().getMethodCalls()) {
        if (call.className.equals(className) && call.methodName.equals(methodName)) {
            ControlFlowDistance d2;
            Set<Branch> handled = new HashSet<Branch>();
            // result.intermediateDistances = new HashMap<Branch,ControlFlowDistance>();
            d2 = getNonRootDistance(result, call, branch, value, className, methodName, handled);
            if (d2.compareTo(r) < 0) {
                r = d2;
            }
        }
    }
    return r;
}
Also used : ControlFlowDistance(org.evosuite.coverage.ControlFlowDistance) MethodCall(org.evosuite.testcase.execution.MethodCall)

Example 7 with ControlFlowDistance

use of org.evosuite.coverage.ControlFlowDistance in project evosuite by EvoSuite.

the class ControlFlowDistanceCalculator method getDistancesForControlDependentBranchesOf.

/**
 * Returns a set containing the ControlFlowDistances in the given result for
 * all branches the given instruction is control dependent on
 *
 * @param handled
 */
private static Set<ControlFlowDistance> getDistancesForControlDependentBranchesOf(ExecutionResult result, MethodCall call, BytecodeInstruction instruction, String className, String methodName, Set<Branch> handled) {
    Set<ControlFlowDistance> r = new HashSet<ControlFlowDistance>();
    Set<ControlDependency> nextToLookAt = instruction.getControlDependencies();
    for (ControlDependency next : nextToLookAt) {
        if (instruction.equals(next.getBranch().getInstruction()))
            // avoid loops
            continue;
        boolean nextValue = next.getBranchExpressionValue();
        ControlFlowDistance nextDistance = getNonRootDistance(result, call, next.getBranch(), nextValue, className, methodName, handled);
        assert (nextDistance != null);
        r.add(nextDistance);
    }
    if (r.isEmpty()) {
        // instruction only dependent on root branch
        // since this method is called by getNonRootDistance(MethodCall)
        // which in turn is only called when a MethodCall for this branch's
        // method was found in the given result, i can safely assume that
        // the 0-distance is a control dependence distance for the given
        // instruction ... right?
        r.add(new ControlFlowDistance());
    }
    return r;
}
Also used : ControlFlowDistance(org.evosuite.coverage.ControlFlowDistance) ControlDependency(org.evosuite.graphs.cfg.ControlDependency)

Aggregations

ControlFlowDistance (org.evosuite.coverage.ControlFlowDistance)7 BranchCoverageGoal (org.evosuite.coverage.branch.BranchCoverageGoal)1 ControlDependency (org.evosuite.graphs.cfg.ControlDependency)1 MethodCall (org.evosuite.testcase.execution.MethodCall)1