Search in sources :

Example 21 with InputProgram

use of fr.inria.diversify.utils.sosiefier.InputProgram 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 22 with InputProgram

use of fr.inria.diversify.utils.sosiefier.InputProgram 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)

Example 23 with InputProgram

use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.

the class ReplacementAmplifierTest method testReplacementOfArrayList.

@Test
public void testReplacementOfArrayList() throws Exception {
    /*
            The replacement of an array list works properly
        */
    final String packageName = "fr.inria.statementadd";
    InputProgram inputProgram = Utils.getInputProgram();
    final Factory factory = inputProgram.getFactory();
    inputProgram.setFactory(factory);
    AmplificationHelper.setSeedRandom(32L);
    ReplacementAmplifier amplifier = new ReplacementAmplifier();
    amplifier.reset(factory.Class().get(packageName + ".ClassTarget"));
    CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTarget"), "testWithLoop");
    List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
    assertEquals(1, amplifiedMethods.size());
    assertEquals("{" + AmplificationHelper.LINE_SEPARATOR + "    java.util.ArrayList<fr.inria.statementadd.TestClassTarget.Internal> internalList = new java.util.ArrayList<fr.inria.statementadd.TestClassTarget.Internal>(1891812663);" + AmplificationHelper.LINE_SEPARATOR + "    internalList.add(new fr.inria.statementadd.TestClassTarget.Internal());" + AmplificationHelper.LINE_SEPARATOR + "    for (fr.inria.statementadd.TestClassTarget.Internal i : internalList)" + AmplificationHelper.LINE_SEPARATOR + "        i.compute(0);" + AmplificationHelper.LINE_SEPARATOR + "" + AmplificationHelper.LINE_SEPARATOR + "}", amplifiedMethods.get(0).getBody().toString());
}
Also used : Factory(spoon.reflect.factory.Factory) CtMethod(spoon.reflect.declaration.CtMethod) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Example 24 with InputProgram

use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.

the class ReplacementAmplifierTest method testOnLoop.

@Test
public void testOnLoop() throws Exception {
    /*
            Test that the replacement amplifier does not replace local variable inside loops
         */
    final String packageName = "fr.inria.statementadd";
    InputProgram inputProgram = Utils.getInputProgram();
    final Factory factory = inputProgram.getFactory();
    inputProgram.setFactory(factory);
    AmplificationHelper.setSeedRandom(32L);
    ReplacementAmplifier amplifier = new ReplacementAmplifier();
    amplifier.reset(factory.Class().get(packageName + ".ClassTarget"));
    CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTarget"), "testWithLoop");
    List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
    assertEquals(1, amplifiedMethods.size());
}
Also used : Factory(spoon.reflect.factory.Factory) CtMethod(spoon.reflect.declaration.CtMethod) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Example 25 with InputProgram

use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.

the class StatementAddTest method testStatementAdd.

@Test
public void testStatementAdd() throws Exception {
    /*
            Test the StatementAdd amplifier. It reuse existing object to add method call of accessible method.
            It can reuse return value to add method call. It results here with 7 new test cases.
         */
    final String packageName = "fr.inria.statementadd";
    InputProgram inputProgram = Utils.getInputProgram();
    final Factory factory = inputProgram.getFactory();
    inputProgram.setFactory(factory);
    AmplificationHelper.setSeedRandom(42L);
    StatementAdd amplifier = new StatementAdd(packageName);
    amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));
    CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
    List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
    System.out.println(amplifiedMethods);
    assertEquals(6, amplifiedMethods.size());
    List<String> expectedCalledMethod = Arrays.asList("method", "methodWithDomainParameter", "methodWithPrimitifParameters", "methodWithPrimitifParameters", "methodWithReturn", "method1");
    assertTrue(amplifiedMethods.stream().allMatch(amplifiedMethod -> amplifiedMethod.filterChildren(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {

        @Override
        public boolean matches(CtInvocation<?> element) {
            return expectedCalledMethod.contains(element.getExecutable().getSimpleName());
        }
    }).first() != null));
}
Also used : TypeFilter(spoon.reflect.visitor.filter.TypeFilter) Arrays(java.util.Arrays) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) CtInvocation(spoon.reflect.code.CtInvocation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Factory(spoon.reflect.factory.Factory) List(java.util.List) Utils(fr.inria.Utils) CtClass(spoon.reflect.declaration.CtClass) Assert.assertEquals(org.junit.Assert.assertEquals) AbstractTest(fr.inria.AbstractTest) CtMethod(spoon.reflect.declaration.CtMethod) Factory(spoon.reflect.factory.Factory) CtInvocation(spoon.reflect.code.CtInvocation) CtMethod(spoon.reflect.declaration.CtMethod) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Aggregations

InputProgram (fr.inria.diversify.utils.sosiefier.InputProgram)30 Test (org.junit.Test)19 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)12 AbstractTest (fr.inria.AbstractTest)10 CtMethod (spoon.reflect.declaration.CtMethod)10 File (java.io.File)9 Factory (spoon.reflect.factory.Factory)7 AmplificationHelper (fr.inria.diversify.utils.AmplificationHelper)6 List (java.util.List)6 IOException (java.io.IOException)5 CtClass (spoon.reflect.declaration.CtClass)5 Utils (fr.inria.Utils)4 Arrays (java.util.Arrays)4 Map (java.util.Map)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 CtInvocation (spoon.reflect.code.CtInvocation)4 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)4 AbstractTest (eu.stamp.project.ex2amplifier.AbstractTest)3 TestListener (fr.inria.stamp.test.listener.TestListener)3 Collectors (java.util.stream.Collectors)3