Class AbstractGenerator

java.lang.Object
randoop.generation.AbstractGenerator
Direct Known Subclasses:
ForwardGenerator

public abstract class AbstractGenerator extends Object
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 Details

    • dump_sequences

      public static boolean dump_sequences
      If true, dump each sequence to the log file as it is generated. Has no effect unless logging is enabled.
    • num_steps

      public int num_steps
      Number of generation steps (each an attempt to generate and execute a new, distinct sequence).
    • null_steps

      public int null_steps
      Number of steps that returned null.
    • num_sequences_generated

      public int num_sequences_generated
      Number of sequences generated.
    • num_failing_sequences

      public int num_failing_sequences
      Number of failing sequences generated.
    • invalidSequenceCount

      public int invalidSequenceCount
      Number of invalid sequences generated.
    • num_failed_output_test

      public int num_failed_output_test
      Number of sequences that failed the output test.
    • startTime

      private long startTime
      When the generator started (millisecond-based system timestamp).
    • subsumed_sequences

      protected Set<Sequence> subsumed_sequences
      Sequences that are used in other sequences (and are thus redundant)
    • limits

      public final GenInputsAbstract.Limits limits
      Limits for generation, after which the generator will stop.
    • operations

      protected final List<TypedOperation> 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

      protected ExecutionVisitor executionVisitor
      Container for execution visitors used during execution of sequences.
    • componentManager

      public ComponentManager componentManager
      Component manager responsible for storing previously-generated sequences.
    • stopper

      private IStopper stopper
      Customizable stopping criterion in addition to time and sequence limits.
    • listenerMgr

      public RandoopListenerManager listenerMgr
      Manages notifications for listeners.
      See Also:
    • progressDisplay

      private ProgressDisplay progressDisplay
      Updates the progress display message printed to the console. Null if GenInputsAbstrect.progressdisplay is false.
    • currSeq

      public static Sequence 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

      public List<ExecutableSequence> outErrorSeqs
      The list of error test sequences to be output as JUnit tests. May include subsequences of other sequences in the list.
    • outRegressionSeqs

      public List<ExecutableSequence> outRegressionSeqs
      The list of regression sequences to be output as JUnit tests. May include subsequences of other sequences in the list.
    • outputTest

      public Predicate<ExecutableSequence> 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

      protected TestCheckGenerator checkGenerator
      Visitor to generate checks for a sequence.
    • operationHistory

      protected OperationHistoryLogInterface 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/output
      componentManager - 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 as new 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

      public void setTestPredicate(Predicate<ExecutableSequence> outputTest)
      Registers test predicate with this generator for use while filtering generated tests for output.
      Parameters:
      outputTest - the predicate to be added to object
    • setExecutionVisitor

      public void setExecutionVisitor(ExecutionVisitor executionVisitor)
      Registers a visitor with this object for use while executing each generated sequence.
      Parameters:
      executionVisitor - the visitor
    • setExecutionVisitor

      public void setExecutionVisitor(List<ExecutionVisitor> visitors)
      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

      public void setTestCheckGenerator(TestCheckGenerator checkGenerator)
      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

      public abstract @Nullable ExecutableSequence 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

      public abstract LinkedHashSet<Sequence> getAllSequences()
      Return all sequences generated by this object.
      Returns:
      all generated sequences
    • getRegressionSequences

      public List<ExecutableSequence> 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

      public List<ExecutableSequence> 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

      void setCurrentSequence(Sequence s)
      Sets the current sequence during exploration.
      Parameters:
      s - the current sequence
    • setOperationHistoryLogger

      public void setOperationHistoryLogger(OperationHistoryLogInterface logger)
      Sets the operation history logger for this generator.
      Parameters:
      logger - the operation history logger to use for this generator
    • getOperationHistory

      public OperationHistoryLogInterface getOperationHistory()
      Return the operation history logger for this generator.
      Returns:
      the operation history logger for this generator
    • newRegressionTestHook

      public abstract void newRegressionTestHook(Sequence sequence)
      Take action based on the given Sequence 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