Class ReproGuidance
- java.lang.Object
-
- edu.berkeley.cs.jqf.fuzz.repro.ReproGuidance
-
- All Implemented Interfaces:
Guidance
- Direct Known Subclasses:
DiffFuzzReproGuidance
public class ReproGuidance extends Object implements Guidance
A front-end that provides a specified set of inputs for test case reproduction, This class enables reproduction of a test case with an input file generated by a guided fuzzing front-end such as AFL.- Author:
- Rohan Padhye
-
-
Constructor Summary
Constructors Constructor Description ReproGuidance(File[] inputFiles, File traceDir)
Constructs an instance of ReproGuidance with a list of input files to replay and a directory where the trace events may be logged.ReproGuidance(File inputFile, File traceDir)
Constructs an instance of ReproGuidance with a single input file or with a directory of input files to replay, and a directory where the trace events may be logged.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Consumer<TraceEvent>
generateCallBack(Thread thread)
Returns a callback that can log trace events or code coverage info.Set<String>
getBranchesCovered()
Retyrns the set of branches covered by this repro.Coverage
getCoverage()
Returns a reference to the coverage statistics.InputStream
getInput()
Returns an input stream corresponding to the next input file.void
handleResult(Result result, Throwable error)
Logs the end of run in the log files, if any.boolean
hasInput()
Returnstrue
if there are more input files to replay.void
jacocoCheckpoint(File classFile, File csvDir)
void
observeGeneratedArgs(Object[] args)
Callback for observing actual arguments passed to the test method.void
setStopOnFailure(boolean value)
Configure whether the repro execution should stop as soon as the first failure is encountered.
-
-
-
Constructor Detail
-
ReproGuidance
public ReproGuidance(File[] inputFiles, File traceDir) throws IOException
Constructs an instance of ReproGuidance with a list of input files to replay and a directory where the trace events may be logged.- Parameters:
inputFiles
- a list of input filestraceDir
- an optional directory, which if non-null will be the destination for log files containing event traces- Throws:
IOException
-
ReproGuidance
public ReproGuidance(File inputFile, File traceDir) throws IOException
Constructs an instance of ReproGuidance with a single input file or with a directory of input files to replay, and a directory where the trace events may be logged.- Parameters:
inputFile
- an input file or directory of input filestraceDir
- an optional directory, which if non-null will be the destination for log files containing event traces- Throws:
FileNotFoundException
- if `inputFile` is not a valid file or directoryIOException
-
-
Method Detail
-
setStopOnFailure
public void setStopOnFailure(boolean value)
Configure whether the repro execution should stop as soon as the first failure is encountered.- Parameters:
value
- whether to stop the repro on failure
-
getInput
public InputStream getInput()
Returns an input stream corresponding to the next input file.
-
hasInput
public boolean hasInput()
Returnstrue
if there are more input files to replay.
-
observeGeneratedArgs
public void observeGeneratedArgs(Object[] args)
Description copied from interface:Guidance
Callback for observing actual arguments passed to the test method.This method is invoked exactly once after each call to
Guidance.getInput()
. The arguments to this callback are the structured inputs that are produced by junit-quickcheck generators, which in turn decode the bytes produced byGuidance.getInput()
.This method is useful for logging the generated args or for calculating the size of the generated args. The default implementation does nothing.
- Specified by:
observeGeneratedArgs
in interfaceGuidance
- Parameters:
args
- an array of arguments that will be passed to the test method; the size of this array is equal to the number of formal parameters to the test method
-
handleResult
public void handleResult(Result result, Throwable error)
Logs the end of run in the log files, if any.- Specified by:
handleResult
in interfaceGuidance
- Parameters:
result
- the result of the fuzzing trialerror
- the error thrown during the trial, ornull
-
generateCallBack
public Consumer<TraceEvent> generateCallBack(Thread thread)
Returns a callback that can log trace events or code coverage info.If the system property
jqf.repro.logUniqueBranches
was set totrue
, then the callback collects coverage info into the setbranchesCoveredInCurrentRun
, which can be accessed usinggetBranchesCovered()
.Otherwise, if the
traceDir
was non-null during the construction of this Guidance instance, then one log file per thread of execution is created in this directory. The callbacks generated by this method write trace event descriptions in sequence to their own thread's log files.If neither of the above are true, the returned callback simply updates a total coverage map (see
getCoverage()
.- Specified by:
generateCallBack
in interfaceGuidance
- Parameters:
thread
- the thread whose events to handle- Returns:
- a callback to log code coverage or execution traces
-
getCoverage
public Coverage getCoverage()
Returns a reference to the coverage statistics.- Returns:
- a reference to the coverage statistics
-
getBranchesCovered
public Set<String> getBranchesCovered()
Retyrns the set of branches covered by this repro.This set will only be non-empty if the system property
jqf.repro.logUniqueBranches
was set totrue
before the guidance instance was constructed.The format of each element in this set is a custom format that strives to be both human and machine readable.
A branch is only logged for inputs that execute successfully. In particular, branches are not recorded for failing runs or for runs that violate assumptions.
- Returns:
- the set of branches covered by this repro
-
-