Search in sources :

Example 6 with Branch

use of org.evosuite.coverage.branch.Branch in project evosuite by EvoSuite.

the class ControlDependenceGraph method isDirectlyControlDependentOn.

/**
 * Determines whether the given BasicBlock is directly control dependent on
 * the given Branch. Meaning within this CDG there is an incoming
 * ControlFlowEdge to this instructions BasicBlock holding the given Branch
 * as it's branchInstruction.
 *
 * If b is null, it is assumed to be the root branch.
 *
 * If the given instruction is not known to this CDG an
 * IllegalArgumentException is thrown.
 *
 * @param insBlock a {@link org.evosuite.graphs.cfg.BasicBlock} object.
 * @param b a {@link org.evosuite.coverage.branch.Branch} object.
 * @return a boolean.
 */
public boolean isDirectlyControlDependentOn(BasicBlock insBlock, Branch b) {
    Set<ControlFlowEdge> incomming = incomingEdgesOf(insBlock);
    if (incomming.size() == 1) {
        for (ControlFlowEdge e : incomming) {
            if (!e.hasControlDependency() && !e.isExceptionEdge()) {
                return isDirectlyControlDependentOn(getEdgeSource(e), b);
            }
        }
    }
    boolean isRootDependent = isRootDependent(insBlock);
    if (b == null)
        return isRootDependent;
    if (isRootDependent && b != null)
        return false;
    for (ControlFlowEdge e : incomming) {
        Branch current = e.getBranchInstruction();
        if (e.isExceptionEdge()) {
            if (current != null)
                throw new IllegalStateException("expect exception edges to have no BranchInstruction set");
            else
                continue;
        }
        if (current == null)
            continue;
        if (current.equals(b))
            return true;
    }
    return false;
}
Also used : ControlFlowEdge(org.evosuite.graphs.cfg.ControlFlowEdge) Branch(org.evosuite.coverage.branch.Branch)

Example 7 with Branch

use of org.evosuite.coverage.branch.Branch in project evosuite by EvoSuite.

the class StatisticsSender method sendCoveredInfo.

private static void sendCoveredInfo(TestSuiteChromosome testSuite) {
    Set<String> coveredMethods = new HashSet<String>();
    Set<Integer> coveredTrueBranches = new HashSet<Integer>();
    Set<Integer> coveredFalseBranches = new HashSet<Integer>();
    Set<String> coveredBranchlessMethods = new HashSet<String>();
    Set<Integer> coveredLines = new HashSet<Integer>();
    Set<Integer> coveredRealBranches = new HashSet<Integer>();
    Set<Integer> coveredInstrumentedBranches = new HashSet<Integer>();
    for (TestChromosome test : testSuite.getTestChromosomes()) {
        ExecutionTrace trace = test.getLastExecutionResult().getTrace();
        coveredMethods.addAll(trace.getCoveredMethods());
        coveredTrueBranches.addAll(trace.getCoveredTrueBranches());
        coveredFalseBranches.addAll(trace.getCoveredFalseBranches());
        coveredBranchlessMethods.addAll(trace.getCoveredBranchlessMethods());
        coveredLines.addAll(trace.getCoveredLines());
    }
    int coveredBranchesInstrumented = 0;
    int coveredBranchesReal = 0;
    if (Properties.ERROR_BRANCHES || Properties.EXCEPTION_BRANCHES) {
        BranchPool branchPool = BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT());
        for (Integer branchId : coveredTrueBranches) {
            Branch b = branchPool.getBranch(branchId);
            if (b.isInstrumented())
                coveredBranchesInstrumented++;
            else {
                coveredBranchesReal++;
            }
        }
        for (Integer branchId : coveredFalseBranches) {
            Branch b = branchPool.getBranch(branchId);
            if (b.isInstrumented())
                coveredBranchesInstrumented++;
            else {
                coveredBranchesReal++;
            }
        }
    } else {
        coveredBranchesReal = coveredTrueBranches.size() + coveredFalseBranches.size();
    }
    ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Covered_Goals, testSuite.getCoveredGoals().size());
    ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Covered_Methods, coveredMethods.size());
    ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Covered_Branches, coveredTrueBranches.size() + coveredFalseBranches.size());
    ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Covered_Branchless_Methods, coveredBranchlessMethods.size());
    ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Covered_Branches_Real, coveredBranchesReal);
    ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Covered_Branches_Instrumented, coveredBranchesInstrumented);
    ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Covered_Lines, coveredLines.size());
}
Also used : Branch(org.evosuite.coverage.branch.Branch) ExecutionTrace(org.evosuite.testcase.execution.ExecutionTrace) BranchPool(org.evosuite.coverage.branch.BranchPool) TestChromosome(org.evosuite.testcase.TestChromosome) HashSet(java.util.HashSet)

Example 8 with Branch

use of org.evosuite.coverage.branch.Branch in project evosuite by EvoSuite.

the class TestGenerationResultBuilder method resetTestData.

private void resetTestData() {
    code = "";
    ga = null;
    testCode.clear();
    testCases.clear();
    contractViolations.clear();
    uncoveredLines = LinePool.getAllLines();
    for (Branch b : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getAllBranches()) {
        uncoveredBranches.add(new BranchInfo(b, true));
        uncoveredBranches.add(new BranchInfo(b, false));
    }
    for (Mutation m : MutationPool.getMutants()) {
        uncoveredMutants.add(new MutationInfo(m));
    }
}
Also used : Branch(org.evosuite.coverage.branch.Branch) Mutation(org.evosuite.coverage.mutation.Mutation)

Example 9 with Branch

use of org.evosuite.coverage.branch.Branch in project evosuite by EvoSuite.

the class RegressionSuiteFitness method initBranchMap.

private void initBranchMap() {
    // populate a temp branch distance map with initial data for all
    // branches(if they are not covered, 4 will be considered).
    tempBranchDistanceMap = new HashMap<>();
    double maxBranchValue = 4.0;
    for (Branch b : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getAllBranches()) {
        tempBranchDistanceMap.put(b.getActualBranchId(), maxBranchValue);
    }
}
Also used : Branch(org.evosuite.coverage.branch.Branch)

Example 10 with Branch

use of org.evosuite.coverage.branch.Branch in project evosuite by EvoSuite.

the class RegressionClassDiff method sameCFG.

public static boolean sameCFG() {
    Collection<Branch> branchesOriginal = BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getAllBranches();
    Collection<Branch> branchesRegression = BranchPool.getInstance(TestGenerationContext.getInstance().getRegressionClassLoaderForSUT()).getAllBranches();
    if (branchesOriginal.size() != branchesRegression.size()) {
        logger.error("Different number of branches between two versions: {} vs {}", branchesOriginal.size(), branchesRegression.size());
        return false;
    }
    Iterator<Branch> branchesOriginalIterator = branchesOriginal.iterator();
    Iterator<Branch> branchesRegressionIterator = branchesRegression.iterator();
    boolean sameBranches = true;
    while (branchesOriginalIterator.hasNext()) {
        Branch bOrig = branchesOriginalIterator.next();
        Branch bReg = branchesRegressionIterator.next();
        int bOrigOpcode = bOrig.getInstruction().getASMNode().getOpcode();
        int bRegOpcode = bReg.getInstruction().getASMNode().getOpcode();
        // Are branches from the same family of branches?
        if (!Objects.equals(RegressionClassDiff.getBranchFamily(bOrigOpcode), RegressionClassDiff.getBranchFamily(bRegOpcode))) {
            logger.error("Different family found between branches: {} vs {}", bOrigOpcode, bRegOpcode);
            sameBranches = false;
            break;
        }
    }
    return sameBranches;
}
Also used : Branch(org.evosuite.coverage.branch.Branch)

Aggregations

Branch (org.evosuite.coverage.branch.Branch)19 ArrayList (java.util.ArrayList)4 BytecodeInstruction (org.evosuite.graphs.cfg.BytecodeInstruction)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 BranchCoverageGoal (org.evosuite.coverage.branch.BranchCoverageGoal)2 Mutation (org.evosuite.coverage.mutation.Mutation)2 ControlFlowEdge (org.evosuite.graphs.cfg.ControlFlowEdge)2 TestCase (org.evosuite.testcase.TestCase)2 TestChromosome (org.evosuite.testcase.TestChromosome)2 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)2 LabelNode (org.objectweb.asm.tree.LabelNode)2 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 Map (java.util.Map)1 Set (java.util.Set)1 Assertion (org.evosuite.assertion.Assertion)1 ContractViolation (org.evosuite.contracts.ContractViolation)1 MethodNameMatcher (org.evosuite.coverage.MethodNameMatcher)1