Skip to content

Commit

Permalink
Descartes (STAMP-project#359)
Browse files Browse the repository at this point in the history
* feat: can use pit with descartes mutation engine

* test: descartes injections, checker and usage of the mutation engine

* the package edu.emory is now prohibited. In DSpot, we use java.util classes

* cli: removes some short flags and add descartes options

* fix: removed const

* ci: get and build pitest-descartes from GH

* fix checkstyle property
  • Loading branch information
danglotb authored Mar 12, 2018
1 parent 07923f7 commit 7322cdb
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 177 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ install:
- export MAVEN_HOME=`mvn --version | grep 'Maven home' | sed -e 's/Maven h.* //'`

script:
- git clone https://github.com/STAMP-project/pitest-descartes && cd pitest-descartes && mvn install -DskipTests && cd ..
- mvn clean install
- cd dspot && java -jar target/dspot-$DSPOT_VERSION-jar-with-dependencies.jar --example

Expand Down
4 changes: 3 additions & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

<!-- Checks for imports -->
<!-- See http://checkstyle.sf.net/config_import.html -->
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="IllegalImport"> <!-- defaults to sun.* packages -->
<property name="illegalPkgs" value="sun.*, edu.emory.*"/> <!-- sun? -->
</module>
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package fr.inria.diversify.automaticbuilder;

import fr.inria.diversify.dspot.selector.PitMutantScoreSelector;
import fr.inria.diversify.mutant.descartes.DescartesChecker;
import fr.inria.diversify.mutant.descartes.DescartesInjector;
import fr.inria.diversify.mutant.pit.MavenPitCommandAndOptions;
import fr.inria.diversify.utils.AmplificationHelper;
import fr.inria.diversify.utils.DSpotUtils;
import fr.inria.diversify.utils.sosiefier.InputConfiguration;
import fr.inria.stamp.Main;
Expand Down Expand Up @@ -33,29 +35,30 @@ public class MavenAutomaticBuilder implements AutomaticBuilder {

private InputConfiguration configuration;

@Deprecated
private String backUpPom;

private String mavenHome;

private String classpath;

private String contentOfOriginalPom;

private static final String FILE_SEPARATOR = "/";

private static final String POM_FILE = "pom.xml";

MavenAutomaticBuilder(@Deprecated InputConfiguration configuration) {
MavenAutomaticBuilder(InputConfiguration configuration) {
this.mavenHome = DSpotUtils.buildMavenHome(configuration);
this.configuration = configuration;
final String pathToPomFile = configuration.getInputProgram().getProgramDir() + FILE_SEPARATOR + POM_FILE;
try (final BufferedReader bufferedReader = new BufferedReader(new FileReader(pathToPomFile))) {
this.backUpPom = bufferedReader.lines().collect(Collectors.joining(System.getProperty("line.separator")));
} catch (Exception e) {
throw new RuntimeException(e);
}
if (MavenPitCommandAndOptions.descartesMode &&
DescartesChecker.shouldInjectDescartes(pathToPomFile)) {
DescartesInjector.injectDescartesIntoPom(pathToPomFile);
final String pathToPom = this.configuration.getInputProgram().getProgramDir() + "/" + POM_FILE;
if (PitMutantScoreSelector.descartesMode &&
DescartesChecker.shouldInjectDescartes(pathToPom)) {
try (final BufferedReader buffer = new BufferedReader(new FileReader(pathToPom))) {
this.contentOfOriginalPom = buffer.lines().collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR));
} catch (Exception ignored) {

}
DescartesInjector.injectDescartesIntoPom(pathToPom);
} else {
this.contentOfOriginalPom = null;
}
}

Expand Down Expand Up @@ -95,13 +98,14 @@ public String buildClasspath(String pathToRootOfProject) {

@Override
public void reset() {
final String pathToPomFile = configuration.getInputProgram().getProgramDir() + FILE_SEPARATOR + POM_FILE;
try {
final FileWriter writer = new FileWriter(pathToPomFile, false);
writer.write(this.backUpPom);
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
if (contentOfOriginalPom != null) {
final String pathToPom = this.configuration.getInputProgram().getProgramDir() + "/" + POM_FILE;
try (FileWriter writer = new FileWriter(pathToPom)) {
writer.write(this.contentOfOriginalPom);
this.contentOfOriginalPom = null;
} catch (Exception ignored) {

}
}
}

Expand All @@ -113,11 +117,8 @@ public void runPit(String pathToRootOfProject, CtType<?>... testClasses) {

}
try {
String[] phases = new String[]{PRE_GOAL_PIT, //
CMD_PIT_MUTATION_COVERAGE + ":" +
(configuration.getProperties().get("pitVersion") != null ?
configuration.getProperties().get("pitVersion") : PIT_VERSION
) + ":" + GOAL_PIT_MUTATION_COVERAGE, //
String[] phases = new String[]{CMD_PIT_MUTATION_COVERAGE + ":" +
PitMutantScoreSelector.pitVersion + ":" + GOAL_PIT_MUTATION_COVERAGE, //
OPT_WITH_HISTORY, //
OPT_TARGET_CLASSES + configuration.getProperty("filter"), //
OPT_VALUE_REPORT_DIR, //
Expand All @@ -128,11 +129,8 @@ public void runPit(String pathToRootOfProject, CtType<?>... testClasses) {
OPT_ADDITIONAL_CP_ELEMENTS + "target/dspot/dependencies/" +
(configuration.getProperty(PROPERTY_ADDITIONAL_CP_ELEMENTS) != null ?
"," + configuration.getProperty(PROPERTY_ADDITIONAL_CP_ELEMENTS) : "") , //
descartesMode ? OPT_MUTATION_ENGINE_DESCARTES : OPT_MUTATION_ENGINE_DEFAULT,
OPT_MUTATORS + (evosuiteMode ?
Arrays.stream(VALUE_MUTATORS_EVOSUITE).collect(Collectors.joining(",")) :
descartesMode ? Arrays.stream(VALUE_MUTATORS_DESCARTES).collect(Collectors.joining(",")) :
VALUE_MUTATORS_ALL), //
PitMutantScoreSelector.descartesMode ? OPT_MUTATION_ENGINE_DESCARTES : OPT_MUTATION_ENGINE_DEFAULT,
PitMutantScoreSelector.descartesMode ? "" : OPT_MUTATORS + VALUE_MUTATORS_ALL, //
configuration.getProperty(PROPERTY_EXCLUDED_CLASSES) != null ?
OPT_EXCLUDED_CLASSES + configuration.getProperty(PROPERTY_EXCLUDED_CLASSES) :
""//
Expand All @@ -158,22 +156,15 @@ public void runPit(String pathToRootOfProject) {

}
try {
String[] phases = new String[]{PRE_GOAL_PIT, //
CMD_PIT_MUTATION_COVERAGE + ":" +
(configuration.getProperties().get("pitVersion") != null ?
configuration.getProperties().get("pitVersion") : PIT_VERSION
) + ":" + GOAL_PIT_MUTATION_COVERAGE, //
String[] phases = new String[]{CMD_PIT_MUTATION_COVERAGE + ":" + PitMutantScoreSelector.pitVersion + ":" + GOAL_PIT_MUTATION_COVERAGE, //
OPT_WITH_HISTORY, //
OPT_TARGET_CLASSES + configuration.getProperty("filter"), //
OPT_VALUE_REPORT_DIR, //
OPT_VALUE_FORMAT, //
OPT_VALUE_TIMEOUT, //
OPT_VALUE_MEMORY, //
descartesMode ? OPT_MUTATION_ENGINE_DESCARTES : OPT_MUTATION_ENGINE_DEFAULT,
OPT_MUTATORS + (evosuiteMode ?
Arrays.stream(VALUE_MUTATORS_EVOSUITE).collect(Collectors.joining(",")) :
descartesMode ? Arrays.stream(VALUE_MUTATORS_DESCARTES).collect(Collectors.joining(",")) :
VALUE_MUTATORS_ALL), //
PitMutantScoreSelector.descartesMode ? OPT_MUTATION_ENGINE_DESCARTES : OPT_MUTATION_ENGINE_DEFAULT,
PitMutantScoreSelector.descartesMode? "" : OPT_MUTATORS + VALUE_MUTATORS_ALL, //
OPT_ADDITIONAL_CP_ELEMENTS + "target/dspot/dependencies/" +
(configuration.getProperty(PROPERTY_ADDITIONAL_CP_ELEMENTS) != null ?
"," + configuration.getProperty(PROPERTY_ADDITIONAL_CP_ELEMENTS) : "") , //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package fr.inria.diversify.dspot.amplifier;

import edu.emory.mathcs.backport.java.util.Collections;
import spoon.reflect.code.CtLiteral;

import java.util.Collections;
import java.util.Set;

public class BooleanLiteralAmplifier extends AbstractLiteralAmplifier<Boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
*/
public class PitMutantScoreSelector extends TakeAllSelector {

public static String pitVersion = "1.3.0";

public static String descartesVersion = "0.2-SNAPSHOT";

public static boolean descartesMode = false;

private static final Logger LOGGER = LoggerFactory.getLogger(PitMutantScoreSelector.class);

private int numberOfMutant;
Expand All @@ -55,6 +61,11 @@ public PitMutantScoreSelector(String pathToOriginalResultOfPit) {
@Override
public void init(InputConfiguration configuration) {
super.init(configuration);
if (configuration.getProperties().get("pitVersion") != null) {
pitVersion = (String) configuration.getProperties().get("pitVersion");
} else if (descartesMode) {
pitVersion = "1.2.0";
}
if (this.originalKilledMutants == null) {
final AutomaticBuilder automaticBuilder = AutomaticBuilderFactory.getAutomaticBuilder(this.configuration);
automaticBuilder.runPit(this.program.getProgramDir());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.inria.diversify.mutant.descartes;

import fr.inria.diversify.dspot.selector.PitMutantScoreSelector;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
Expand All @@ -15,7 +16,6 @@
* [email protected]
* on 24/03/17
*/
@Deprecated
public class DescartesChecker {

public static boolean shouldInjectDescartes(String pathToPom) {
Expand Down Expand Up @@ -43,7 +43,7 @@ private static boolean checkDependency(Node root) {
if (dependencies == null) {
return true;
}
final List<String> expectedValues = new ArrayList<>(Arrays.asList("org.pitest", "pitest-maven", "1.1.11"));
final List<String> expectedValues = new ArrayList<>(Arrays.asList("org.pitest", "pitest-maven", PitMutantScoreSelector.pitVersion));
Optional<Node> checkDependency = getAllChildNodeNamedFrom(dependencies, "dependency").stream()
.filter(dependency ->
checkThatHasTheGoodDependency(dependency, expectedValues)
Expand Down Expand Up @@ -95,7 +95,7 @@ private static Node getPlugin(Node root) {
if (plugins == null) {
return null;
}
final List<String> expectedValues = new ArrayList<>(Arrays.asList("org.pitest", "pitest-maven", "1.1.11"));
final List<String> expectedValues = new ArrayList<>(Arrays.asList("org.pitest", "pitest-maven", PitMutantScoreSelector.pitVersion));
Optional<Node> checkDependency = getChildThatHasTheGoodDependency(plugins, expectedValues, "plugin");
if (!checkDependency.isPresent()) {
return null;
Expand All @@ -109,7 +109,7 @@ private static Optional<Node> getChildThatHasTheGoodDependency(Node parent, List
.filter(plugin ->
checkThatHasTheGoodDependency(plugin, expectedValues)
)
.findFirst();
.findFirst();
}

private static boolean checkPlugin(Node root) {
Expand All @@ -134,7 +134,7 @@ private static boolean checkPlugin(Node root) {
return true;
}

final List<String> expectedValues = new ArrayList<>(Arrays.asList("fr.inria.stamp", "descartes", "0.1-SNAPSHOT"));
final List<String> expectedValues = new ArrayList<>(Arrays.asList("fr.inria.stamp", "descartes", PitMutantScoreSelector.descartesVersion));
return !getChildThatHasTheGoodDependency(dependencies1, expectedValues, "dependency").isPresent();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.inria.diversify.mutant.descartes;

import fr.inria.diversify.dspot.selector.PitMutantScoreSelector;
import fr.inria.diversify.mutant.pit.MavenPitCommandAndOptions;
import org.w3c.dom.*;
import org.xml.sax.SAXException;

Expand All @@ -22,11 +24,8 @@
* [email protected]
* on 23/03/17
*/
@Deprecated
public class DescartesInjector {

private final static String[] mutators = {"null", "void", "0", "false"};

private static Node getNodeNamedFromOrBuildIfDoesnotExist(Document doc, Node startNode, String name) {
Node currentNode = DescartesChecker.getNodeNamedFrom(startNode, name);
if (currentNode == null) {
Expand All @@ -49,21 +48,21 @@ private static List<Node> buildNodesDependency(Document doc, String groupIdValue

private static Node buildDependencyToPitTest(Document doc) {
final Element dependency = doc.createElement("dependency");
buildNodesDependency(doc, "org.pitest", "pitest-maven", "1.1.11").forEach(dependency::appendChild);
buildNodesDependency(doc, "org.pitest", "pitest-maven", PitMutantScoreSelector.pitVersion).forEach(dependency::appendChild);
return dependency;
}

private static Node buildPlugin(Document doc) {
final Element plugin = doc.createElement("plugin");
buildNodesDependency(doc, "org.pitest", "pitest-maven", "1.1.11").forEach(plugin::appendChild);
buildNodesDependency(doc, "org.pitest", "pitest-maven", PitMutantScoreSelector.pitVersion).forEach(plugin::appendChild);
plugin.appendChild(buildConfiguration(doc));
plugin.appendChild(buildDependencies(doc));
return plugin;
}

private static Node buildDependency(Document doc) {
final Element dependency = doc.createElement("dependency");
buildNodesDependency(doc, "fr.inria.stamp", "descartes", "0.1-SNAPSHOT").forEach(dependency::appendChild);
buildNodesDependency(doc, "fr.inria.stamp", "descartes", PitMutantScoreSelector.descartesVersion).forEach(dependency::appendChild);
return dependency;
}

Expand All @@ -80,7 +79,7 @@ private static Node buildMutators(Document doc, String name) {
}

private static List<Node> buildListOfMutators(Document doc) {
return Arrays.stream(mutators)
return Arrays.stream(MavenPitCommandAndOptions.VALUE_MUTATORS_DESCARTES)
.collect(ArrayList<Node>::new,
(nodes, name) -> nodes.add(buildMutators(doc, name)),
ArrayList<Node>::addAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
*/
public class MavenPitCommandAndOptions {

@Deprecated
public static boolean descartesMode = false;

@Deprecated
public static boolean evosuiteMode = false;

public static final String PRE_GOAL_PIT = ""; // TODO those pre-goals are necessary while we do not know how to compile with spoon

public static final String OPT_WITH_HISTORY = "-DwithHistory";

public static final String OPT_VALUE_REPORT_DIR = "-DreportsDirectory=target/pit-reports";
Expand All @@ -39,8 +31,6 @@ public class MavenPitCommandAndOptions {

public static final String CMD_PIT_MUTATION_COVERAGE = "org.pitest:pitest-maven";

public static final String PIT_VERSION = "1.3.0";

public static final String GOAL_PIT_MUTATION_COVERAGE = "mutationCoverage";

public static final String OPT_VALUE_TIMEOUT = "-DtimeoutConst=10000";
Expand All @@ -51,18 +41,6 @@ public class MavenPitCommandAndOptions {

public static final String VALUE_MUTATORS_ALL = "ALL";

public static final String[] VALUE_MUTATORS_EVOSUITE = new String[]{
"VOID_METHOD_CALLS",
"NON_VOID_METHOD_CALLS",
"EXPERIMENTAL_MEMBER_VARIABLE",
"INCREMENTS",
"INVERT_NEGS",
"MATH",
"NEGATE_CONDITIONALS",
"CONDITIONALS_BOUNDARY",
"INLINE_CONSTS"
};

/**
* Mutant operator copied from dhell
*/
Expand Down
Loading

0 comments on commit 7322cdb

Please sign in to comment.