Search in sources :

Example 1 with MethodCall

use of org.evosuite.testcase.execution.MethodCall in project evosuite by EvoSuite.

the class DefUseExecutionTraceAnalyzer method printFinishCalls.

/**
 * Prints all information found concerning finished calls of the given
 * ExecutionTrace
 *
 * @param trace
 *            a {@link org.evosuite.testcase.execution.ExecutionTrace} object.
 */
public static void printFinishCalls(ExecutionTrace trace) {
    for (MethodCall call : trace.getMethodCalls()) {
        System.out.println("Found MethodCall for: " + call.methodName + " on object " + call.callingObjectID);
        System.out.println("#passed branches: " + call.branchTrace.size());
        for (int i = 0; i < call.defuseCounterTrace.size(); i++) {
            System.out.println(i + ". at Branch " + call.branchTrace.get(i) + " true_dist: " + call.trueDistanceTrace.get(i) + " false_dist: " + call.falseDistanceTrace.get(i) + " duCounter: " + call.defuseCounterTrace.get(i));
            System.out.println();
        }
    }
}
Also used : MethodCall(org.evosuite.testcase.execution.MethodCall)

Example 2 with MethodCall

use of org.evosuite.testcase.execution.MethodCall in project evosuite by EvoSuite.

the class RegressionSuiteFitness method getBranchDistance.

/*
   * Get the distance of two branches given two method calls
   * 
   * @deprecated This function isn't in use anymore...
   */
private void getBranchDistance(List<MethodCall> methodCallsOrig, List<MethodCall> methodCallsReg) {
    for (int i = 0, j = 0; i < methodCallsOrig.size() && j < methodCallsReg.size(); ) {
        MethodCall mO = methodCallsOrig.get(i);
        MethodCall mR = methodCallsReg.get(j);
        if (mO.methodName.equals(mR.methodName)) {
            // logger.warn("mO is mR: " + mO.methodName);
            List<Integer> branchesO = mO.branchTrace;
            List<Integer> branchesR = mR.branchTrace;
            for (int k = 0, l = 0; k < branchesO.size() && l < branchesR.size(); ) {
                Integer branchO = branchesO.get(k);
                Integer branchR = branchesR.get(l);
                if (Properties.REGRESSION_DIFFERENT_BRANCHES) {
                    logger.error("Regression_differrent_branches has been deprecated and removed from Evosuite. Please disable the property and try again");
                    if (branchIdMap.containsKey(branchO)) {
                        branchR = branchIdMap.get(branchO);
                    } else {
                        if ((Objects.equals(branchO, branchR))) {
                            k++;
                        }
                        l++;
                        continue;
                    }
                }
                if (Objects.equals(branchO, branchR)) {
                    double trueDisO = normalize(mO.trueDistanceTrace.get(k));
                    double trueDisR = normalize(mR.trueDistanceTrace.get(l));
                    double falseDisO = normalize(mO.falseDistanceTrace.get(k));
                    double falseDisR = normalize(mR.falseDistanceTrace.get(l));
                    double tempBranchDistance = 2.0 * (1 - (Math.abs(trueDisO - trueDisR) + Math.abs(falseDisO - falseDisR)));
                    tempBranchDistance += (Math.abs(trueDisR) + Math.abs(falseDisR)) / 2.0;
                    tempBranchDistance += (Math.abs(trueDisO) + Math.abs(falseDisO)) / 2.0;
                    if ((trueDisO == 0 && falseDisR == 0) || (falseDisO == 0 && trueDisR == 0)) {
                        tempBranchDistance = 0;
                    }
                    if (!branchDistanceMap.containsKey(branchO) || branchDistanceMap.get(branchO) > tempBranchDistance) {
                        branchDistanceMap.put(branchO, tempBranchDistance);
                    }
                    k++;
                    l++;
                    continue;
                } else {
                    break;
                }
            }
            i++;
            j++;
            continue;
        } else if (mO.callDepth == 1 && mR.callDepth > 1) {
            j++;
            continue;
        } else if (mR.callDepth == 1 && mO.callDepth > 1) {
            i++;
            continue;
        } else {
            i++;
            j++;
        }
    }
}
Also used : MethodCall(org.evosuite.testcase.execution.MethodCall)

Example 3 with MethodCall

use of org.evosuite.testcase.execution.MethodCall in project evosuite by EvoSuite.

the class BranchCoverageTestFitness method getUnfitness.

/**
 * <p>
 * getUnfitness
 * </p>
 *
 * @param individual
 *            a {@link org.evosuite.testcase.ExecutableChromosome} object.
 * @param result
 *            a {@link org.evosuite.testcase.execution.ExecutionResult} object.
 * @return a double.
 */
public double getUnfitness(ExecutableChromosome individual, ExecutionResult result) {
    double sum = 0.0;
    boolean methodExecuted = false;
    for (MethodCall call : result.getTrace().getMethodCalls()) {
        if (call.className.equals(goal.getClassName()) && call.methodName.equals(goal.getMethodName())) {
            methodExecuted = true;
            if (goal.getBranch() != null) {
                for (int i = 0; i < call.branchTrace.size(); i++) {
                    if (call.branchTrace.get(i) == goal.getBranch().getInstruction().getInstructionId()) {
                        if (goal.getValue())
                            sum += call.falseDistanceTrace.get(i);
                        else
                            sum += call.trueDistanceTrace.get(i);
                    }
                }
            }
        }
    }
    if (goal.getBranch() == null) {
        // logger.info("Branch is null? " + goal.branch);
        if (goal.getValue())
            sum = methodExecuted ? 1.0 : 0.0;
        else
            sum = methodExecuted ? 0.0 : 1.0;
    }
    return sum;
}
Also used : MethodCall(org.evosuite.testcase.execution.MethodCall)

Example 4 with MethodCall

use of org.evosuite.testcase.execution.MethodCall 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)

Aggregations

MethodCall (org.evosuite.testcase.execution.MethodCall)4 ControlFlowDistance (org.evosuite.coverage.ControlFlowDistance)1