Skip to content

Commit

Permalink
Maven plugin: New -DnoCov option disables instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanpadhye committed Apr 6, 2020
1 parent 52800d0 commit 008432b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -142,6 +145,19 @@ public class FuzzGoal extends AbstractMojo {
@Parameter(property="blind")
private boolean blind;

/**
* Whether to disable code-coverage instrumentation.
*
* <p>Disabling instrumentation speeds up test case execution, but
* provides no feedback about code coverage in the status screen and
* to the fuzzing guidance.</p>
*
* <p>This setting only makes sense when used with {@code -Dblind}.</p>
*
*/
@Parameter(property="noCov")
private boolean disableCoverage;

/**
* The name of the input directory containing seed files.
*
Expand Down Expand Up @@ -263,9 +279,16 @@ public void execute() throws MojoExecutionException, MojoFailureException {
try {
List<String> 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);
}
Expand Down

0 comments on commit 008432b

Please sign in to comment.