Search in sources :

Example 1 with DSpot

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

the class ExecutedMutantSelectorTest method test.

@Ignore
@Test
public void test() throws Exception {
    // pre computing the number of executed mutants...
    Main.verbose = true;
    AutomaticBuilderFactory.getAutomaticBuilder(Utils.getInputConfiguration()).runPit(Utils.getInputProgram().getProgramDir());
    final List<PitResult> pitResults = PitResultParser.parseAndDelete(Utils.getInputProgram().getProgramDir() + "target/pit-reports/");
    final ExecutedMutantSelector testSelector = new ExecutedMutantSelector();
    DSpot dspot = new DSpot(Utils.getInputConfiguration(), 1, Collections.singletonList(new TestDataMutator()), testSelector);
    final CtType amplifyTest = dspot.amplifyTest(Utils.findClass("example.TestSuiteExample"), Collections.singletonList(Utils.findMethod("example.TestSuiteExample", "test8")));
    // pretty print it
    DSpotUtils.printCtTypeToGivenDirectory(amplifyTest, new File(DSpotCompiler.pathToTmpTestSources));
    // then compile
    final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(Utils.getInputConfiguration()).buildClasspath(Utils.getInputProgram().getProgramDir()) + AmplificationHelper.PATH_SEPARATOR + Utils.getInputProgram().getProgramDir() + "/" + Utils.getInputProgram().getClassesDir() + AmplificationHelper.PATH_SEPARATOR + "target/dspot/dependencies/" + AmplificationHelper.PATH_SEPARATOR + Utils.getInputProgram().getProgramDir() + "/" + Utils.getInputProgram().getTestClassesDir();
    DSpotCompiler.compile(DSpotCompiler.pathToTmpTestSources, classpath, new File(Utils.getInputProgram().getProgramDir() + "/" + Utils.getInputProgram().getTestClassesDir()));
    AutomaticBuilderFactory.getAutomaticBuilder(Utils.getInputConfiguration()).runPit(Utils.getInputProgram().getProgramDir());
    final List<PitResult> amplifiedPitResults = PitResultParser.parseAndDelete(Utils.getInputProgram().getProgramDir() + "target/pit-reports/");
    assertTrue(pitResults.stream().filter(pitResult -> pitResult.getStateOfMutant() == PitResult.State.KILLED || pitResult.getStateOfMutant() == PitResult.State.SURVIVED).count() < amplifiedPitResults.stream().filter(pitResult -> pitResult.getStateOfMutant() == PitResult.State.KILLED || pitResult.getStateOfMutant() == PitResult.State.SURVIVED).count());
    Main.verbose = false;
}
Also used : TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) DSpotCompiler(fr.inria.diversify.utils.compilation.DSpotCompiler) DSpotUtils(fr.inria.diversify.utils.DSpotUtils) Main(fr.inria.stamp.Main) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) DSpot(fr.inria.diversify.dspot.DSpot) File(java.io.File) List(java.util.List) CtType(spoon.reflect.declaration.CtType) Ignore(org.junit.Ignore) Utils(fr.inria.Utils) AutomaticBuilderFactory(fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory) PitResult(fr.inria.diversify.mutant.pit.PitResult) Collections(java.util.Collections) PitResultParser(fr.inria.diversify.mutant.pit.PitResultParser) Before(org.junit.Before) DSpot(fr.inria.diversify.dspot.DSpot) CtType(spoon.reflect.declaration.CtType) PitResult(fr.inria.diversify.mutant.pit.PitResult) File(java.io.File) TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with DSpot

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

the class JacocoCoverageSelectorTest method testDSpotWithJacocoCoverageSelector.

@Test
public void testDSpotWithJacocoCoverageSelector() throws Exception {
    try {
        FileUtils.deleteDirectory(new File("target/trash"));
    } catch (Exception ignored) {
    // ignored
    }
    AmplificationHelper.setSeedRandom(23L);
    InputConfiguration configuration = new InputConfiguration("src/test/resources/test-projects/test-projects.properties");
    DSpot dspot = new DSpot(configuration, 2, Arrays.asList(new TestDataMutator(), new StatementAdd()), new JacocoCoverageSelector());
    dspot.amplifyTest("example.TestSuiteExample", Collections.singletonList("test2"));
    try (BufferedReader buffer = new BufferedReader(new FileReader(configuration.getOutputDirectory() + "example.TestSuiteExample_jacoco_instr_coverage_report.txt"))) {
        assertEquals(expectedReport, buffer.lines().collect(Collectors.joining(nl)));
    }
}
Also used : DSpot(fr.inria.diversify.dspot.DSpot) BufferedReader(java.io.BufferedReader) StatementAdd(fr.inria.diversify.dspot.amplifier.StatementAdd) FileReader(java.io.FileReader) File(java.io.File) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) Test(org.junit.Test)

Example 3 with DSpot

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

the class Main method run.

public static void run(Configuration configuration, InputConfiguration inputConfiguration) throws Exception {
    AmplificationHelper.setSeedRandom(23L);
    AmplificationHelper.minimize = configuration.minimize;
    InputProgram program = new InputProgram();
    inputConfiguration.setInputProgram(program);
    inputConfiguration.getProperties().setProperty("automaticBuilderName", configuration.automaticBuilderName);
    AmplificationHelper.MAX_NUMBER_OF_TESTS = configuration.maxTestAmplified;
    if (configuration.mavenHome != null) {
        inputConfiguration.getProperties().put("maven.home", configuration.mavenHome);
    }
    if (configuration.pathToOutput != null) {
        inputConfiguration.getProperties().setProperty("outputDirectory", configuration.pathToOutput);
    }
    DSpot dspot = new DSpot(inputConfiguration, configuration.nbIteration, configuration.amplifiers, configuration.selector);
    AmplificationHelper.setSeedRandom(configuration.seed);
    AmplificationHelper.setTimeOutInMs(configuration.timeOutInMs);
    createOutputDirectories(inputConfiguration, configuration.clean);
    final long startTime = System.currentTimeMillis();
    final List<CtType> amplifiedTestClasses;
    if ("all".equals(configuration.testClasses.get(0))) {
        amplifiedTestClasses = dspot.amplifyAllTests();
    } else if ("diff".equals(configuration.testClasses.get(0))) {
        amplifiedTestClasses = dspot.amplifyAllTests(SelectorOnDiff.findTestClassesAccordingToADiff(inputConfiguration));
    } else {
        if (configuration.testCases.isEmpty()) {
            amplifiedTestClasses = dspot.amplifyAllTestsNames(configuration.testClasses);
        } else {
            amplifiedTestClasses = configuration.testClasses.stream().map(testClasses -> dspot.amplifyTest(testClasses, configuration.testCases)).collect(Collectors.toList());
        }
    }
    LOGGER.info("Amplification {}.", amplifiedTestClasses.isEmpty() ? "failed" : "succeed");
    final long elapsedTime = System.currentTimeMillis() - startTime;
    LOGGER.info("Elapsed time {} ms", elapsedTime);
}
Also used : TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) Logger(org.slf4j.Logger) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) JacocoCoverageSelector(fr.inria.diversify.dspot.selector.JacocoCoverageSelector) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) SelectorOnDiff(fr.inria.stamp.diff.SelectorOnDiff) DSpot(fr.inria.diversify.dspot.DSpot) File(java.io.File) List(java.util.List) CtType(spoon.reflect.declaration.CtType) Collections(java.util.Collections) DSpot(fr.inria.diversify.dspot.DSpot) CtType(spoon.reflect.declaration.CtType) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram)

Example 4 with DSpot

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

the class Main method runExample.

static void runExample() {
    try {
        InputConfiguration configuration = new InputConfiguration("src/test/resources/test-projects/test-projects.properties");
        DSpot dSpot = new DSpot(configuration, 1, Collections.singletonList(new TestDataMutator()), new JacocoCoverageSelector());
        dSpot.amplifyTest("example.TestSuiteExample");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DSpot(fr.inria.diversify.dspot.DSpot) JacocoCoverageSelector(fr.inria.diversify.dspot.selector.JacocoCoverageSelector) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) IOException(java.io.IOException) TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator)

Example 5 with DSpot

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

the class PitScoreMutantSelectorDescartesTest method testPitDescartesMode.

@Test
public void testPitDescartesMode() throws Exception {
    /*
            weak contract: this test should not throw any exception and end properly
                the increase of the mutation score and the selection is delegated to dedicated test
                here we test that the descartes mode runs
         */
    assertFalse(PitMutantScoreSelector.descartesMode);
    PitMutantScoreSelector.descartesMode = true;
    PitMutantScoreSelector.pitVersion = "1.2.0";
    InputConfiguration configuration = new InputConfiguration("src/test/resources/test-projects/test-projects.properties");
    DSpot dspot = new DSpot(configuration, 1, Arrays.asList(new StringLiteralAmplifier(), new NumberLiteralAmplifier()), new PitMutantScoreSelector());
    dspot.amplifyTest("example.TestSuiteExample", Collections.singletonList("test2"));
    FileUtils.cleanDirectory(new File(configuration.getOutputDirectory()));
    assertTrue(PitMutantScoreSelector.descartesMode);
}
Also used : DSpot(fr.inria.diversify.dspot.DSpot) PitMutantScoreSelector(fr.inria.diversify.dspot.selector.PitMutantScoreSelector) StringLiteralAmplifier(fr.inria.diversify.dspot.amplifier.StringLiteralAmplifier) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) NumberLiteralAmplifier(fr.inria.diversify.dspot.amplifier.NumberLiteralAmplifier) Test(org.junit.Test)

Aggregations

DSpot (fr.inria.diversify.dspot.DSpot)5 TestDataMutator (fr.inria.diversify.dspot.amplifier.TestDataMutator)4 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)4 File (java.io.File)3 Test (org.junit.Test)3 JacocoCoverageSelector (fr.inria.diversify.dspot.selector.JacocoCoverageSelector)2 AmplificationHelper (fr.inria.diversify.utils.AmplificationHelper)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 List (java.util.List)2 CtType (spoon.reflect.declaration.CtType)2 Utils (fr.inria.Utils)1 AutomaticBuilderFactory (fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory)1 NumberLiteralAmplifier (fr.inria.diversify.dspot.amplifier.NumberLiteralAmplifier)1 StatementAdd (fr.inria.diversify.dspot.amplifier.StatementAdd)1 StringLiteralAmplifier (fr.inria.diversify.dspot.amplifier.StringLiteralAmplifier)1 PitMutantScoreSelector (fr.inria.diversify.dspot.selector.PitMutantScoreSelector)1 PitResult (fr.inria.diversify.mutant.pit.PitResult)1 PitResultParser (fr.inria.diversify.mutant.pit.PitResultParser)1 DSpotUtils (fr.inria.diversify.utils.DSpotUtils)1