use of fr.inria.diversify.utils.AmplificationChecker in project dspot by STAMP-project.
the class ExecutedMutantSelector method selectToKeep.
@Override
public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) {
if (amplifiedTestToBeKept.isEmpty()) {
return amplifiedTestToBeKept;
}
// construct a test classes with only amplified tests
CtType clone = this.currentClassTestToBeAmplified.clone();
clone.setParent(this.currentClassTestToBeAmplified.getParent());
this.currentClassTestToBeAmplified.getMethods().stream().filter(AmplificationChecker::isTest).forEach(clone::removeMethod);
amplifiedTestToBeKept.forEach(clone::addMethod);
// pretty print it
DSpotUtils.printCtTypeToGivenDirectory(clone, new File(DSpotCompiler.pathToTmpTestSources));
// then compile
final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(this.configuration).buildClasspath(this.program.getProgramDir()) + AmplificationHelper.PATH_SEPARATOR + this.program.getProgramDir() + "/" + this.program.getClassesDir() + AmplificationHelper.PATH_SEPARATOR + "target/dspot/dependencies/" + AmplificationHelper.PATH_SEPARATOR + this.program.getProgramDir() + "/" + this.program.getTestClassesDir();
DSpotCompiler.compile(DSpotCompiler.pathToTmpTestSources, classpath, new File(this.program.getProgramDir() + "/" + this.program.getTestClassesDir()));
AutomaticBuilderFactory.getAutomaticBuilder(this.configuration).runPit(this.program.getProgramDir(), clone);
final List<PitResult> pitResults = PitResultParser.parseAndDelete(program.getProgramDir() + AutomaticBuilderFactory.getAutomaticBuilder(this.configuration).getOutputDirectoryPit());
final int numberOfSelectedAmplifiedTest = pitResults.stream().filter(pitResult -> pitResult.getStateOfMutant() == PitResult.State.KILLED || pitResult.getStateOfMutant() == PitResult.State.SURVIVED).filter(pitResult -> !this.originalMutantExecuted.contains(pitResult)).map(pitResult -> {
final CtMethod amplifiedTestThatExecuteMoreMutants = pitResult.getMethod(clone);
if (!this.mutantExecutedPerAmplifiedTestMethod.containsKey(amplifiedTestThatExecuteMoreMutants)) {
this.mutantExecutedPerAmplifiedTestMethod.put(amplifiedTestThatExecuteMoreMutants, new HashSet<>());
}
this.mutantExecutedPerAmplifiedTestMethod.get(amplifiedTestThatExecuteMoreMutants).add(pitResult);
this.selectedAmplifiedTest.add(amplifiedTestThatExecuteMoreMutants);
return amplifiedTestThatExecuteMoreMutants;
}).collect(Collectors.toSet()).size();
LOGGER.info("{} has been selected to amplify the test suite", numberOfSelectedAmplifiedTest);
return amplifiedTestToBeKept;
}
use of fr.inria.diversify.utils.AmplificationChecker in project dspot by STAMP-project.
the class PitMutantScoreSelector method selectToKeep.
@Override
public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) {
if (amplifiedTestToBeKept.isEmpty()) {
return amplifiedTestToBeKept;
}
CtType clone = this.currentClassTestToBeAmplified.clone();
clone.setParent(this.currentClassTestToBeAmplified.getParent());
this.currentClassTestToBeAmplified.getMethods().stream().filter(AmplificationChecker::isTest).forEach(clone::removeMethod);
amplifiedTestToBeKept.forEach(clone::addMethod);
DSpotUtils.printCtTypeToGivenDirectory(clone, new File(DSpotCompiler.pathToTmpTestSources));
final AutomaticBuilder automaticBuilder = AutomaticBuilderFactory.getAutomaticBuilder(this.configuration);
final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(this.configuration).buildClasspath(this.program.getProgramDir()) + AmplificationHelper.PATH_SEPARATOR + this.program.getProgramDir() + "/" + this.program.getClassesDir() + AmplificationHelper.PATH_SEPARATOR + "target/dspot/dependencies/" + AmplificationHelper.PATH_SEPARATOR + this.program.getProgramDir() + "/" + this.program.getTestClassesDir();
DSpotCompiler.compile(DSpotCompiler.pathToTmpTestSources, classpath, new File(this.program.getProgramDir() + "/" + this.program.getTestClassesDir()));
AutomaticBuilderFactory.getAutomaticBuilder(this.configuration).runPit(this.program.getProgramDir(), clone);
final List<PitResult> results = PitResultParser.parseAndDelete(program.getProgramDir() + automaticBuilder.getOutputDirectoryPit());
Set<CtMethod<?>> selectedTests = new HashSet<>();
if (results != null) {
LOGGER.info("{} mutants has been generated ({})", results.size(), this.numberOfMutant);
if (results.size() != this.numberOfMutant) {
LOGGER.warn("Number of generated mutant is different than the original one.");
}
results.stream().filter(result -> result.getStateOfMutant() == PitResult.State.KILLED && !this.originalKilledMutants.contains(result) && !this.mutantNotTestedByOriginal.contains(result)).forEach(result -> {
CtMethod method = result.getMethod(clone);
if (killsMoreMutantThanParents(method, result)) {
if (!testThatKilledMutants.containsKey(method)) {
testThatKilledMutants.put(method, new HashSet<>());
}
testThatKilledMutants.get(method).add(result);
if (method == null) {
// output of pit test does not allow us to know which test case kill new mutants... we keep them all...
selectedTests.addAll(amplifiedTestToBeKept);
} else {
selectedTests.add(method);
}
}
});
}
this.selectedAmplifiedTest.addAll(selectedTests);
selectedTests.forEach(selectedTest -> LOGGER.info("{} kills {} more mutants", selectedTest == null ? this.currentClassTestToBeAmplified.getSimpleName() : selectedTest.getSimpleName(), this.testThatKilledMutants.containsKey(selectedTest) ? this.testThatKilledMutants.get(selectedTest).size() : this.testThatKilledMutants.get(null)));
return new ArrayList<>(selectedTests);
}
use of fr.inria.diversify.utils.AmplificationChecker in project dspot by STAMP-project.
the class DSpotMockedTest method test.
@Test
public void test() throws Exception {
/*
Test the whole dspot procedure.
*/
ValueCreator.count = 0;
AmplificationHelper.setSeedRandom(23L);
InputConfiguration configuration = new InputConfiguration(getPathToPropertiesFile());
InputProgram program = new InputProgram();
configuration.setInputProgram(program);
DSpot dspot = new DSpot(configuration, 1, Arrays.asList(new StatementAdd()));
try {
FileUtils.cleanDirectory(new File(configuration.getOutputDirectory()));
} catch (Exception ignored) {
}
assertEquals(6, dspot.getInputProgram().getFactory().Class().get("info.sanaulla.dal.BookDALTest").getMethods().size());
CtType<?> amplifiedTest = dspot.amplifyTest("info.sanaulla.dal.BookDALTest", Collections.singletonList("testGetBook"));
assertEquals(1, amplifiedTest.getMethods().stream().filter(AmplificationChecker::isTest).count());
System.out.println(amplifiedTest);
assertTrue(!amplifiedTest.getMethodsByName("testGetBook_sd8").isEmpty());
}
Aggregations