Skip to content

Commit

Permalink
Merge pull request #6 from STAMP-project/master
Browse files Browse the repository at this point in the history
rebase with up to date version
  • Loading branch information
spookyvale authored Oct 24, 2018
2 parents 1369739 + 8643dfe commit a862180
Show file tree
Hide file tree
Showing 70 changed files with 897 additions and 383 deletions.
2 changes: 1 addition & 1 deletion .travis/travis-openjdk8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

source /opt/jdk_switcher/jdk_switcher.sh

jdk_switcher use openjdk8 & mvn -Djava.src.version=1.8 test
jdk_switcher use openjdk8 & mvn -Djava.src.version=1.8 test -f dspot/pom.xml
2 changes: 1 addition & 1 deletion .travis/travis-oraclejdk8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

source /opt/jdk_switcher/jdk_switcher.sh

jdk_switcher use oraclejdk8 & mvn -Djava.src.version=1.8 test
jdk_switcher use oraclejdk8 & mvn -Djava.src.version=1.8 test -f dspot/pom.xml
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ outputDirectory=target/trash/
#Argument string to use when PIT launches child processes. This is most commonly used
# to increase the amount of memory available to the process,
# but may be used to pass any valid JVM argument.
# Use commas to separate multiple arguments, and put them within brackets
jvmArgs=['-Xmx2048m','-Xms1024m']
# Use commas to separate multiple arguments
jvmArgs=-Xmx2048m,-Xms1024m
```

The result of the amplification of charAt consists of 6 new tests, as shown in the output below. These new tests are
Expand Down Expand Up @@ -174,15 +174,15 @@ java -jar /path/to/dspot-LATEST-jar-with-dependencies.jar --path-to-properties d

```
Usage: java -jar target/dspot-<version>-jar-with-dependencies.jar
[(-p|--path-to-properties) <./path/to/myproject.properties>] [(-a|--amplifiers) Amplifier1:Amplifier2:...:AmplifierN ] [(-i|--iteration) <iteration>] [(-s|--test-criterion) <PitMutantScoreSelector | ExecutedMutantSelector | CloverCoverageSelector | JacocoCoverageSelector | TakeAllSelector | ChangeDetectorSelector>] [--budgetizer <NoBudgetizer | SimpleBuddgetizer>] [--max-test-amplified <integer>] [(-t|--test) my.package.MyClassTest | all | diff1:my.package.MyClassTest | all | diff2:...:my.package.MyClassTest | all | diffN ] [(-c|--cases) testCases1:testCases2:...:testCasesN ] [(-o|--output-path) <output>] [--clean] [(-m|--path-pit-result) <./path/to/mutations.csv>] [--descartes] [--automatic-builder <MavenBuilder | GradleBuilder>] [--maven-home <path to maven home>] [--randomSeed <long integer>] [--timeOut <long integer>] [--verbose] [--with-comment] [--no-minimize] [--working-directory] [-e|--example] [-h|--help]
[(-p|--path-to-properties) <./path/to/myproject.properties>] [(-a|--amplifiers) Amplifier1:Amplifier2:...:AmplifierN ] [(-i|--iteration) <iteration>] [(-s|--test-criterion) <PitMutantScoreSelector | JacocoCoverageSelector | TakeAllSelector | ChangeDetectorSelector>] [--budgetizer <NoBudgetizer | SimpleBudgetizer>] [--max-test-amplified <integer>] [(-t|--test) my.package.MyClassTest | all | diff1:my.package.MyClassTest | all | diff2:...:my.package.MyClassTest | all | diffN ] [(-c|--cases) testCases1:testCases2:...:testCasesN ] [(-o|--output-path) <output>] [--clean] [(-m|--path-pit-result) <./path/to/mutations.csv>] [--descartes] [--automatic-builder <MavenBuilder | GradleBuilder>] [--maven-home <path to maven home>] [--randomSeed <long integer>] [--timeOut <long integer>] [--verbose] [--with-comment] [--no-minimize] [--working-directory] [--generate-new-test-class] [--keep-original-test-methods] [--use-maven-to-exe-test] [-e|--example] [-h|--help]
[(-p|--path-to-properties) <./path/to/myproject.properties>]
[mandatory] specify the path to the configuration file (format Java
properties) of the target project (e.g. ./foo.properties).
[(-a|--amplifiers) Amplifier1:Amplifier2:...:AmplifierN ]
[optional] specify the list of amplifiers to use. Default with all
available amplifiers.
available amplifiers.
- StringLiteralAmplifier
- NumberLiteralAmplifier
- CharLiteralAmplifier
Expand All @@ -193,7 +193,6 @@ Usage: java -jar target/dspot-<version>-jar-with-dependencies.jar
- TestDataMutator (deprecated)
- MethodGeneratorAmplifier
- ReturnValueAmplifier
- ReplacementAmplifier
- NullifierAmplifier
- None (default: None)
Expand All @@ -203,11 +202,11 @@ Usage: java -jar target/dspot-<version>-jar-with-dependencies.jar
iterations may help to kill more mutants). This has an impact on the
execution time: the more iterations, the longer DSpot runs. (default: 3)
[(-s|--test-criterion) <PitMutantScoreSelector | ExecutedMutantSelector | CloverCoverageSelector | JacocoCoverageSelector | TakeAllSelector | ChangeDetectorSelector>]
[(-s|--test-criterion) <PitMutantScoreSelector | JacocoCoverageSelector | TakeAllSelector | ChangeDetectorSelector>]
[optional] specify the test adequacy criterion to be maximized with
amplification (default: PitMutantScoreSelector)
[--budgetizer <NoBudgetizer | SimpleBuddgetizer>]
[--budgetizer <NoBudgetizer | SimpleBudgetizer>]
[optional] specify a Bugdetizer. (default: NoBudgetizer)
[--max-test-amplified <integer>]
Expand Down Expand Up @@ -243,7 +242,7 @@ Usage: java -jar target/dspot-<version>-jar-with-dependencies.jar
[--automatic-builder <MavenBuilder | GradleBuilder>]
[optional] specify the automatic builder to build the project (default:
MavenBuilder)
)
[--maven-home <path to maven home>]
specify the path to the maven home
Expand Down Expand Up @@ -271,7 +270,11 @@ Usage: java -jar target/dspot-<version>-jar-with-dependencies.jar
[--generate-new-test-class]
Enable the creation of a new test class.
[--keep-original-test-methods]
If enabled, DSpot keeps original test methods of the amplified test
class.
[--use-maven-to-exe-test]
If enabled, DSpot will use maven to execute the tests.
Expand All @@ -288,15 +291,15 @@ Here is the list of configuration properties of DSpot:

* Required properties
* project: specify the path to the root of the project. This path can be either absolute (recommended) or relative to the working directory of the DSpot process. We consider as root of the project folder that contain the top-most parent in a multi-module project.
* Required properties
* Optional properties
* targetModule: specify the module to be amplified. This value must be a relative path from the property project. If your project is multi-module, you must use this property because DSpot works at module level.
* src: specify the relative path from project/targetModule of the folder that contain sources (.java).(default: src/main/java/)
* testSrc: specify the relative path from project/targetModule of the folder that contain test sources (.java).(default: src/test/java/)
* classes: specify the relative path from project/targetModule of the folder that contain binaries of the source program (.class).(default: target/classes/)
* testclasses: specify the relative path from project/targetModule of the folder that contain binaries of the test source program (.class).(default: target/test-classes/)
* additionalClasspathElements: specify additional classpath elements. (_e.g._ a jar file) This value should be a list of relative paths from project/targetModule. Elements of the list must be separated by a comma ','.
* systemProperties: specify system properties. This value should be a list of couple property;value, separated by a comma ','. For example, systemProperties=admin=toto,passwd=tata. This define two system properties.
* outputDirectory: specify a path folder for the output.(default: target/dspot/output)
* outputDirectory: specify a path folder for the output.
* delta: specify the delta value for the assertions of floating-point numbers. If DSpot generates assertions for float, it uses Assert.assertEquals(expected, actual, delta). This property specify the delta value.(default: 0.1)
* excludedClasses: specify the full qualified name of excluded test classes. Each qualified name must be separated by a comma ','. These classes won't be amplified, nor executed during the mutation analysis, if the PitMutantScoreSelector is used.This property can be valued by a regex.
* excludedTestCases: specify the list of test cases to be excluded. Each is the name of a test case, separated by a comma ','.
Expand All @@ -306,7 +309,7 @@ Here is the list of configuration properties of DSpot:
* automaticBuilderName: specify the type of automatic builder. This properties is redundant with the command line option `--automatic-builder`. It should have also the same value: (MavenBuilder | GradleBuilder). This property has the priority over the command line.
* pitVersion: specify the version of PIT to use.(default: 1.3.0)
* pitTimeout: specify the time out of PIT, if the PitMutantScoreSelector.
* jvmArgs: specify JVM args to use when executing the test, PIT or other java process
* jvmArgs: specify JVM args to use when executing the test, PIT or other java process. This arguments should be a list, separated by a comma ',', _e.g._ jvmArgs=Xmx2048m,-Xms1024m',-Dis.admin.user=admin,-Dis.admin.passwd=$2pRSid#
* filter: specify the filter used by PIT. If you use PitMutantScoreSelector, we recommend you to set this property to your top-most package. This value will allow PIT to mutant all your code. However, if you want to restrict the scope of the mutation, you can specify a custom regex. If you do not specify any value, PIT will use the following filter: <groupId>.<artifactId>.* which might not match your packages.
* descartesVersion: specify the version of pit-descartes to use.(default: 1.2)
* descartesMutators: specify the list of descartes mutators to be used. Please refer to the descartes documentation for more details: https://github.com/STAMP-project/pitest-descartes
Expand Down
17 changes: 16 additions & 1 deletion dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package eu.stamp_project;

import eu.stamp_project.dspot.selector.PitMutantScoreSelector;
import eu.stamp_project.options.AmplifierEnum;
import eu.stamp_project.options.BudgetizerEnum;
import eu.stamp_project.options.JSAPOptions;
import eu.stamp_project.options.SelectorEnum;
import eu.stamp_project.program.ConstantsProperties;
Expand Down Expand Up @@ -169,6 +171,12 @@ public class DSpotMojo extends AbstractMojo {
@Parameter(defaultValue = "false", property = "generate-new-test-class")
private Boolean generateNewTestClass;

/**
* If enabled, DSpot keeps original test methods of the amplified test class.
*/
@Parameter(defaultValue = "false", property = "keep-original-test-methods")
private Boolean keepOriginalTestMethods;

/**
* If enabled, DSpot will use maven to execute the tests.
*/
Expand Down Expand Up @@ -224,7 +232,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.setAmplifiers(AmplifierEnum.buildAmplifiersFromString(this.amplifiers.toArray(new String[this.amplifiers.size()])))
.setNbIteration(this.iteration)
.setTestClasses(this.test)
.setSelector(SelectorEnum.valueOf(this.testCriterion).buildSelector())
.setBudgetizer(BudgetizerEnum.valueOf(this.budgetizer).getBugtizer())
.setTestCases(this.cases)
.setSeed(this.randomSeed)
.setTimeOutInMs(this.timeOut)
Expand All @@ -237,9 +245,16 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.setWithComment(this.withComment)
.setDescartesMode(this.descartes)
.setGenerateAmplifiedTestClass(this.generateNewTestClass)
.setKeepOriginalTestMethods(this.keepOriginalTestMethods)
.setOutputDirectory(this.outputPath)
.setUseMavenToExecuteTest(this.useMavenToExeTest);

if (this.pathPitResult != null && !this.pathPitResult.isEmpty()) {
InputConfiguration.get().setSelector(new PitMutantScoreSelector(this.pathPitResult));
} else {
InputConfiguration.get().setSelector(SelectorEnum.valueOf(this.testCriterion).buildSelector());
}

if (!this.pathToSecondVersion.isEmpty()) {
InputConfiguration.get().setAbsolutePathToSecondVersionProjectRoot(this.pathToSecondVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testDefaultConfiguration() throws Exception {
*/
mojoUnderTest.setPathToProperties("src/test/resources/test-projects/test-projects.properties");

mojoUnderTest.setPathPitResult("src/test/resources/test-projects/mutations.csv");
mojoUnderTest.setPathPitResult("src/test/resources/test-projects/originalpit/mutations.csv");
mojoUnderTest.setTestCriterion("PitMutantScoreSelector");
mojoUnderTest.setOutputPath("target/dspot-output");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ timeoutConstInMillis=10000
# to increase the amount of memory available to the process,
# but may be used to pass any valid JVM argument.
# Use commas to separate multiple arguments, and put them within brackets
jvmArgs=['-Xmx2048m','-Xms1024m']
jvmArgs=-Xmx2048m,-Xms1024m

#Mutators to apply when using Descartes Mode
#descartesMutators=['void','null','true','false','empty','0','(byte)0','(byte)1','(short)1','(short)2','0L','1L','0.0','1.0','0.0f','1.0f','\\40','\\'A\\'','\\"\\"','\\"A\\"']
Expand Down
6 changes: 3 additions & 3 deletions dspot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>spoon-core</artifactId>
<version>7.1.0-SNAPSHOT</version>
<version>7.1.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>eu.stamp-project</groupId>
<artifactId>test-runner</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<classifier>jar-with-dependencies</classifier>
</dependency>

Expand All @@ -117,7 +117,7 @@
<dependency>
<groupId>fr.inria.gforge.spoon.labs</groupId>
<artifactId>gumtree-spoon-ast-diff</artifactId>
<version>1.3</version>
<version>1.5</version>
</dependency>

</dependencies>
Expand Down
18 changes: 6 additions & 12 deletions dspot/src/main/java/eu/stamp_project/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,18 @@ public static void run(InputConfiguration configuration) throws Exception {
createOutputDirectories(configuration);
final long startTime = System.currentTimeMillis();
final List<CtType> amplifiedTestClasses;
if ("all".equals(configuration.getTestClasses().get(0))) {
if (configuration.getTestClasses().isEmpty() || "all".equals(configuration.getTestClasses().get(0))) {
amplifiedTestClasses = dspot.amplifyAllTests();
} else if ("diff".equals(configuration.getTestClasses().get(0))) {
final Map<String, List<String>> testMethodsAccordingToADiff = SelectorOnDiff
.findTestMethodsAccordingToADiff(configuration);
amplifiedTestClasses = testMethodsAccordingToADiff.keySet().stream()
.map(ctType -> dspot.amplifyTest(ctType, testMethodsAccordingToADiff.get(ctType)))
.filter(Objects::nonNull)
.flatMap(ctType ->
dspot.amplifyTestClassesTestMethods(Collections.singletonList(ctType), testMethodsAccordingToADiff.get(ctType)).stream()
).filter(Objects::nonNull)
.collect(Collectors.toList());
} else {
if (configuration.getTestClasses().isEmpty()) {
amplifiedTestClasses = dspot.amplifyAllTests();
} else {
amplifiedTestClasses = configuration.getTestClasses().stream()
.map(testClasses -> dspot.amplifyTest(testClasses, configuration.getTestCases()))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
amplifiedTestClasses = dspot.amplifyTestClassesTestMethods(configuration.getTestClasses(), configuration.getTestCases());
}
LOGGER.info("Amplification {}.", amplifiedTestClasses.isEmpty() ? "failed" : "succeed");
final long elapsedTime = System.currentTimeMillis() - startTime;
Expand All @@ -96,7 +90,7 @@ static void runExample() {
configuration.setAmplifiers(Collections.singletonList(new TestDataMutator()));
DSpot dSpot = new DSpot(configuration, 1, configuration.getAmplifiers(),
new JacocoCoverageSelector());
dSpot.amplifyTest("example.TestSuiteExample");
dSpot.amplifyTestClassesTestMethods(Collections.singletonList("example.TestSuiteExample"), Collections.emptyList());
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public String buildClasspath() {
final File classpathFile = new File(this.configuration.getAbsolutePathToProjectRoot() + File.separator + JAVA_PROJECT_CLASSPATH);
if (!classpathFile.exists()) {
LOGGER.info("Classpath file for Gradle project doesn't exist, starting to build it...");

LOGGER.info("Injecting Gradle task to print project classpath on stdout...");
injectPrintClasspathTask(this.configuration.getAbsolutePathToProjectRoot());
LOGGER.info("Retrieving project classpath...");
Expand All @@ -97,7 +96,12 @@ public String buildClasspath() {
resetOriginalGradleBuildFile(this.configuration.getAbsolutePathToProjectRoot());
}
try (BufferedReader buffer = new BufferedReader(new FileReader(classpathFile))) {
return buffer.lines().collect(Collectors.joining());
final String collect = buffer
.lines()
.collect(Collectors.joining());
return Arrays.stream(collect.split(":"))
.filter(path -> new File(path).exists() && new File(path).isAbsolute())
.collect(Collectors.joining(":"));
}
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -135,6 +139,8 @@ protected byte[] runTasks(String pathToRootOfProject, String... tasks) {
ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File(pathToRootOfProject)).connect();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

LOGGER.info("Run gradle tasks: {}", String.join(" ", tasks));

try {
BuildLauncher build = connection.newBuild();
build.forTasks(tasks);
Expand Down Expand Up @@ -274,6 +280,10 @@ private String getPitTaskConfiguration() {
"apply plugin: 'info.solidsoft.pitest'" + NEW_LINE;
}

private String wrapWithSingleQuote(String option) {
return "\'" + option + "\'";
}

private String getPitTaskOptions(CtType<?>... testClasses) {
return NEW_LINE + NEW_LINE + "pitest {" + NEW_LINE +
" " + OPT_TARGET_CLASSES + "['" + configuration.getFilter() + "']" + NEW_LINE +
Expand All @@ -283,7 +293,9 @@ private String getPitTaskOptions(CtType<?>... testClasses) {
(!configuration.getTimeoutPit().isEmpty() ?
" " + PROPERTY_VALUE_TIMEOUT + " = " + configuration.getTimeoutPit().isEmpty() : "") + NEW_LINE +
(!configuration.getJVMArgs().isEmpty() ?
" " + PROPERTY_VALUE_JVM_ARGS + " = " + configuration.getJVMArgs() : "") + NEW_LINE +
" " + PROPERTY_VALUE_JVM_ARGS + " = [" +
Arrays.stream(configuration.getJVMArgs().split(" ")).map(this::wrapWithSingleQuote).collect(Collectors.joining(",")) + "]"
: "") + NEW_LINE +
(testClasses != null ? " " + OPT_TARGET_TESTS + "['" + Arrays.stream(testClasses).map(DSpotUtils::ctTypeToFullQualifiedName).collect(Collectors.joining(",")) + "']" : "") + NEW_LINE +
(!configuration.getAdditionalClasspathElements().isEmpty() ?
" " + OPT_ADDITIONAL_CP_ELEMENTS + "['" + configuration.getAdditionalClasspathElements() + "']" : "") + NEW_LINE +
Expand Down
Loading

0 comments on commit a862180

Please sign in to comment.