Search in sources :

Example 1 with AutomaticBuilder

use of fr.inria.diversify.automaticbuilder.AutomaticBuilder 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);
}
Also used : java.util(java.util) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) Logger(org.slf4j.Logger) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) DSpotCompiler(fr.inria.diversify.utils.compilation.DSpotCompiler) DSpotUtils(fr.inria.diversify.utils.DSpotUtils) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) GsonBuilder(com.google.gson.GsonBuilder) AutomaticBuilder(fr.inria.diversify.automaticbuilder.AutomaticBuilder) CtType(spoon.reflect.declaration.CtType) java.io(java.io) Gson(com.google.gson.Gson) AutomaticBuilderFactory(fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory) AmplificationChecker(fr.inria.diversify.utils.AmplificationChecker) TestCaseJSON(fr.inria.diversify.dspot.selector.json.mutant.TestCaseJSON) Counter(fr.inria.diversify.utils.Counter) MutantJSON(fr.inria.diversify.dspot.selector.json.mutant.MutantJSON) TestClassJSON(fr.inria.diversify.dspot.selector.json.mutant.TestClassJSON) PitResult(fr.inria.diversify.mutant.pit.PitResult) PitMutantMinimizer(fr.inria.stamp.minimization.PitMutantMinimizer) PitResultParser(fr.inria.diversify.mutant.pit.PitResultParser) Minimizer(fr.inria.stamp.minimization.Minimizer) CtMethod(spoon.reflect.declaration.CtMethod) AutomaticBuilder(fr.inria.diversify.automaticbuilder.AutomaticBuilder) CtType(spoon.reflect.declaration.CtType) PitResult(fr.inria.diversify.mutant.pit.PitResult) CtMethod(spoon.reflect.declaration.CtMethod)

Example 2 with AutomaticBuilder

use of fr.inria.diversify.automaticbuilder.AutomaticBuilder in project dspot by STAMP-project.

the class PitMutantScoreSelector method init.

@Override
public void init(InputConfiguration configuration) {
    super.init(configuration);
    if (configuration.getProperties().get("pitVersion") != null) {
        pitVersion = (String) configuration.getProperties().get("pitVersion");
    } else if (descartesMode) {
        pitVersion = "1.2.0";
    }
    if (this.originalKilledMutants == null) {
        final AutomaticBuilder automaticBuilder = AutomaticBuilderFactory.getAutomaticBuilder(this.configuration);
        automaticBuilder.runPit(this.program.getProgramDir());
        initOriginalPitResult(PitResultParser.parseAndDelete(this.program.getProgramDir() + automaticBuilder.getOutputDirectoryPit()));
    }
}
Also used : AutomaticBuilder(fr.inria.diversify.automaticbuilder.AutomaticBuilder)

Example 3 with AutomaticBuilder

use of fr.inria.diversify.automaticbuilder.AutomaticBuilder in project dspot by STAMP-project.

the class Initializer method initialize.

public static void initialize(InputConfiguration configuration, InputProgram program) {
    AutomaticBuilderFactory.reset();
    AutomaticBuilder builder = AutomaticBuilderFactory.getAutomaticBuilder(configuration);
    builder.compile(program.getProgramDir());
    if (!new File("target/dspot/dependencies/compare").exists()) {
        DSpotUtils.copyPackageFromResources("fr/inria/diversify/compare/", "MethodsHandler", "ObjectLog", "Observation", "Utils");
    }
}
Also used : AutomaticBuilder(fr.inria.diversify.automaticbuilder.AutomaticBuilder) File(java.io.File)

Example 4 with AutomaticBuilder

use of fr.inria.diversify.automaticbuilder.AutomaticBuilder in project dspot by STAMP-project.

the class ExecutedMutantSelector method init.

@Override
public void init(InputConfiguration configuration) {
    super.init(configuration);
    if (this.originalMutantExecuted == null) {
        LOGGER.info("Computing executed mutants by the original test suite...");
        final AutomaticBuilder automaticBuilder = AutomaticBuilderFactory.getAutomaticBuilder(this.configuration);
        automaticBuilder.runPit(this.program.getProgramDir());
        this.originalMutantExecuted = PitResultParser.parseAndDelete(this.program.getProgramDir() + automaticBuilder.getOutputDirectoryPit()).stream().filter(pitResult -> pitResult.getStateOfMutant() == PitResult.State.KILLED || pitResult.getStateOfMutant() == PitResult.State.SURVIVED).collect(Collectors.toList());
    }
}
Also used : AutomaticBuilder(fr.inria.diversify.automaticbuilder.AutomaticBuilder)

Example 5 with AutomaticBuilder

use of fr.inria.diversify.automaticbuilder.AutomaticBuilder in project Ex2Amplifier by STAMP-project.

the class AbstractTest method initSpoonModel.

private Launcher initSpoonModel(String pathToConfigurationFile) {
    try {
        this.configuration = new InputConfiguration(pathToConfigurationFile);
        final InputProgram program = InputConfiguration.initInputProgram(this.configuration);
        this.configuration.setInputProgram(program);
        AutomaticBuilder builder = AutomaticBuilderFactory.getAutomaticBuilder(this.configuration);
        String dependencies = builder.buildClasspath(program.getProgramDir());
        return initLauncher(program.getAbsoluteSourceCodeDir(), program.getAbsoluteTestSourceCodeDir(), dependencies + AmplificationHelper.PATH_SEPARATOR + "lib/catg-dev.jar");
    } catch (IOException ignored) {
        // should not happen
        fail();
    }
    // make javac happy
    return null;
}
Also used : AutomaticBuilder(fr.inria.diversify.automaticbuilder.AutomaticBuilder) IOException(java.io.IOException) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram)

Aggregations

AutomaticBuilder (fr.inria.diversify.automaticbuilder.AutomaticBuilder)5 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 AutomaticBuilderFactory (fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory)1 MutantJSON (fr.inria.diversify.dspot.selector.json.mutant.MutantJSON)1 TestCaseJSON (fr.inria.diversify.dspot.selector.json.mutant.TestCaseJSON)1 TestClassJSON (fr.inria.diversify.dspot.selector.json.mutant.TestClassJSON)1 PitResult (fr.inria.diversify.mutant.pit.PitResult)1 PitResultParser (fr.inria.diversify.mutant.pit.PitResultParser)1 AmplificationChecker (fr.inria.diversify.utils.AmplificationChecker)1 AmplificationHelper (fr.inria.diversify.utils.AmplificationHelper)1 Counter (fr.inria.diversify.utils.Counter)1 DSpotUtils (fr.inria.diversify.utils.DSpotUtils)1 DSpotCompiler (fr.inria.diversify.utils.compilation.DSpotCompiler)1 InputProgram (fr.inria.diversify.utils.sosiefier.InputProgram)1 Minimizer (fr.inria.stamp.minimization.Minimizer)1 PitMutantMinimizer (fr.inria.stamp.minimization.PitMutantMinimizer)1 java.io (java.io)1 File (java.io.File)1