Search in sources :

Example 1 with InputProgram

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

the class JBSERunnerTest method test2.

@Test
public void test2() throws Exception {
    /*
            Same as Test, but on another test method (compareTo).
            In this case, there is also a parameter in the second operand
         */
    final InputProgram program = configuration.getInputProgram();
    final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(configuration).buildClasspath(program.getProgramDir()) + ":" + program.getProgramDir() + program.getClassesDir() + ":" + program.getProgramDir() + program.getTestClassesDir();
    final CtMethod<?> testMethod = this.launcher.getFactory().Class().get("fr.inria.calculator.CalculatorTest").getMethodsByName("testCompareToWithParameters").get(0);
    final List<Map<String, List<String>>> conditionOnVariablesForEachState = JBSERunner.runJBSE(classpath, testMethod);
    assertEquals("[{param1=[param1 > param2]}, {param1=[param1 <= param2]}]", conditionOnVariablesForEachState.toString());
}
Also used : Map(java.util.Map) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(eu.stamp.project.ex2amplifier.AbstractTest)

Example 2 with InputProgram

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

the class JBSERunnerTest method test.

@Test
public void test() throws Exception {
    /*
            Test the run method of JBSERunner. JBSE should return a List of Map,
            that associates a name of parameter to its constraints to reach each state.
            Parameter are extracted literals from test.
         */
    final InputProgram program = this.configuration.getInputProgram();
    final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(this.configuration).buildClasspath(program.getProgramDir()) + ":" + program.getProgramDir() + program.getClassesDir() + ":" + program.getProgramDir() + program.getTestClassesDir();
    final CtMethod<?> testMethod = this.launcher.getFactory().Class().get("fr.inria.calculator.CalculatorTest").getMethodsByName("testAccumulateWithParameters").get(0);
    final List<Map<String, List<String>>> conditionOnVariablesForEachState = JBSERunner.runJBSE(classpath, testMethod);
    assertEquals(2, conditionOnVariablesForEachState.size());
    assertEquals("[{param1=[param1 % 3 == 0]}, {param1=[param1 % 3 != 0]}]", conditionOnVariablesForEachState.toString());
}
Also used : Map(java.util.Map) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(eu.stamp.project.ex2amplifier.AbstractTest)

Example 3 with InputProgram

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

the class JBSERunnterTest2 method test.

@Test
public void test() throws Exception {
    final InputProgram program = configuration.getInputProgram();
    final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(configuration).buildClasspath(program.getProgramDir()) + ":" + program.getProgramDir() + program.getClassesDir() + ":" + program.getProgramDir() + program.getTestClassesDir();
    final CtClass<?> mainClass = this.launcher.getFactory().Class().get("fr.inria.stamp.MainTest");
    final CtMethod<?> testMethod = mainClass.getMethodsByName("test3").get(0);
    final CtMethod<?> ctMethod = ArgumentsExtractor.performExtraction(testMethod);
    mainClass.addMethod(ctMethod);
    DSpotUtils.printCtTypeToGivenDirectory(mainClass, new File("target/dspot/tmp_test_sources"));
    DSpotCompiler.compile("target/dspot/tmp_test_sources", classpath, new File(this.configuration.getInputProgram().getProgramDir() + "/" + this.configuration.getInputProgram().getTestClassesDir()));
    final List<Map<String, List<String>>> conditionOnVariablesForEachState = JBSERunner.runJBSE(classpath, ctMethod);
    System.out.println(conditionOnVariablesForEachState);
}
Also used : File(java.io.File) Map(java.util.Map) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(eu.stamp.project.ex2amplifier.AbstractTest)

Example 4 with InputProgram

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

the class ChangeDetectorSelector method init.

@Override
public void init(InputConfiguration configuration) {
    this.configuration = configuration;
    this.program = this.configuration.getInputProgram();
    final String configurationPath = configuration.getProperty("configPath");
    final String pathToFolder = configuration.getProperty("folderPath");
    InputConfiguration inputConfiguration;
    try {
        inputConfiguration = new InputConfiguration(configurationPath);
        InputProgram inputProgram = InputConfiguration.initInputProgram(inputConfiguration);
        inputConfiguration.setInputProgram(inputProgram);
        this.pathToChangedVersionOfProgram = pathToFolder + DSpotUtils.shouldAddSeparator.apply(pathToFolder) + (inputConfiguration.getProperty("targetModule") != null ? inputConfiguration.getProperty("targetModule") + DSpotUtils.shouldAddSeparator.apply(pathToFolder) : "");
        inputProgram.setProgramDir(this.pathToChangedVersionOfProgram);
        Initializer.initialize(inputConfiguration, inputProgram);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram)

Example 5 with InputProgram

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

the class CloverCoverageSelector method selectToAmplify.

@Override
public List<CtMethod<?>> selectToAmplify(List<CtMethod<?>> testsToBeAmplified) {
    if (this.currentClassTestToBeAmplified == null && !testsToBeAmplified.isEmpty()) {
        this.currentClassTestToBeAmplified = testsToBeAmplified.get(0).getDeclaringType();
        final Map<String, Map<String, List<Integer>>> lineCoveragePerTestMethods = CloverExecutor.executeAll(this.configuration, PATH_TO_COPIED_FILES);
        this.originalLineCoveragePerClass = new HashMap<>();
        final InputProgram program = this.configuration.getInputProgram();
        lineCoveragePerTestMethods.keySet().stream().map(lineCoveragePerTestMethods::get).forEach(lineCoveragePerTestMethod -> lineCoveragePerTestMethod.keySet().forEach(className -> {
            final CtType<?> key = program.getFactory().Type().get(className);
            if (!this.originalLineCoveragePerClass.containsKey(key)) {
                this.originalLineCoveragePerClass.put(key, new HashSet<>());
            }
            this.originalLineCoveragePerClass.get(key).addAll(lineCoveragePerTestMethod.get(className));
        }));
        final String classesOfProject = program.getProgramDir() + program.getClassesDir() + AmplificationHelper.PATH_SEPARATOR + program.getProgramDir() + program.getTestClassesDir();
        final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(this.configuration).buildClasspath(program.getProgramDir()) + AmplificationHelper.PATH_SEPARATOR + classesOfProject;
        this.initialCoverage = EntryPoint.runCoverageOnTestClasses(classpath, classesOfProject, DSpotUtils.getAllTestClasses(configuration));
    }
    if (testsToBeAmplified.size() > 1) {
        final List<CtMethod<?>> collect = testsToBeAmplified.stream().filter(this.selectedAmplifiedTest::contains).collect(Collectors.toList());
        if (collect.isEmpty()) {
            return testsToBeAmplified;
        } else {
            return collect;
        }
    } else {
        return testsToBeAmplified;
    }
}
Also used : AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) DSpotCompiler(fr.inria.diversify.utils.compilation.DSpotCompiler) DSpotUtils(fr.inria.diversify.utils.DSpotUtils) FileWriter(java.io.FileWriter) Set(java.util.Set) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) File(java.io.File) HashSet(java.util.HashSet) CloverExecutor(fr.inria.stamp.coverage.clover.CloverExecutor) List(java.util.List) CtType(spoon.reflect.declaration.CtType) AutomaticBuilderFactory(fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory) Map(java.util.Map) AmplificationChecker(fr.inria.diversify.utils.AmplificationChecker) EntryPoint(eu.stamp.project.testrunner.EntryPoint) Coverage(eu.stamp.project.testrunner.runner.coverage.Coverage) CtMethod(spoon.reflect.declaration.CtMethod) CtType(spoon.reflect.declaration.CtType) HashMap(java.util.HashMap) Map(java.util.Map) CtMethod(spoon.reflect.declaration.CtMethod) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) HashSet(java.util.HashSet)

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