Package randoop.generation
Class AbstractGenerator
java.lang.Object
randoop.generation.AbstractGenerator
- Direct Known Subclasses:
ForwardGenerator
Algorithm template for implementing a test generator.
The main generation loop is defined in method createAndClassifySequences()
, which
repeatedly generates a new sequence, determines if it a failing sequence, and stops the process
when the time or sequence limit expires. The process of generating a new sequences is left
abstract.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected TestCheckGenerator
Visitor to generate checks for a sequence.Component manager responsible for storing previously-generated sequences.static Sequence
This field is set by Randoop to point to the sequence currently being executed.static boolean
If true, dump each sequence to the log file as it is generated.protected ExecutionVisitor
Container for execution visitors used during execution of sequences.int
Number of invalid sequences generated.final GenInputsAbstract.Limits
Limits for generation, after which the generator will stop.Manages notifications for listeners.int
Number of steps that returned null.int
Number of sequences that failed the output test.int
Number of failing sequences generated.int
Number of sequences generated.int
Number of generation steps (each an attempt to generate and execute a new, distinct sequence).protected OperationHistoryLogInterface
protected final List<TypedOperation>
The list of statement kinds (methods, constructors, primitive value declarations, etc.) used to generate sequences.The list of error test sequences to be output as JUnit tests.A filter to determine whether a sequence should be added to the output sequence lists.The list of regression sequences to be output as JUnit tests.private ProgressDisplay
Updates the progress display message printed to the console.private long
When the generator started (millisecond-based system timestamp).private IStopper
Customizable stopping criterion in addition to time and sequence limits.Sequences that are used in other sequences (and are thus redundant) -
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractGenerator
(List<TypedOperation> operations, GenInputsAbstract.Limits limits, ComponentManager componentManager, IStopper stopper, RandoopListenerManager listenerManager) Constructs a generator with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Creates and executes new sequences until stopping criteria is met.private long
Elapsed time since the generator started.abstract LinkedHashSet<Sequence>
Return all sequences generated by this object.Returns the generated error-revealing test sequences for output.Return the operation history logger for this generator.Returns the generated regression test sequences for output.abstract void
newRegressionTestHook
(Sequence sequence) Take action based on the givenSequence
that was classified as a regression test, i.e., normal behavior.int
Returns the count of attempts to generate a sequence so far.private int
Returns the count of generated error-revealing sequences.abstract int
Returns the count of sequences generated so far by the generator.int
Returns the count of generated sequence currently for output.int
Returns the total number of test sequences generated to output, including both regression tests and error-revealing tests.(package private) void
Sets the current sequence during exploration.void
setExecutionVisitor
(List<ExecutionVisitor> visitors) Registers a MultiVisitor of all the given visitors with this object for use while executing each generated sequence.void
setExecutionVisitor
(ExecutionVisitor executionVisitor) Registers a visitor with this object for use while executing each generated sequence.void
Sets the operation history logger for this generator.void
setTestCheckGenerator
(TestCheckGenerator checkGenerator) Registers a visitor with this object to generate checks following execution of each generated test sequence.void
setTestPredicate
(Predicate<ExecutableSequence> outputTest) Registers test predicate with this generator for use while filtering generated tests for output.protected boolean
Tests stopping criteria.abstract @Nullable ExecutableSequence
step()
Attempt to generate a test (a sequence).
-
Field Details
-
dump_sequences
public static boolean dump_sequencesIf true, dump each sequence to the log file as it is generated. Has no effect unless logging is enabled. -
num_steps
public int num_stepsNumber of generation steps (each an attempt to generate and execute a new, distinct sequence). -
null_steps
public int null_stepsNumber of steps that returned null. -
num_sequences_generated
public int num_sequences_generatedNumber of sequences generated. -
num_failing_sequences
public int num_failing_sequencesNumber of failing sequences generated. -
invalidSequenceCount
public int invalidSequenceCountNumber of invalid sequences generated. -
num_failed_output_test
public int num_failed_output_testNumber of sequences that failed the output test. -
startTime
private long startTimeWhen the generator started (millisecond-based system timestamp). -
subsumed_sequences
Sequences that are used in other sequences (and are thus redundant) -
limits
Limits for generation, after which the generator will stop. -
operations
The list of statement kinds (methods, constructors, primitive value declarations, etc.) used to generate sequences. In other words, statements specifies the universe of operations from which sequences are generated. -
executionVisitor
Container for execution visitors used during execution of sequences. -
componentManager
Component manager responsible for storing previously-generated sequences. -
stopper
Customizable stopping criterion in addition to time and sequence limits. -
listenerMgr
Manages notifications for listeners.- See Also:
-
progressDisplay
Updates the progress display message printed to the console. Null if GenInputsAbstrect.progressdisplay is false. -
currSeq
This field is set by Randoop to point to the sequence currently being executed. In the event that Randoop appears to hang, this sequence is printed out to console to help the user debug the cause of the hanging behavior. -
outErrorSeqs
The list of error test sequences to be output as JUnit tests. May include subsequences of other sequences in the list. -
outRegressionSeqs
The list of regression sequences to be output as JUnit tests. May include subsequences of other sequences in the list. -
outputTest
A filter to determine whether a sequence should be added to the output sequence lists. Returns true if the sequence should be output. -
checkGenerator
Visitor to generate checks for a sequence. -
operationHistory
-
-
Constructor Details
-
AbstractGenerator
protected AbstractGenerator(List<TypedOperation> operations, GenInputsAbstract.Limits limits, ComponentManager componentManager, IStopper stopper, RandoopListenerManager listenerManager) Constructs a generator with the given parameters.- Parameters:
operations
- statements (e.g. methods and constructors) used to create sequences. Cannot be null.limits
- maximum time and number of sequences to generate/outputcomponentManager
- the component manager to use to store sequences during component-based generation. Can be null, in which case the generator's component manager is initialized asnew ComponentManager()
.stopper
- optional, additional stopping criterion for the generator. Can be null.listenerManager
- manager that stores and calls any listeners to use during generation. Can be null.
-
-
Method Details
-
elapsedTime
private long elapsedTime()Elapsed time since the generator started.- Returns:
- elapsed time since the generator started
-
setTestPredicate
Registers test predicate with this generator for use while filtering generated tests for output.- Parameters:
outputTest
- the predicate to be added to object
-
setExecutionVisitor
Registers a visitor with this object for use while executing each generated sequence.- Parameters:
executionVisitor
- the visitor
-
setExecutionVisitor
Registers a MultiVisitor of all the given visitors with this object for use while executing each generated sequence.- Parameters:
visitors
- the list of visitors
-
setTestCheckGenerator
Registers a visitor with this object to generate checks following execution of each generated test sequence.- Parameters:
checkGenerator
- the check generating visitor
-
shouldStop
protected boolean shouldStop()Tests stopping criteria.- Returns:
- true iff any stopping criterion is met
-
step
Attempt to generate a test (a sequence).- Returns:
- a test sequence, may be null
-
numAttemptedSequences
public int numAttemptedSequences()Returns the count of attempts to generate a sequence so far.- Returns:
- the number of attempts to generate a sequence so far
-
numGeneratedSequences
public abstract int numGeneratedSequences()Returns the count of sequences generated so far by the generator.- Returns:
- the number of sequences generated
-
numOutputSequences
public int numOutputSequences()Returns the count of generated sequence currently for output.- Returns:
- the sum of the number of error and regression test sequences for output
-
numErrorSequences
private int numErrorSequences()Returns the count of generated error-revealing sequences.- Returns:
- the number of error test sequences
-
createAndClassifySequences
public void createAndClassifySequences()Creates and executes new sequences until stopping criteria is met.- See Also:
-
getAllSequences
Return all sequences generated by this object.- Returns:
- all generated sequences
-
getRegressionSequences
Returns the generated regression test sequences for output. Filters out subsequences.- Returns:
- regression test sequences that do not occur in a longer sequence
-
getErrorTestSequences
Returns the generated error-revealing test sequences for output.- Returns:
- the generated error test sequences
-
outputSequenceCount
public int outputSequenceCount()Returns the total number of test sequences generated to output, including both regression tests and error-revealing tests.- Returns:
- the total number of test sequences saved for output
-
setCurrentSequence
Sets the current sequence during exploration.- Parameters:
s
- the current sequence
-
setOperationHistoryLogger
Sets the operation history logger for this generator.- Parameters:
logger
- the operation history logger to use for this generator
-
getOperationHistory
Return the operation history logger for this generator.- Returns:
- the operation history logger for this generator
-
newRegressionTestHook
Take action based on the givenSequence
that was classified as a regression test, i.e., normal behavior.- Parameters:
sequence
- the new test sequence that was classified as a regression test, i.e., normal behavior
-