use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.
the class NullifierAmplifierTest method testOnInteger.
@Test
public void testOnInteger() throws Exception {
// test the result of the NullifierAmplifier
final String nameMethod = "methodInteger";
CtClass<?> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
RandomHelper.setSeedRandom(42L);
Amplifier amplifier = new NullifierAmplifier();
final CtMethod method = findMethod(literalMutationClass, nameMethod);
List<CtMethod<?>> amplification = amplifier.amplify(method, 0).collect(Collectors.toList());
assertEquals(0, amplification.size());
}
use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.
the class NullifierAmplifierTest method testOnArrayType.
@Test
public void testOnArrayType() throws Exception {
final String nameMethod = "methodThatClassmethodWithCharArray";
CtClass<?> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
RandomHelper.setSeedRandom(42L);
Amplifier amplifier = new NullifierAmplifier();
final CtMethod<?> method = findMethod(literalMutationClass, nameMethod);
List<CtMethod<?>> amplification = amplifier.amplify(method, 0).collect(Collectors.toList());
assertTrue(amplification.isEmpty());
}
use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.
the class StringLiteralAmplifierTest method testAmplify.
@Test
public void testAmplify() throws Exception {
/*
test the StringLiteral
The first iteration is complete, i.e. apply random operations plus the specific strings
*/
final String nameMethod = "methodString";
CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
RandomHelper.setSeedRandom(42L);
Amplifier amplifier = new StringLiteralAmplifier();
amplifier.reset(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<CtMethod> mutantMethods = amplifier.amplify(method, 0).collect(Collectors.toList());
assertEquals(28, mutantMethods.size());
}
use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.
the class InitializeDSpot method init.
public void init(UserInput userInput) {
this.DSpotState = new DSpotState();
DSpotState.setUserInput(userInput);
DSpotState.setOnlyInputAmplification(userInput.isOnlyInputAmplification());
DSpotState.setDevFriendlyAmplification(userInput.isDevFriendlyAmplification());
DSpotState.verbose = userInput.isVerbose();
DSpotState.setStartTime(System.currentTimeMillis());
DSpotState.setTestFinder(new TestFinder(Arrays.stream(userInput.getExcludedClasses().split(",")).collect(Collectors.toList()), Arrays.stream(userInput.getExcludedTestCases().split(",")).collect(Collectors.toList())));
DSpotState.setAutomaticBuilder(userInput.getBuilderEnum().getAutomaticBuilder(userInput));
final String dependencies = completeDependencies(userInput, DSpotState.getAutomaticBuilder());
DSpotState.setCompiler(DSpotCompiler.createDSpotCompiler(userInput, dependencies));
userInput.setFactory(DSpotState.getCompiler().getLauncher().getFactory());
initHelpers(userInput);
DSpotState.setTestCompiler(new TestCompiler(userInput.getNumberParallelExecutionProcessors(), userInput.shouldExecuteTestsInParallel(), userInput.getAbsolutePathToProjectRoot(), userInput.getClasspathClassesProject(), userInput.getTimeOutInMs(), userInput.getPreGoalsTestExecution(), userInput.shouldUseMavenToExecuteTest()));
final EmailSender emailSender = new EmailSender(userInput.getSmtpUsername(), userInput.getSmtpPassword(), userInput.getSmtpHost(), userInput.getSmtpPort(), userInput.isSmtpAuth(), userInput.getSmtpTls());
DSpotState.setCollector(CollectorFactory.build(userInput, emailSender));
DSpotState.getCollector().reportInitInformation(userInput.getAmplifiers(), userInput.getSelector(), userInput.getNbIteration(), userInput.isGregorMode(), !userInput.isGregorMode(), userInput.getNumberParallelExecutionProcessors());
DSpotState.setTestClassesToBeAmplified(DSpotState.getTestFinder().findTestClasses(userInput.getTestClasses()));
DSpotState.setTestMethodsToBeAmplifiedNames(userInput.getTestCases());
if (DSpotState.getTestMethodsToBeAmplifiedNames().size() == 1 && DSpotState.getTestMethodsToBeAmplifiedNames().get(0).isEmpty()) {
DSpotState.getTestMethodsToBeAmplifiedNames().clear();
}
DSpotState.setTestSelector(userInput.getSelector().buildSelector(DSpotState.getAutomaticBuilder(), userInput));
final List<Amplifier> amplifiers = userInput.getAmplifiers().stream().map(AmplifierEnum::getAmplifier).filter(Objects::nonNull).collect(Collectors.toList());
DSpotState.setInputAmplDistributor(userInput.getInputAmplDistributor().getInputAmplDistributor(userInput.getMaxTestAmplified(), amplifiers));
DSpotState.setOutput(new Output(userInput.getAbsolutePathToProjectRoot(), userInput.getOutputDirectory(), DSpotState.getCollector()));
DSpotState.setAssertionGenerator(new AssertionGenerator(userInput.getDelta(), DSpotState.getCompiler(), DSpotState.getTestCompiler(), DSpotState.isDevFriendlyAmplification()));
Checker.postChecking(userInput);
DSpotState.setCollectData(true);
DSpotState.setDelta(userInput.getDelta());
DSpotState.setNbIteration(userInput.getNbIteration());
DSpotState.verbose = userInput.isVerbose();
}
use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.
the class SimpleInputAmplDistributor method inputAmplify.
/**
* Input amplification of multiple tests.
*
* @param testMethods Test methods
* @return New generated tests
*/
@Override
public List<CtMethod<?>> inputAmplify(List<CtMethod<?>> testMethods, int iteration) {
LOGGER.info("Amplification of inputs...");
final int budget = this.maxNumTests;
int totalBudget = this.maxNumTests;
// copy the amplifiers, we will remove amplifier that does not generate more test
final List<Amplifier> amplifiers = new ArrayList<>(this.amplifiers);
// copy the test methods to be amplified
final ArrayList<CtMethod<?>> testMethodsToBeAmplified = new ArrayList<>(testMethods);
// Amplify all method using all amplifiers
long time = System.currentTimeMillis();
final Map<Amplifier, Map<CtMethod<?>, List<CtMethod<?>>>> amplifiedTestMethodPerAmplifierPerTestMethod = amplify(amplifiers, testMethodsToBeAmplified, iteration);
LOGGER.info("Time to amplify: {}ms", System.currentTimeMillis() - time);
final List<CtMethod<?>> amplifiedTestMethods = new ArrayList<>();
while (totalBudget > 0 && !amplifiedTestMethodPerAmplifierPerTestMethod.isEmpty()) {
DSpotUtils.printProgress(budget - totalBudget, budget);
final int nbAmplifierRemaining = amplifiedTestMethodPerAmplifierPerTestMethod.size();
int budgetPerAmplifier = totalBudget / nbAmplifierRemaining;
if (budgetPerAmplifier == 0) {
// not enough budget, we get last randomly and quit
amplifiedTestMethods.addAll(getLastAmplifiedMethods(totalBudget, amplifiedTestMethodPerAmplifierPerTestMethod));
break;
}
for (Amplifier amplifier : amplifiedTestMethodPerAmplifierPerTestMethod.keySet()) {
totalBudget = selectAndAddAmplifiedTestMethods(totalBudget, amplifiedTestMethodPerAmplifierPerTestMethod, amplifiedTestMethods, budgetPerAmplifier, amplifier);
}
amplifiedTestMethodPerAmplifierPerTestMethod.entrySet().removeIf(entry -> entry.getValue().isEmpty());
}
LOGGER.info("{} new tests generated", amplifiedTestMethods.size());
return amplifiedTestMethods;
}
Aggregations