Class ForwardGenerator
- java.lang.Object
-
- randoop.generation.AbstractGenerator
-
- randoop.generation.ForwardGenerator
-
public class ForwardGenerator extends AbstractGenerator
Randoop's forward, component-based generator.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ForwardGenerator.VarAndSeq
-
Field Summary
Fields Modifier and Type Field Description private LinkedHashSet<Sequence>
allSequences
The set of ALL sequences ever generated, including sequences that were executed and then discarded.private List<String>
allsequencesAsCode
Set and used only ifGenInputsAbstract.debug_checks
==true.private List<Sequence>
allsequencesAsList
Set and used only ifGenInputsAbstract.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 Set<Object>
runtimePrimitivesSeen
The set of all primitive values seen during generation and execution of sequences.private Set<TypedOperation>
sideEffectFreeMethods
The side-effect-free methods.-
Fields inherited from class randoop.generation.AbstractGenerator
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 Summary
Constructors Constructor Description ForwardGenerator(List<TypedOperation> operations, Set<TypedOperation> sideEffectFreeMethods, GenInputsAbstract.Limits limits, ComponentManager componentManager, Set<ClassOrInterfaceType> classesUnderTest)
Create a forward generator.ForwardGenerator(List<TypedOperation> operations, Set<TypedOperation> sideEffectFreeMethods, GenInputsAbstract.Limits limits, ComponentManager componentManager, IStopper stopper, Set<ClassOrInterfaceType> classesUnderTest)
Create a forward generator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private ExecutableSequence
createNewUniqueSequence()
Tries to create a new sequence.private void
determineActiveIndices(ExecutableSequence seq)
Determines what indices in the given sequence are active.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 givenSequence
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 newSequence
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).String
toString()
-
Methods inherited from class randoop.generation.AbstractGenerator
createAndClassifySequences, getErrorTestSequences, getOperationHistory, getRegressionSequences, numAttemptedSequences, numOutputSequences, outputSequenceCount, setCurrentSequence, setExecutionVisitor, setExecutionVisitor, setOperationHistoryLogger, setTestCheckGenerator, setTestPredicate, shouldStop
-
-
-
-
Field Detail
-
allSequences
private final LinkedHashSet<Sequence> allSequences
The set of ALL sequences ever generated, including sequences that were executed and then discarded.This must be ordered by insertion to allow for flaky test history collection in
GenTests.printSequenceExceptionError(AbstractGenerator, SequenceExceptionError)
.
-
sideEffectFreeMethods
private final Set<TypedOperation> sideEffectFreeMethods
The side-effect-free methods.
-
allsequencesAsCode
private final List<String> allsequencesAsCode
Set and used only ifGenInputsAbstract.debug_checks
==true. This contains the same components asallSequences
, in the same order, but stores them as strings obtained via the toCodeString() method.
-
allsequencesAsList
private final List<Sequence> allsequencesAsList
Set and used only ifGenInputsAbstract.debug_checks
==true. This contains the same components asallSequences
, in the same order, but can be accessed by index.
-
instantiator
private final TypeInstantiator instantiator
-
inputSequenceSelector
private final InputSequenceSelector inputSequenceSelector
How to select sequences as input for creating new sequences.
-
operationSelector
private final TypedOperationSelector operationSelector
How to select the method to use for creating a new sequence.
-
runtimePrimitivesSeen
private Set<Object> runtimePrimitivesSeen
The set of all primitive values seen during generation and execution of sequences. This set is used to tell if a new primitive value has been generated, to add the value to the components.Each value in the collection is a primitive wrapper or a String.
-
-
Constructor Detail
-
ForwardGenerator
public ForwardGenerator(List<TypedOperation> operations, Set<TypedOperation> sideEffectFreeMethods, GenInputsAbstract.Limits limits, ComponentManager componentManager, Set<ClassOrInterfaceType> classesUnderTest)
Create a forward generator.- Parameters:
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 test
-
ForwardGenerator
public ForwardGenerator(List<TypedOperation> operations, Set<TypedOperation> sideEffectFreeMethods, GenInputsAbstract.Limits limits, ComponentManager componentManager, IStopper stopper, Set<ClassOrInterfaceType> classesUnderTest)
Create a forward generator.- Parameters:
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 test
-
-
Method Detail
-
newRegressionTestHook
public void newRegressionTestHook(Sequence sequence)
Take action based on the givenSequence
that was classified as a regression test.- Specified by:
newRegressionTestHook
in classAbstractGenerator
- Parameters:
sequence
- the new sequence that was classified as a regression test
-
initializeRuntimePrimitivesSeen
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. The component set initially contains a set of primitive sequences; this method puts those primitives in this set.
-
step
public @Nullable ExecutableSequence step()
Description copied from class:AbstractGenerator
Attempt to generate a test (a sequence).- Specified by:
step
in classAbstractGenerator
- Returns:
- a test sequence, may be null
-
getAllSequences
public Set<Sequence> getAllSequences()
Description copied from class:AbstractGenerator
Return all sequences generated by this object.- Specified by:
getAllSequences
in classAbstractGenerator
- Returns:
- all generated sequences
-
determineActiveIndices
private void determineActiveIndices(ExecutableSequence seq)
Determines what indices in the given sequence are active. (Actually, sets some indices as not active, since the default is that every index is active.)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.
- Parameters:
seq
- the sequence, all of whose indices are initially marked as active
-
createNewUniqueSequence
private ExecutableSequence createNewUniqueSequence()
Tries to create a new sequence. If the sequence is new (not already in the specified component manager), then adds it to the manager's sequences.This method returns null if:
- it selects an operation but cannot generate inputs for the operation
- it creates too large a method
- it creates a duplicate sequence
- Returns:
- a new sequence, or null
-
repeat
private Sequence repeat(Sequence seq, TypedOperation operation, int times)
Adds the given operation to a newSequence
with the statements of this object as a prefix, repeating the operation the given number of times. Used during generation.- Parameters:
seq
- the sequence to extendoperation
- theTypedOperation
to repeattimes
- the number of times to repeat theOperation
- Returns:
- a new
Sequence
-
randoopConsistencyTest2
private void randoopConsistencyTest2(Sequence newSequence)
-
randoopConsistencyTests
private void randoopConsistencyTests(Sequence newSequence)
-
selectInputs
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.
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.
- Parameters:
operation
- the statement to analyze- Returns:
- the selected sequences and indices
-
randomVariable
ForwardGenerator.VarAndSeq randomVariable(SimpleList<Sequence> candidates, Type inputType, boolean isReceiver)
Return a variable of the given type.- Parameters:
candidates
- sequences, each of which produces a value of typeinputType
; that is, each would be a legal return valueinputType
- the type of the chosen variable/sequenceisReceiver
- whether the value will be used as a receiver- Returns:
- a random variable of the given type, chosen from the candidates
-
numGeneratedSequences
public int numGeneratedSequences()
Description copied from class:AbstractGenerator
Returns the count of sequences generated so far by the generator.- Specified by:
numGeneratedSequences
in classAbstractGenerator
- Returns:
- the number of sequences generated
-
-