Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to make serialization optional #36

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ public class DiffMutationReproGuidance extends DiffReproGuidance {
*/
private static ArraySet runMutants = new ArraySet();

private boolean serializeIn;
private boolean serializeOut;

private File reportFile;

public DiffMutationReproGuidance(File inputFile, File traceDir, MutationClassLoaders mcls, File resultsDir) throws IOException {
super(inputFile, traceDir);
public DiffMutationReproGuidance(File inputFile, File traceDir, MutationClassLoaders mcls, boolean serialIn, boolean serialOut, File resultsDir) throws IOException {
super(inputFile, traceDir, serialIn, serialOut);
cclOutcomes = new ArrayList<>();
MCLs = mcls;
ind = -1;

serializeIn = serialIn;
serializeOut = serialOut;
reportFile = new File(resultsDir, "mutate-repro-out.txt");
this.optLevel = MCLs.getCartographyClassLoader().getOptLevel();
}
Expand All @@ -75,7 +79,6 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro

recentOutcomes.clear();
cmpTo = null;

ind++;

// run CCL
Expand All @@ -95,7 +98,8 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro
// set up info
cmpTo = new ArrayList<>(recentOutcomes);
cclOutcomes.add(cmpTo.get(0));
byte[] argBytes = Serializer.serialize(args);
byte[] argBytes = null;
if(serializeIn) argBytes = Serializer.serialize(args);
recentOutcomes.clear();

for (MutationInstance mutationInstance : MCLs.getCartographyClassLoader().getMutationInstances()) {
Expand All @@ -107,7 +111,8 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro
continue;
}

MutationRunInfo mri = new MutationRunInfo(MCLs, mutationInstance, testClass, argBytes, args, method);
MutationRunInfo mri = new MutationRunInfo(MCLs, mutationInstance, testClass, args, method);
if(serializeIn) mri = new MutationRunInfo(MCLs, mutationInstance, testClass, argBytes, args, method);

// run with MCL
System.out.println("Running Mutant " + mutationInstance);
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@ public class DiffReproGuidance extends ReproGuidance implements DiffGuidance {
private Method compare;
protected List<Outcome> cmpTo;
public static final List<Outcome> recentOutcomes = new ArrayList<>();
private boolean serializeIn;
private boolean serializeOut;

public DiffReproGuidance(File inputFile, File traceDir) throws IOException {
public DiffReproGuidance(File inputFile, File traceDir, boolean serialIn, boolean serialOut) throws IOException {
super(inputFile, traceDir);
cmpTo = null;
recentOutcomes.clear();
serializeIn = serialIn;
serializeOut = serialOut;
try {
compare = Objects.class.getMethod("equals", Object.class, Object.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}

public DiffReproGuidance(File inputFile, File traceDir, List<Outcome> cmpRes) throws IOException {
this(inputFile, traceDir);
public DiffReproGuidance(File inputFile, File traceDir, List<Outcome> cmpRes, boolean serialIn, boolean serialOut) throws IOException {
this(inputFile, traceDir, serialIn, serialOut);
cmpTo = cmpRes;
}

Expand All @@ -50,12 +54,14 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro
return;
}

// use serialization to load both outputs with the same ClassLoader
//TODO may not want serialization for all diff repros
// optionally use serialization to load both outputs with the same ClassLoader
Outcome cmpOut = cmpTo.get(recentOutcomes.size() - 1);
ClassLoader cmpCL = compare.getDeclaringClass().getClassLoader();
Outcome cmpSerial = new Outcome(Serializer.translate(cmpOut.output, cmpCL), cmpOut.thrown);
Outcome outSerial = new Outcome(Serializer.translate(out.output, cmpCL), out.thrown);
Outcome cmpSerial = cmpOut, outSerial = out;
if(serializeOut) {
ClassLoader cmpCL = compare.getDeclaringClass().getClassLoader();
cmpSerial = new Outcome(Serializer.translate(cmpOut.output, cmpCL), cmpOut.thrown);
outSerial = new Outcome(Serializer.translate(out.output, cmpCL), out.thrown);
}

if (!Outcome.same(cmpSerial, outSerial, compare)) {
throw new DiffException(cmpTo.get(recentOutcomes.size() - 1), out);
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ public class DiffGoal extends AbstractMojo {
@Parameter(property="optLevel", defaultValue = "EXECUTION")
private String optLevel;

@Parameter(property="disableInputSerialization", defaultValue = "false")
private boolean disableInputSerialization;

@Parameter(property="disableOutputSerialization", defaultValue = "false")
private boolean disableOutputSerialization;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
ClassLoader loader;
Expand Down Expand Up @@ -203,7 +209,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
MutationClassLoaders mcl = new MutationClassLoaders(classPath, includes, targetIncludes, ol, baseClassLoader);
loader = mcl.getCartographyClassLoader();
guidance = new MutationGuidance(targetName, mcl, duration, trials, resultsDir, seedsDir, rnd);
guidance = new MutationGuidance(targetName, mcl, duration, trials, resultsDir, seedsDir, rnd, !disableInputSerialization, !disableOutputSerialization);
} catch (DependencyResolutionRequiredException | MalformedURLException e) {
throw new MojoExecutionException("Could not get project classpath", e);
} catch (FileNotFoundException e) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public class MutateDiffGoal extends AbstractMojo {
@Parameter(property="optLevel", defaultValue = "execution")
private String optLevel;

@Parameter(property="disableInputSerialization", defaultValue = "false")
private boolean disableInputSerialization;

@Parameter(property="disableOutputSerialization", defaultValue = "false")
private boolean disableOutputSerialization;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Log log = getLog();
Expand Down Expand Up @@ -98,7 +104,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

// Run initial test to compute mutants dynamically
System.out.println("Starting Initial Run:");
DiffMutationReproGuidance dmrg = new DiffMutationReproGuidance(input, null, mcls, resultsDir);
DiffMutationReproGuidance dmrg = new DiffMutationReproGuidance(input, null, mcls, !disableInputSerialization, !disableOutputSerialization, resultsDir);
dmrg.setStopOnFailure(true);
Result result = GuidedFuzzing.run(testClassName, testMethod, ccl, dmrg, null);
if (!result.wasSuccessful()) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public class ReproDiffGoal extends AbstractMojo {
@Parameter(property="dumpArgsDir")
private String dumpArgsDir;

@Parameter(property="disableInputSerialization", defaultValue = "false")
private boolean disableInputSerialization;

@Parameter(property="disableOutputSerialization", defaultValue = "false")
private boolean disableOutputSerialization;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
ClassLoader loader;
Expand Down Expand Up @@ -187,7 +193,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

try {
guidance = new DiffReproGuidance(inputFile, null);
guidance = new DiffReproGuidance(inputFile, null, !disableInputSerialization, !disableOutputSerialization);
result = GuidedFuzzing.run(testClassName, testMethod, loader, guidance, out);
} catch (ClassNotFoundException e) {
throw new MojoExecutionException("Could not load test class", e);
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/cmu/pasta/mu2/fuzz/MutationGuidance.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,20 @@ public class MutationGuidance extends ZestGuidance implements DiffGuidance {

private final List<String> exceptions = new ArrayList<>();

private boolean serializeIn;
private boolean serializeOut;

public MutationGuidance(String testName, MutationClassLoaders mutationClassLoaders,
Duration duration, Long trials, File outputDirectory, File seedInputDir, Random rand)
Duration duration, Long trials, File outputDirectory, File seedInputDir, Random rand, boolean serialIn, boolean serialOut)
throws IOException {
super(testName, duration, trials, outputDirectory, seedInputDir, rand);
this.mutationClassLoaders = mutationClassLoaders;
this.totalCoverage = new MutationCoverage();
this.runCoverage = new MutationCoverage();
this.validCoverage = new MutationCoverage();
this.optLevel = mutationClassLoaders.getCartographyClassLoader().getOptLevel();
serializeIn = serialIn;
serializeOut = serialOut;
try {
compare = Objects.class.getMethod("equals", Object.class, Object.class);
} catch (NoSuchMethodException e) {
Expand Down Expand Up @@ -160,7 +165,8 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro

// set up info
long trialTime = System.currentTimeMillis() - startTime;
byte[] argBytes = Serializer.serialize(args);
byte[] argBytes = null;
if(serializeIn) argBytes = Serializer.serialize(args);
int run = 1;

for (MutationInstance mutationInstance : getMutationInstances()) {
Expand All @@ -176,7 +182,8 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro
run += 1;
mutationInstance.resetTimer();

MutationRunInfo mri = new MutationRunInfo(mutationClassLoaders, mutationInstance, testClass, argBytes, args, method);
MutationRunInfo mri = new MutationRunInfo(mutationClassLoaders, mutationInstance, testClass, args, method);
if(serializeIn) mri = new MutationRunInfo(mutationClassLoaders, mutationInstance, testClass, argBytes, args, method);

// run with MCL
Outcome mclOutcome;
Expand All @@ -185,8 +192,10 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro
dtr.run();
if(dtr.getOutput() == null) mclOutcome = new Outcome(null, null);
else {
mclOutcome = new Outcome(Serializer.translate(dtr.getOutput(),
if(serializeOut)
mclOutcome = new Outcome(Serializer.translate(dtr.getOutput(),
mutationClassLoaders.getCartographyClassLoader()), null);
else mclOutcome = new Outcome(dtr.getOutput(), null);
}
} catch (InstrumentationException e) {
throw new GuidanceException(e);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/cmu/pasta/mu2/fuzz/MutationRunInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public class MutationRunInfo {
public FrameworkMethod method;
public Object[] args;

public MutationRunInfo(MutationClassLoaders MCLs, MutationInstance mutationInstance, TestClass testClass, Object[] a, FrameworkMethod fm) throws ClassNotFoundException {
MutationClassLoader mcl = MCLs.getMutationClassLoader(mutationInstance);
clazz = Class.forName(testClass.getName(), true, mcl);
method = fm;
args = a;
}

public MutationRunInfo(MutationClassLoaders MCLs, MutationInstance mutationInstance, TestClass testClass, byte[] argBytes, Object[] oArgs, FrameworkMethod fm) throws ClassNotFoundException, NoSuchMethodException, IOException {
// load class with MCL
MutationClassLoader mcl = MCLs.getMutationClassLoader(mutationInstance);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/cmu/pasta/mu2/diff/DiffIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static class ProbedMutationGuidance extends MutationGuidance {
List<Integer> inputHashes = new ArrayList<>();

ProbedMutationGuidance(MutationClassLoaders mcls, long trials, Random rnd) throws IOException {
super(null, mcls,null, trials, resultsDir, null, rnd);
super(null, mcls,null, trials, resultsDir, null, rnd, true, true);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/cmu/pasta/mu2/fuzz/MutationGuidanceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static class ProbedMutationGuidance extends MutationGuidance {
List<Integer> inputHashes = new ArrayList<>();

ProbedMutationGuidance(MutationClassLoaders mcls, long trials, Random rnd) throws IOException {
super(null, mcls,null, trials, resultsDir, null, rnd);
super(null, mcls,null, trials, resultsDir, null, rnd, true, true);
}

@Override
Expand Down