public class ForwardGenerator extends AbstractGenerator
Modifier and Type | Class and Description |
---|---|
private static class |
ForwardGenerator.VarAndSeq |
Modifier and Type | Field and Description |
---|---|
private java.util.LinkedHashSet<Sequence> |
allSequences
The set of ALL sequences ever generated, including sequences that were executed and then
discarded.
|
private java.util.List<java.lang.String> |
allsequencesAsCode
Set and used only if
GenInputsAbstract.debug_checks ==true. |
private java.util.List<Sequence> |
allsequencesAsList
Set and used only if
GenInputsAbstract.debug_checks ==true. |
private InputSequenceSelector |
inputSequenceSelector
How to select sequences as input for creating new sequences.
|
private TypeInstantiator |
instantiator |
private TypedOperationSelector |
operationSelector
How to select the method to use for creating a new sequence.
|
private java.util.Set<java.lang.Object> |
runtimePrimitivesSeen
The set of all primitive values seen during generation and execution of sequences.
|
private java.util.Set<TypedOperation> |
sideEffectFreeMethods
The side-effect-free methods.
|
checkGenerator, componentManager, currSeq, dump_sequences, executionVisitor, invalidSequenceCount, limits, null_steps, num_failed_output_test, num_failing_sequences, num_sequences_generated, num_steps, operationHistory, operations, outErrorSeqs, outputTest, outRegressionSeqs, subsumed_sequences
Constructor and Description |
---|
ForwardGenerator(java.util.List<TypedOperation> operations,
java.util.Set<TypedOperation> sideEffectFreeMethods,
GenInputsAbstract.Limits limits,
ComponentManager componentManager,
IStopper stopper,
java.util.Set<ClassOrInterfaceType> classesUnderTest)
Create a forward generator.
|
ForwardGenerator(java.util.List<TypedOperation> operations,
java.util.Set<TypedOperation> sideEffectFreeMethods,
GenInputsAbstract.Limits limits,
ComponentManager componentManager,
java.util.Set<ClassOrInterfaceType> classesUnderTest)
Create a forward generator.
|
Modifier and Type | Method and Description |
---|---|
private ExecutableSequence |
createNewUniqueSequence()
Tries to create a new sequence.
|
private void |
determineActiveIndices(ExecutableSequence seq)
Determines what indices in the given sequence are active.
|
java.util.Set<Sequence> |
getAllSequences()
Return all sequences generated by this object.
|
private void |
initializeRuntimePrimitivesSeen()
The runtimePrimitivesSeen set contains primitive values seen during generation/execution and is
used to determine new values that should be added to the component set.
|
void |
newRegressionTestHook(Sequence sequence)
Take action based on the given
Sequence that was classified as a regression test. |
int |
numGeneratedSequences()
Returns the count of sequences generated so far by the generator.
|
(package private) ForwardGenerator.VarAndSeq |
randomVariable(SimpleList<Sequence> candidates,
Type inputType,
boolean isReceiver)
Return a variable of the given type.
|
private void |
randoopConsistencyTest2(Sequence newSequence) |
private void |
randoopConsistencyTests(Sequence newSequence) |
private Sequence |
repeat(Sequence seq,
TypedOperation operation,
int times)
Adds the given operation to a new
Sequence with the statements of this object as a
prefix, repeating the operation the given number of times. |
private InputsAndSuccessFlag |
selectInputs(TypedOperation operation)
This method is responsible for doing two things:
Selecting at random a collection of sequences that can be used to create input values for
the given statement, and
Selecting at random valid indices to the above sequence specifying the values to be used
as input to the statement.
|
@Nullable ExecutableSequence |
step()
Attempt to generate a test (a sequence).
|
java.lang.String |
toString() |
createAndClassifySequences, getErrorTestSequences, getOperationHistory, getRegressionSequences, numAttemptedSequences, numOutputSequences, outputSequenceCount, setCurrentSequence, setExecutionVisitor, setExecutionVisitor, setOperationHistoryLogger, setTestCheckGenerator, setTestPredicate, shouldStop
private final java.util.LinkedHashSet<Sequence> allSequences
This must be ordered by insertion to allow for flaky test history collection in GenTests.printSequenceExceptionError(AbstractGenerator, SequenceExceptionError)
.
private final java.util.Set<TypedOperation> sideEffectFreeMethods
private final java.util.List<java.lang.String> allsequencesAsCode
GenInputsAbstract.debug_checks
==true. This contains the same
components as allSequences
, in the same order, but stores them as strings obtained via
the toCodeString() method.private final java.util.List<Sequence> allsequencesAsList
GenInputsAbstract.debug_checks
==true. This contains the same
components as allSequences
, in the same order, but can be accessed by index.private final TypeInstantiator instantiator
private final InputSequenceSelector inputSequenceSelector
private final TypedOperationSelector operationSelector
private java.util.Set<java.lang.Object> runtimePrimitivesSeen
Each value in the collection is a primitive wrapper or a String.
public ForwardGenerator(java.util.List<TypedOperation> operations, java.util.Set<TypedOperation> sideEffectFreeMethods, GenInputsAbstract.Limits limits, ComponentManager componentManager, java.util.Set<ClassOrInterfaceType> classesUnderTest)
operations
- list of operations under testsideEffectFreeMethods
- side-effect-free methodslimits
- limits for generation, after which the generator will stopcomponentManager
- stores previously-generated sequencesclassesUnderTest
- set of classes under testpublic ForwardGenerator(java.util.List<TypedOperation> operations, java.util.Set<TypedOperation> sideEffectFreeMethods, GenInputsAbstract.Limits limits, ComponentManager componentManager, IStopper stopper, java.util.Set<ClassOrInterfaceType> classesUnderTest)
operations
- list of methods under testsideEffectFreeMethods
- side-effect-free methodslimits
- limits for generation, after which the generator will stopcomponentManager
- container for sequences that are used to generate new sequencesstopper
- determines when the test generation process should conclude. Can be null.classesUnderTest
- the classes that are under testpublic void newRegressionTestHook(Sequence sequence)
Sequence
that was classified as a regression test.newRegressionTestHook
in class AbstractGenerator
sequence
- the new sequence that was classified as a regression testprivate void initializeRuntimePrimitivesSeen()
public @Nullable ExecutableSequence step()
AbstractGenerator
step
in class AbstractGenerator
public java.util.Set<Sequence> getAllSequences()
AbstractGenerator
getAllSequences
in class AbstractGenerator
private void determineActiveIndices(ExecutableSequence seq)
An active index i means that the i-th method call creates an interesting/useful value that can be used as an input to a larger sequence; inactive indices are never used as inputs. The SequenceCollection to which the given sequences is added only considers the active indices when deciding whether the sequence creates values of a given type.
In addition to determining active indices, this method determines if any primitive values created during execution of the sequence are new values not encountered before. Such values are added to the component manager so they can be used during subsequent generation attempts.
seq
- the sequence, all of whose indices are initially marked as activeprivate ExecutableSequence createNewUniqueSequence()
This method returns null if:
private Sequence repeat(Sequence seq, TypedOperation operation, int times)
Sequence
with the statements of this object as a
prefix, repeating the operation the given number of times. Used during generation.seq
- the sequence to extendoperation
- the TypedOperation
to repeattimes
- the number of times to repeat the Operation
Sequence
private void randoopConsistencyTest2(Sequence newSequence)
private void randoopConsistencyTests(Sequence newSequence)
private InputsAndSuccessFlag selectInputs(TypedOperation operation)
The selected sequences and indices are wrapped in an InputsAndSuccessFlag object and returned. If an appropriate collection of sequences and indices was not found (e.g. because there are no sequences in the componentManager that create values of some type required by the statement), the success flag of the returned object is false.
operation
- the statement to analyzeForwardGenerator.VarAndSeq randomVariable(SimpleList<Sequence> candidates, Type inputType, boolean isReceiver)
candidates
- sequences, each of which produces a value of type inputType
; that is,
each would be a legal return valueinputType
- the type of the chosen variable/sequenceisReceiver
- whether the value will be used as a receiverpublic int numGeneratedSequences()
AbstractGenerator
numGeneratedSequences
in class AbstractGenerator
public java.lang.String toString()
toString
in class java.lang.Object