From 890f257c4aa7c283135a613bc7d3e59702a4b009 Mon Sep 17 00:00:00 2001 From: Bella Laybourn Date: Mon, 7 Feb 2022 16:11:04 -0500 Subject: [PATCH 1/7] serialization flag for repro --- .../guidance/DiffMutationReproGuidance.java | 3 +-- .../mu2/diff/guidance/DiffReproGuidance.java | 17 +++++++++++------ .../pasta/mu2/diff/plugin/ReproDiffGoal.java | 5 ++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java index 3988730..f6c3e87 100644 --- a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java +++ b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java @@ -11,7 +11,6 @@ import cmu.pasta.mu2.instrument.MutationClassLoaders; import com.pholser.junit.quickcheck.Pair; import edu.berkeley.cs.jqf.fuzz.guidance.GuidanceException; -import edu.berkeley.cs.jqf.fuzz.util.MovingAverage; import edu.berkeley.cs.jqf.instrument.InstrumentationException; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.TestClass; @@ -60,7 +59,7 @@ public class DiffMutationReproGuidance extends DiffReproGuidance { private static ArraySet runMutants = new ArraySet(); public DiffMutationReproGuidance(File inputFile, File traceDir, MutationClassLoaders mcls) throws IOException { - super(inputFile, traceDir); + super(inputFile, traceDir, true); cclOutcomes = new ArrayList<>(); mclOutcomes = new HashMap<>(); MCLs = mcls; diff --git a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java index 1c62e5d..9ba0e56 100644 --- a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java +++ b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java @@ -18,11 +18,13 @@ public class DiffReproGuidance extends ReproGuidance implements DiffGuidance { private Method compare; protected List cmpTo; public static final List recentOutcomes = new ArrayList<>(); + private boolean serializing; - public DiffReproGuidance(File inputFile, File traceDir) throws IOException { + public DiffReproGuidance(File inputFile, File traceDir, boolean serial) throws IOException { super(inputFile, traceDir); cmpTo = null; recentOutcomes.clear(); + serializing = serial; try { compare = Objects.class.getMethod("equals", Object.class, Object.class); } catch (NoSuchMethodException e) { @@ -30,8 +32,8 @@ public DiffReproGuidance(File inputFile, File traceDir) throws IOException { } } - public DiffReproGuidance(File inputFile, File traceDir, List cmpRes) throws IOException { - this(inputFile, traceDir); + public DiffReproGuidance(File inputFile, File traceDir, List cmpRes, boolean serial) throws IOException { + this(inputFile, traceDir, serial); cmpTo = cmpRes; } @@ -53,9 +55,12 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro // use serialization to load both outputs with the same ClassLoader //TODO may not want serialization for all diff repros 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(serializing) { + 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); diff --git a/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java b/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java index d47a917..bc1a5a4 100644 --- a/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java +++ b/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java @@ -140,6 +140,9 @@ public class ReproDiffGoal extends AbstractMojo { @Parameter(property="dumpArgsDir") private String dumpArgsDir; + @Parameter(property="serializing", defaultValue = "true") + private boolean serializing; + @Override public void execute() throws MojoExecutionException, MojoFailureException { ClassLoader loader; @@ -187,7 +190,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } try { - guidance = new DiffReproGuidance(inputFile, null); + guidance = new DiffReproGuidance(inputFile, null, serializing); result = GuidedFuzzing.run(testClassName, testMethod, loader, guidance, out); } catch (ClassNotFoundException e) { throw new MojoExecutionException("Could not load test class", e); From 28f3e77abf6380df5fa2db4f4b8e6503f4654738 Mon Sep 17 00:00:00 2001 From: Bella Laybourn Date: Mon, 7 Feb 2022 16:44:19 -0500 Subject: [PATCH 2/7] serialization flag for MutationGuidance --- .../mu2/diff/guidance/DiffReproGuidance.java | 5 ++--- .../java/cmu/pasta/mu2/diff/plugin/DiffGoal.java | 5 ++++- .../java/cmu/pasta/mu2/fuzz/MutationGuidance.java | 15 +++++++++++---- .../java/cmu/pasta/mu2/fuzz/MutationRunInfo.java | 7 +++++++ src/test/java/cmu/pasta/mu2/diff/DiffIT.java | 2 +- .../cmu/pasta/mu2/fuzz/MutationGuidanceIT.java | 2 +- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java index 9ba0e56..ab75fbb 100644 --- a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java +++ b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java @@ -18,7 +18,7 @@ public class DiffReproGuidance extends ReproGuidance implements DiffGuidance { private Method compare; protected List cmpTo; public static final List recentOutcomes = new ArrayList<>(); - private boolean serializing; + private final boolean serializing; public DiffReproGuidance(File inputFile, File traceDir, boolean serial) throws IOException { super(inputFile, traceDir); @@ -52,8 +52,7 @@ 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); Outcome cmpSerial = cmpOut, outSerial = out; if(serializing) { diff --git a/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java b/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java index 944be1d..78d0d6b 100644 --- a/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java +++ b/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java @@ -156,6 +156,9 @@ public class DiffGoal extends AbstractMojo { @Parameter(property="optLevel", defaultValue = "EXECUTION") private String optLevel; + @Parameter(property="serializing", defaultValue = "true") + private boolean serializing; + @Override public void execute() throws MojoExecutionException, MojoFailureException { ClassLoader loader; @@ -203,7 +206,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, serializing); } catch (DependencyResolutionRequiredException | MalformedURLException e) { throw new MojoExecutionException("Could not get project classpath", e); } catch (FileNotFoundException e) { diff --git a/src/main/java/cmu/pasta/mu2/fuzz/MutationGuidance.java b/src/main/java/cmu/pasta/mu2/fuzz/MutationGuidance.java index 4598d35..99ef81b 100644 --- a/src/main/java/cmu/pasta/mu2/fuzz/MutationGuidance.java +++ b/src/main/java/cmu/pasta/mu2/fuzz/MutationGuidance.java @@ -98,8 +98,10 @@ public class MutationGuidance extends ZestGuidance implements DiffGuidance { private final List exceptions = new ArrayList<>(); + private final boolean serializing; + 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 serializing) throws IOException { super(testName, duration, trials, outputDirectory, seedInputDir, rand); this.mutationClassLoaders = mutationClassLoaders; @@ -107,6 +109,7 @@ public MutationGuidance(String testName, MutationClassLoaders mutationClassLoade this.runCoverage = new MutationCoverage(); this.validCoverage = new MutationCoverage(); this.optLevel = mutationClassLoaders.getCartographyClassLoader().getOptLevel(); + this.serializing = serializing; try { compare = Objects.class.getMethod("equals", Object.class, Object.class); } catch (NoSuchMethodException e) { @@ -160,7 +163,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(serializing) argBytes = Serializer.serialize(args); int run = 1; for (MutationInstance mutationInstance : getMutationInstances()) { @@ -176,7 +180,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(serializing) mri = new MutationRunInfo(mutationClassLoaders, mutationInstance, testClass, argBytes, args, method); // run with MCL Outcome mclOutcome; @@ -185,8 +190,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(serializing) + mclOutcome = new Outcome(Serializer.translate(dtr.getOutput(), mutationClassLoaders.getCartographyClassLoader()), null); + else mclOutcome = new Outcome(dtr.getOutput(), null); } } catch (InstrumentationException e) { throw new GuidanceException(e); diff --git a/src/main/java/cmu/pasta/mu2/fuzz/MutationRunInfo.java b/src/main/java/cmu/pasta/mu2/fuzz/MutationRunInfo.java index 492d102..b0c24ed 100644 --- a/src/main/java/cmu/pasta/mu2/fuzz/MutationRunInfo.java +++ b/src/main/java/cmu/pasta/mu2/fuzz/MutationRunInfo.java @@ -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); diff --git a/src/test/java/cmu/pasta/mu2/diff/DiffIT.java b/src/test/java/cmu/pasta/mu2/diff/DiffIT.java index 1ffb551..c34de0e 100644 --- a/src/test/java/cmu/pasta/mu2/diff/DiffIT.java +++ b/src/test/java/cmu/pasta/mu2/diff/DiffIT.java @@ -37,7 +37,7 @@ private static class ProbedMutationGuidance extends MutationGuidance { List 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); } @Override diff --git a/src/test/java/cmu/pasta/mu2/fuzz/MutationGuidanceIT.java b/src/test/java/cmu/pasta/mu2/fuzz/MutationGuidanceIT.java index f12aff6..09abb4a 100644 --- a/src/test/java/cmu/pasta/mu2/fuzz/MutationGuidanceIT.java +++ b/src/test/java/cmu/pasta/mu2/fuzz/MutationGuidanceIT.java @@ -39,7 +39,7 @@ private static class ProbedMutationGuidance extends MutationGuidance { List 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); } @Override From e21d2340f7d731127da409764f3fe9d1f95b2999 Mon Sep 17 00:00:00 2001 From: Bella Laybourn Date: Mon, 14 Feb 2022 16:58:58 -0500 Subject: [PATCH 3/7] update serialization for DMRG --- .../mu2/diff/guidance/DiffMutationReproGuidance.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java index f6c3e87..99f27cc 100644 --- a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java +++ b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java @@ -58,12 +58,15 @@ public class DiffMutationReproGuidance extends DiffReproGuidance { */ private static ArraySet runMutants = new ArraySet(); - public DiffMutationReproGuidance(File inputFile, File traceDir, MutationClassLoaders mcls) throws IOException { + private boolean serializing; + + public DiffMutationReproGuidance(File inputFile, File traceDir, MutationClassLoaders mcls, boolean serial) throws IOException { super(inputFile, traceDir, true); cclOutcomes = new ArrayList<>(); mclOutcomes = new HashMap<>(); MCLs = mcls; ind = -1; + serializing = serial; for(MutationInstance mutationInstance : MCLs.getCartographyClassLoader().getMutationInstances()) { mclOutcomes.put(mutationInstance, new Pair<>(new ArrayList<>(), -1)); } @@ -92,7 +95,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(serializing) argBytes = Serializer.serialize(args); recentOutcomes.clear(); for (MutationInstance mutationInstance : MCLs.getCartographyClassLoader().getMutationInstances()) { @@ -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(serializing) mri = new MutationRunInfo(MCLs, mutationInstance, testClass, argBytes, args, method); // run with MCL try { From 9ef759e0675e79afee89a1c6c47c10508477d0de Mon Sep 17 00:00:00 2001 From: Bella Laybourn Date: Mon, 14 Feb 2022 16:59:56 -0500 Subject: [PATCH 4/7] adjust MutateDiffGoal to match --- src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java b/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java index 7d0d08d..e67b676 100644 --- a/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java +++ b/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java @@ -71,6 +71,9 @@ public class MutateDiffGoal extends AbstractMojo { @Parameter(property="optLevel", defaultValue = "execution") private String optLevel; + @Parameter(property="serializing", defaultValue = "true") + private boolean serializing; + @Override public void execute() throws MojoExecutionException, MojoFailureException { Log log = getLog(); @@ -98,7 +101,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); + DiffMutationReproGuidance dmrg = new DiffMutationReproGuidance(input, null, mcls, serializing); dmrg.setStopOnFailure(true); Result result = GuidedFuzzing.run(testClassName, testMethod, ccl, dmrg, null); if (!result.wasSuccessful()) { From a42610fd9afa9f10cab0de9f541fac67610bda60 Mon Sep 17 00:00:00 2001 From: Bella Laybourn Date: Sun, 20 Feb 2022 09:32:23 -0500 Subject: [PATCH 5/7] switch flags to not-serializing --- src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java | 6 +++--- src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java | 6 +++--- src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java b/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java index 78d0d6b..aa79a5b 100644 --- a/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java +++ b/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java @@ -156,8 +156,8 @@ public class DiffGoal extends AbstractMojo { @Parameter(property="optLevel", defaultValue = "EXECUTION") private String optLevel; - @Parameter(property="serializing", defaultValue = "true") - private boolean serializing; + @Parameter(property="noSerialization", defaultValue = "false") + private boolean notSerializing; @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -206,7 +206,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, serializing); + guidance = new MutationGuidance(targetName, mcl, duration, trials, resultsDir, seedsDir, rnd, !notSerializing); } catch (DependencyResolutionRequiredException | MalformedURLException e) { throw new MojoExecutionException("Could not get project classpath", e); } catch (FileNotFoundException e) { diff --git a/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java b/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java index 8810371..e67ba09 100644 --- a/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java +++ b/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java @@ -71,8 +71,8 @@ public class MutateDiffGoal extends AbstractMojo { @Parameter(property="optLevel", defaultValue = "execution") private String optLevel; - @Parameter(property="serializing", defaultValue = "true") - private boolean serializing; + @Parameter(property="noSerialization", defaultValue = "false") + private boolean notSerializing; @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -101,7 +101,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, serializing, resultsDir); + DiffMutationReproGuidance dmrg = new DiffMutationReproGuidance(input, null, mcls, !notSerializing, resultsDir); dmrg.setStopOnFailure(true); Result result = GuidedFuzzing.run(testClassName, testMethod, ccl, dmrg, null); if (!result.wasSuccessful()) { diff --git a/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java b/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java index bc1a5a4..3f04347 100644 --- a/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java +++ b/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java @@ -140,8 +140,8 @@ public class ReproDiffGoal extends AbstractMojo { @Parameter(property="dumpArgsDir") private String dumpArgsDir; - @Parameter(property="serializing", defaultValue = "true") - private boolean serializing; + @Parameter(property="noSerialization", defaultValue = "false") + private boolean notSerializing; @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -190,7 +190,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } try { - guidance = new DiffReproGuidance(inputFile, null, serializing); + guidance = new DiffReproGuidance(inputFile, null, !notSerializing); result = GuidedFuzzing.run(testClassName, testMethod, loader, guidance, out); } catch (ClassNotFoundException e) { throw new MojoExecutionException("Could not load test class", e); From ea2f36c310a82794e62d5d1fe0b054de03379bec Mon Sep 17 00:00:00 2001 From: Bella Laybourn Date: Sun, 20 Feb 2022 09:39:14 -0500 Subject: [PATCH 6/7] separate input + output serialization --- .../diff/guidance/DiffMutationReproGuidance.java | 12 +++++++----- .../pasta/mu2/diff/guidance/DiffReproGuidance.java | 14 ++++++++------ .../java/cmu/pasta/mu2/diff/plugin/DiffGoal.java | 9 ++++++--- .../cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java | 9 ++++++--- .../cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java | 9 ++++++--- .../java/cmu/pasta/mu2/fuzz/MutationGuidance.java | 14 ++++++++------ 6 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java index f030ba0..f494989 100644 --- a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java +++ b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java @@ -56,16 +56,18 @@ public class DiffMutationReproGuidance extends DiffReproGuidance { */ private static ArraySet runMutants = new ArraySet(); - private boolean serializing; + private boolean serializeIn; + private boolean serializeOut; private File reportFile; - public DiffMutationReproGuidance(File inputFile, File traceDir, MutationClassLoaders mcls, boolean serial, File resultsDir) throws IOException { + public DiffMutationReproGuidance(File inputFile, File traceDir, MutationClassLoaders mcls, boolean serialIn, boolean serialOut, File resultsDir) throws IOException { super(inputFile, traceDir, true); cclOutcomes = new ArrayList<>(); MCLs = mcls; ind = -1; - serializing = serial; + serializeIn = serialIn; + serializeOut = serialOut; reportFile = new File(resultsDir, "mutate-repro-out.txt"); this.optLevel = MCLs.getCartographyClassLoader().getOptLevel(); } @@ -97,7 +99,7 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro cmpTo = new ArrayList<>(recentOutcomes); cclOutcomes.add(cmpTo.get(0)); byte[] argBytes = null; - if(serializing) argBytes = Serializer.serialize(args); + if(serializeIn) argBytes = Serializer.serialize(args); recentOutcomes.clear(); for (MutationInstance mutationInstance : MCLs.getCartographyClassLoader().getMutationInstances()) { @@ -110,7 +112,7 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro } MutationRunInfo mri = new MutationRunInfo(MCLs, mutationInstance, testClass, args, method); - if(serializing) mri = new MutationRunInfo(MCLs, mutationInstance, testClass, argBytes, args, method); + if(serializeIn) mri = new MutationRunInfo(MCLs, mutationInstance, testClass, argBytes, args, method); // run with MCL System.out.println("Running Mutant " + mutationInstance); diff --git a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java index ab75fbb..322b71e 100644 --- a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java +++ b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffReproGuidance.java @@ -18,13 +18,15 @@ public class DiffReproGuidance extends ReproGuidance implements DiffGuidance { private Method compare; protected List cmpTo; public static final List recentOutcomes = new ArrayList<>(); - private final boolean serializing; + private boolean serializeIn; + private boolean serializeOut; - public DiffReproGuidance(File inputFile, File traceDir, boolean serial) throws IOException { + public DiffReproGuidance(File inputFile, File traceDir, boolean serialIn, boolean serialOut) throws IOException { super(inputFile, traceDir); cmpTo = null; recentOutcomes.clear(); - serializing = serial; + serializeIn = serialIn; + serializeOut = serialOut; try { compare = Objects.class.getMethod("equals", Object.class, Object.class); } catch (NoSuchMethodException e) { @@ -32,8 +34,8 @@ public DiffReproGuidance(File inputFile, File traceDir, boolean serial) throws I } } - public DiffReproGuidance(File inputFile, File traceDir, List cmpRes, boolean serial) throws IOException { - this(inputFile, traceDir, serial); + public DiffReproGuidance(File inputFile, File traceDir, List cmpRes, boolean serialIn, boolean serialOut) throws IOException { + this(inputFile, traceDir, serialIn, serialOut); cmpTo = cmpRes; } @@ -55,7 +57,7 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro // optionally use serialization to load both outputs with the same ClassLoader Outcome cmpOut = cmpTo.get(recentOutcomes.size() - 1); Outcome cmpSerial = cmpOut, outSerial = out; - if(serializing) { + 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); diff --git a/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java b/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java index aa79a5b..61ab410 100644 --- a/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java +++ b/src/main/java/cmu/pasta/mu2/diff/plugin/DiffGoal.java @@ -156,8 +156,11 @@ public class DiffGoal extends AbstractMojo { @Parameter(property="optLevel", defaultValue = "EXECUTION") private String optLevel; - @Parameter(property="noSerialization", defaultValue = "false") - private boolean notSerializing; + @Parameter(property="disableInputSerialization", defaultValue = "false") + private boolean disableInputSerialization; + + @Parameter(property="disableOutputSerialization", defaultValue = "false") + private boolean disableOutputSerialization; @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -206,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, !notSerializing); + 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) { diff --git a/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java b/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java index e67ba09..2767170 100644 --- a/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java +++ b/src/main/java/cmu/pasta/mu2/diff/plugin/MutateDiffGoal.java @@ -71,8 +71,11 @@ public class MutateDiffGoal extends AbstractMojo { @Parameter(property="optLevel", defaultValue = "execution") private String optLevel; - @Parameter(property="noSerialization", defaultValue = "false") - private boolean notSerializing; + @Parameter(property="disableInputSerialization", defaultValue = "false") + private boolean disableInputSerialization; + + @Parameter(property="disableOutputSerialization", defaultValue = "false") + private boolean disableOutputSerialization; @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -101,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, !notSerializing, 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()) { diff --git a/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java b/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java index 3f04347..4ae0d45 100644 --- a/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java +++ b/src/main/java/cmu/pasta/mu2/diff/plugin/ReproDiffGoal.java @@ -140,8 +140,11 @@ public class ReproDiffGoal extends AbstractMojo { @Parameter(property="dumpArgsDir") private String dumpArgsDir; - @Parameter(property="noSerialization", defaultValue = "false") - private boolean notSerializing; + @Parameter(property="disableInputSerialization", defaultValue = "false") + private boolean disableInputSerialization; + + @Parameter(property="disableOutputSerialization", defaultValue = "false") + private boolean disableOutputSerialization; @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -190,7 +193,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } try { - guidance = new DiffReproGuidance(inputFile, null, !notSerializing); + 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); diff --git a/src/main/java/cmu/pasta/mu2/fuzz/MutationGuidance.java b/src/main/java/cmu/pasta/mu2/fuzz/MutationGuidance.java index 99ef81b..d431a25 100644 --- a/src/main/java/cmu/pasta/mu2/fuzz/MutationGuidance.java +++ b/src/main/java/cmu/pasta/mu2/fuzz/MutationGuidance.java @@ -98,10 +98,11 @@ public class MutationGuidance extends ZestGuidance implements DiffGuidance { private final List exceptions = new ArrayList<>(); - private final boolean serializing; + private boolean serializeIn; + private boolean serializeOut; public MutationGuidance(String testName, MutationClassLoaders mutationClassLoaders, - Duration duration, Long trials, File outputDirectory, File seedInputDir, Random rand, boolean serializing) + 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; @@ -109,7 +110,8 @@ public MutationGuidance(String testName, MutationClassLoaders mutationClassLoade this.runCoverage = new MutationCoverage(); this.validCoverage = new MutationCoverage(); this.optLevel = mutationClassLoaders.getCartographyClassLoader().getOptLevel(); - this.serializing = serializing; + serializeIn = serialIn; + serializeOut = serialOut; try { compare = Objects.class.getMethod("equals", Object.class, Object.class); } catch (NoSuchMethodException e) { @@ -164,7 +166,7 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro // set up info long trialTime = System.currentTimeMillis() - startTime; byte[] argBytes = null; - if(serializing) argBytes = Serializer.serialize(args); + if(serializeIn) argBytes = Serializer.serialize(args); int run = 1; for (MutationInstance mutationInstance : getMutationInstances()) { @@ -181,7 +183,7 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro mutationInstance.resetTimer(); MutationRunInfo mri = new MutationRunInfo(mutationClassLoaders, mutationInstance, testClass, args, method); - if(serializing) mri = new MutationRunInfo(mutationClassLoaders, mutationInstance, testClass, argBytes, args, method); + if(serializeIn) mri = new MutationRunInfo(mutationClassLoaders, mutationInstance, testClass, argBytes, args, method); // run with MCL Outcome mclOutcome; @@ -190,7 +192,7 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro dtr.run(); if(dtr.getOutput() == null) mclOutcome = new Outcome(null, null); else { - if(serializing) + if(serializeOut) mclOutcome = new Outcome(Serializer.translate(dtr.getOutput(), mutationClassLoaders.getCartographyClassLoader()), null); else mclOutcome = new Outcome(dtr.getOutput(), null); From 94a3f63aa949a46c662e2ac464d2b3242f83a910 Mon Sep 17 00:00:00 2001 From: Bella Laybourn Date: Sun, 20 Feb 2022 09:41:41 -0500 Subject: [PATCH 7/7] cleanup --- .../cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java | 2 +- src/test/java/cmu/pasta/mu2/diff/DiffIT.java | 2 +- src/test/java/cmu/pasta/mu2/fuzz/MutationGuidanceIT.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java index f494989..7967665 100644 --- a/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java +++ b/src/main/java/cmu/pasta/mu2/diff/guidance/DiffMutationReproGuidance.java @@ -62,7 +62,7 @@ public class DiffMutationReproGuidance extends DiffReproGuidance { private File reportFile; public DiffMutationReproGuidance(File inputFile, File traceDir, MutationClassLoaders mcls, boolean serialIn, boolean serialOut, File resultsDir) throws IOException { - super(inputFile, traceDir, true); + super(inputFile, traceDir, serialIn, serialOut); cclOutcomes = new ArrayList<>(); MCLs = mcls; ind = -1; diff --git a/src/test/java/cmu/pasta/mu2/diff/DiffIT.java b/src/test/java/cmu/pasta/mu2/diff/DiffIT.java index c34de0e..ea5b411 100644 --- a/src/test/java/cmu/pasta/mu2/diff/DiffIT.java +++ b/src/test/java/cmu/pasta/mu2/diff/DiffIT.java @@ -37,7 +37,7 @@ private static class ProbedMutationGuidance extends MutationGuidance { List inputHashes = new ArrayList<>(); ProbedMutationGuidance(MutationClassLoaders mcls, long trials, Random rnd) throws IOException { - super(null, mcls,null, trials, resultsDir, null, rnd, true); + super(null, mcls,null, trials, resultsDir, null, rnd, true, true); } @Override diff --git a/src/test/java/cmu/pasta/mu2/fuzz/MutationGuidanceIT.java b/src/test/java/cmu/pasta/mu2/fuzz/MutationGuidanceIT.java index 09abb4a..1daa694 100644 --- a/src/test/java/cmu/pasta/mu2/fuzz/MutationGuidanceIT.java +++ b/src/test/java/cmu/pasta/mu2/fuzz/MutationGuidanceIT.java @@ -39,7 +39,7 @@ private static class ProbedMutationGuidance extends MutationGuidance { List inputHashes = new ArrayList<>(); ProbedMutationGuidance(MutationClassLoaders mcls, long trials, Random rnd) throws IOException { - super(null, mcls,null, trials, resultsDir, null, rnd, true); + super(null, mcls,null, trials, resultsDir, null, rnd, true, true); } @Override