Skip to content

Commit

Permalink
write to file
Browse files Browse the repository at this point in the history
  • Loading branch information
saphirasnow committed Feb 5, 2022
1 parent d8c9ba9 commit d50f9b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import org.junit.runners.model.TestClass;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

/**
Expand Down Expand Up @@ -56,12 +58,16 @@ public class DiffMutationReproGuidance extends DiffReproGuidance {
*/
private static ArraySet runMutants = new ArraySet();

public DiffMutationReproGuidance(File inputFile, File traceDir, MutationClassLoaders mcls) throws IOException {
private File reportFile;

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

reportFile = new File(resultsDir, "dmrg-report.csv");

this.optLevel = MCLs.getCartographyClassLoader().getOptLevel();
}

Expand All @@ -84,6 +90,9 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro
} catch (Throwable e) {}

System.out.println("CCL Outcome for input " + ind + ": " + recentOutcomes.get(0));
try (PrintWriter pw = new PrintWriter(new FileOutputStream(reportFile, true))) {
pw.printf("CCL Outcome for input %d: %s\n", ind, recentOutcomes.get(0).toString());
}

// set up info
cmpTo = new ArrayList<>(recentOutcomes);
Expand All @@ -104,11 +113,18 @@ public void run(TestClass testClass, FrameworkMethod method, Object[] args) thro

// run with MCL
System.out.println("Running " + mutationInstance);
try (PrintWriter pw = new PrintWriter(new FileOutputStream(reportFile, true))) {
pw.printf("Running %s\n", mutationInstance.toString());
}

try {
super.run(new TestClass(mri.clazz), mri.method, mri.args);
} catch (DiffException e) {
deadMutants.add(mutationInstance.id);
System.out.println("killed by " + e);
try (PrintWriter pw = new PrintWriter(new FileOutputStream(reportFile, true))) {
pw.printf("killed by %s\n", e.toString());
}
} catch(InstrumentationException e) {
throw new GuidanceException(e);
} catch (GuidanceException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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, resultsDir);
dmrg.setStopOnFailure(true);
Result result = GuidedFuzzing.run(testClassName, testMethod, ccl, dmrg, null);
if (!result.wasSuccessful()) {
Expand Down

0 comments on commit d50f9b2

Please sign in to comment.