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);
}
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;
}
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());
}
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());
}
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));
}
Aggregations