From 008432b79aeda0b68dd709931e19c988faf21ed0 Mon Sep 17 00:00:00 2001 From: Rohan Padhye Date: Sun, 5 Apr 2020 22:57:18 -0700 Subject: [PATCH] Maven plugin: New -DnoCov option disables instrumentation --- .../instrument/InstrumentingClassLoader.java | 2 +- .../edu/berkeley/cs/jqf/plugin/FuzzGoal.java | 29 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/instrument/src/main/java/edu/berkeley/cs/jqf/instrument/InstrumentingClassLoader.java b/instrument/src/main/java/edu/berkeley/cs/jqf/instrument/InstrumentingClassLoader.java index c70223c95..b582657dc 100644 --- a/instrument/src/main/java/edu/berkeley/cs/jqf/instrument/InstrumentingClassLoader.java +++ b/instrument/src/main/java/edu/berkeley/cs/jqf/instrument/InstrumentingClassLoader.java @@ -56,7 +56,7 @@ public InstrumentingClassLoader(String[] paths, ClassLoader parent) throws Malfo this(stringsToUrls(paths), parent); } - private static URL[] stringsToUrls(String[] paths) throws MalformedURLException { + public static URL[] stringsToUrls(String[] paths) throws MalformedURLException { URL[] urls = new URL[paths.length]; for (int i = 0; i < paths.length; i++) { urls[i] = new File(paths[i]).toURI().toURL(); diff --git a/maven-plugin/src/main/java/edu/berkeley/cs/jqf/plugin/FuzzGoal.java b/maven-plugin/src/main/java/edu/berkeley/cs/jqf/plugin/FuzzGoal.java index 36cd42525..8c456eed6 100644 --- a/maven-plugin/src/main/java/edu/berkeley/cs/jqf/plugin/FuzzGoal.java +++ b/maven-plugin/src/main/java/edu/berkeley/cs/jqf/plugin/FuzzGoal.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.io.PrintStream; import java.net.MalformedURLException; +import java.net.URLClassLoader; import java.time.Duration; import java.time.format.DateTimeParseException; import java.util.List; @@ -51,6 +52,8 @@ import org.apache.maven.project.MavenProject; import org.junit.runner.Result; +import static edu.berkeley.cs.jqf.instrument.InstrumentingClassLoader.stringsToUrls; + /** * Maven plugin for feedback-directed fuzzing using JQF. * @@ -142,6 +145,19 @@ public class FuzzGoal extends AbstractMojo { @Parameter(property="blind") private boolean blind; + /** + * Whether to disable code-coverage instrumentation. + * + *

Disabling instrumentation speeds up test case execution, but + * provides no feedback about code coverage in the status screen and + * to the fuzzing guidance.

+ * + *

This setting only makes sense when used with {@code -Dblind}.

+ * + */ + @Parameter(property="noCov") + private boolean disableCoverage; + /** * The name of the input directory containing seed files. * @@ -263,9 +279,16 @@ public void execute() throws MojoExecutionException, MojoFailureException { try { List classpathElements = project.getTestClasspathElements(); - loader = new InstrumentingClassLoader( - classpathElements.toArray(new String[0]), - getClass().getClassLoader()); + if (disableCoverage) { + loader = new URLClassLoader( + stringsToUrls(classpathElements.toArray(new String[0])), + getClass().getClassLoader()); + + } else { + loader = new InstrumentingClassLoader( + classpathElements.toArray(new String[0]), + getClass().getClassLoader()); + } } catch (DependencyResolutionRequiredException|MalformedURLException e) { throw new MojoExecutionException("Could not get project classpath", e); }