use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class PropertiesTestGAFactory method getSearchAlgorithm.
@Override
public GeneticAlgorithm<TestChromosome> getSearchAlgorithm() {
ChromosomeFactory<TestChromosome> factory = getChromosomeFactory();
// FIXXME
GeneticAlgorithm<TestChromosome> ga = getGeneticAlgorithm(factory);
if (Properties.NEW_STATISTICS)
ga.addListener(new org.evosuite.statistics.StatisticsListener());
// How to select candidates for reproduction
SelectionFunction<TestChromosome> selection_function = getSelectionFunction();
selection_function.setMaximize(false);
ga.setSelectionFunction(selection_function);
// When to stop the search
StoppingCondition stopping_condition = getStoppingCondition();
ga.setStoppingCondition(stopping_condition);
// ga.addListener(stopping_condition);
if (Properties.STOP_ZERO) {
ga.addStoppingCondition(new ZeroFitnessStoppingCondition());
}
if (!(stopping_condition instanceof MaxTimeStoppingCondition)) {
ga.addStoppingCondition(new GlobalTimeStoppingCondition());
}
if (ArrayUtil.contains(Properties.CRITERION, Criterion.MUTATION) || ArrayUtil.contains(Properties.CRITERION, Criterion.STRONGMUTATION)) {
ga.addStoppingCondition(new MutationTimeoutStoppingCondition());
}
ga.resetStoppingConditions();
ga.setPopulationLimit(getPopulationLimit());
// How to cross over
CrossOverFunction crossover_function = getCrossoverFunction();
ga.setCrossOverFunction(crossover_function);
if (Properties.CHECK_BEST_LENGTH) {
org.evosuite.testcase.RelativeTestLengthBloatControl bloat_control = new org.evosuite.testcase.RelativeTestLengthBloatControl();
ga.addBloatControl(bloat_control);
ga.addListener(bloat_control);
}
TestCaseSecondaryObjective.setSecondaryObjectives();
if (Properties.DYNAMIC_LIMIT) {
// max_s = GAProperties.generations * getBranches().size();
// TODO: might want to make this dependent on the selected coverage
// criterion
// TODO also, question: is branchMap.size() really intended here?
// I think BranchPool.getBranchCount() was intended
Properties.SEARCH_BUDGET = Properties.SEARCH_BUDGET * (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getNumBranchlessMethods(Properties.TARGET_CLASS) + BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchCountForClass(Properties.TARGET_CLASS) * 2);
stopping_condition.setLimit(Properties.SEARCH_BUDGET);
logger.info("Setting dynamic length limit to " + Properties.SEARCH_BUDGET);
}
if (Properties.RECYCLE_CHROMOSOMES) {
if (Properties.STRATEGY == Strategy.ONEBRANCH)
ga.addListener(TestCaseRecycler.getInstance());
}
// ga.addListener(new ResourceController<TestChromosome>());
return ga;
}
use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class ConcolicExecution method getSymbolicPath.
/**
* Retrieve the path condition for a given test case
*
* @param test
* a {@link org.evosuite.testcase.TestChromosome} object.
* @return a {@link java.util.List} object.
*/
public static List<BranchCondition> getSymbolicPath(TestChromosome test) {
TestChromosome dscCopy = (TestChromosome) test.clone();
DefaultTestCase defaultTestCase = (DefaultTestCase) dscCopy.getTestCase();
return executeConcolic(defaultTestCase);
}
use of org.evosuite.testcase.TestChromosome 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.testcase.TestChromosome in project evosuite by EvoSuite.
the class FixedNumRandomTestStrategy method generateTests.
@Override
public TestSuiteChromosome generateTests() {
LoggingUtils.getEvoLogger().info("* Generating fixed number of random tests");
RandomLengthTestFactory factory = new org.evosuite.testcase.factories.RandomLengthTestFactory();
TestSuiteChromosome suite = new TestSuiteChromosome();
if (!canGenerateTestsForSUT()) {
LoggingUtils.getEvoLogger().info("* Found no testable methods in the target class " + Properties.TARGET_CLASS);
ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Total_Goals, 0);
return suite;
}
for (int i = 0; i < Properties.NUM_RANDOM_TESTS; i++) {
logger.info("Current test: " + i + "/" + Properties.NUM_RANDOM_TESTS);
TestChromosome test = factory.getChromosome();
ExecutionResult result = TestCaseExecutor.runTest(test.getTestCase());
Integer pos = result.getFirstPositionOfThrownException();
if (pos != null) {
if (result.getExceptionThrownAtPosition(pos) instanceof CodeUnderTestException || result.getExceptionThrownAtPosition(pos) instanceof UncompilableCodeException || result.getExceptionThrownAtPosition(pos) instanceof TestCaseExecutor.TimeoutExceeded) {
// Filter invalid tests
continue;
} else {
// Remove anything that follows an exception
test.getTestCase().chop(pos + 1);
}
test.setChanged(true);
} else {
test.setLastExecutionResult(result);
}
suite.addTest(test);
}
// Search is finished, send statistics
sendExecutionStatistics();
return suite;
}
use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class TestCaseRecycler method searchFinished.
@Override
public void searchFinished(GeneticAlgorithm<?> algorithm) {
Chromosome individual = algorithm.getBestIndividual();
if (individual instanceof TestChromosome) {
TestChromosome testChromosome = (TestChromosome) individual;
testPool.add(testChromosome.getTestCase());
} else if (individual instanceof TestSuiteChromosome) {
TestSuiteChromosome testSuiteChromosome = (TestSuiteChromosome) individual;
testPool.addAll(testSuiteChromosome.getTests());
}
}
Aggregations