Search in sources :

Example 6 with Amplifier

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());
}
Also used : NullifierAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NullifierAmplifier) NullifierAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NullifierAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 7 with Amplifier

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());
}
Also used : NullifierAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NullifierAmplifier) NullifierAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NullifierAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 8 with Amplifier

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());
}
Also used : StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 9 with Amplifier

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();
}
Also used : TestCompiler(eu.stamp_project.dspot.common.compilation.TestCompiler) AssertionGenerator(eu.stamp_project.dspot.assertiongenerator.AssertionGenerator) Output(eu.stamp_project.dspot.common.report.output.Output) AmplifierEnum(eu.stamp_project.dspot.common.configuration.options.AmplifierEnum) TestFinder(eu.stamp_project.dspot.common.configuration.test_finder.TestFinder) EmailSender(eu.stamp_project.dspot.common.collector.smtp.EmailSender) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)

Example 10 with Amplifier

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;
}
Also used : ArrayList(java.util.ArrayList) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) Map(java.util.Map) HashMap(java.util.HashMap) CtMethod(spoon.reflect.declaration.CtMethod)

Aggregations

Amplifier (eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)18 CtMethod (spoon.reflect.declaration.CtMethod)17 Test (org.junit.Test)15 StringLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier)6 NullifierAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.NullifierAmplifier)4 NumberLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier)4 AbstractLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier)3 ArrayList (java.util.ArrayList)3 AssertionGenerator (eu.stamp_project.dspot.assertiongenerator.AssertionGenerator)2 TestFinder (eu.stamp_project.dspot.common.configuration.test_finder.TestFinder)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Ignore (org.junit.Ignore)2 CtExpression (spoon.reflect.code.CtExpression)2 CtClass (spoon.reflect.declaration.CtClass)2 AbstractTestOnSample (eu.stamp_project.dspot.AbstractTestOnSample)1 TextualDistanceInputAmplDistributor (eu.stamp_project.dspot.amplifier.TextualDistanceInputAmplDistributor)1 AllLiteralAmplifiers (eu.stamp_project.dspot.amplifier.amplifiers.AllLiteralAmplifiers)1 BooleanLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.BooleanLiteralAmplifier)1 CharLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.CharLiteralAmplifier)1