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;
}
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());
}
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));
}
}
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);
}
}
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;
}
Aggregations