randoop
Class ExecutableSequence

Object
  extended by ExecutableSequence
All Implemented Interfaces:
Serializable

public class ExecutableSequence
extends Object
implements Serializable

An ExecutableSequence wraps a Sequence with functionality for executing the sequence. It also lets the client add Checks to that check expected behaviors of the execution.

An ExecutableSequence augments a sequence with three additional pieces of data:

Of the three pieces of data above, an ExecutableSequence only directly manages the first one, i.e. the execution results. Other pieces of data, including checks and check evaluation results, are added or removed by the client of the ExecutableSequence. One way of doing this is by implementing an ExecutionVisitor and passing it as an argument to the execute method.

The ethod execute(ExecutionVisitor v) executes the code that the sequence represents. This method uses reflection to execute each element in the sequence (method call, constructor call, primitive or array declaration, etc). Before executing each statement (e.g. the i-th statement), execute(v) calls v.visitBefore(this, i), and after executing each statement, it calls v.visitAfter(this, i). The purpose of the visitor is to examine the unfolding execution, and take some action depending on its intended purpose. For example, it may decorate the sequence with Checks about the execution. NOTES.

See Also:
Serialized Form

Field Summary
Modifier and Type Field and Description
protected  List<List<Check>> checks
           
protected  List<List<Boolean>> checksResults
           
 long exectime
           
protected  Execution executionResults
           
 long gentime
           
 Sequence sequence
           
 
Constructor Summary
Constructor and Description
ExecutableSequence(Sequence sequence)
          Create an executable sequence that executes the given sequence.
ExecutableSequence(Sequence sequence, Execution exec, List<List<Check>> checks)
          Create an executable sequence directly using the given arguments.
 
Method Summary
Modifier and Type Method and Description
 void addCheck(int i, Check check, boolean passed)
          Adds the given check to the i-th element of the sequence.
static int checks_count(List<ExecutableSequence> seqs)
          Return the total number of checks in a list of sequences
 int compare_checks(ExecutableSequence es, boolean remove_diffs, boolean print_diffs)
          Compares the results of the checks of two sequences (the code in each sequence should be the same).
 ExecutableSequence duplicate()
           
 boolean equals(Object obj)
           
 int exceptionIndex()
          Returns the index i for which this.isExceptionalExecution(i), or -1 if there is no such index.
 void execute(ExecutionVisitor visitor)
          Executes sequence, stopping on exceptions
 void execute(ExecutionVisitor visitor, boolean stop_on_exception)
          Execute this sequence, invoking the given visitor as the execution unfolds.
 int executedSize()
           
static void executeStatement(Sequence s, List<ExecutionOutcome> outcome, int index, Object[] inputVariables)
           
 ExecutionOutcome[] getAllResults()
           
 List<Check> getChecks(int i)
          Get the checks for the i-th element of the sequence.
 List<Check> getChecks(int i, Class<? extends Check> clazz)
           
 List<List<Boolean>> getChecksResults()
           
 int getContractCheckIndex(Class<? extends Check> clazz)
           
 int getExceptionIndex(Class<?> exceptionClass)
           
 int getFailureIndex()
           
 List<Check> getFailures(int idx)
           
 ExecutionOutcome getResult(int index)
          This method is typically used by ExecutionVisitors.
static boolean getRuntimeInputs(Sequence s, List<ExecutionOutcome> outcome, int i, List<Variable> inputs, Object[] runtimeObjects)
           
protected static Object[] getRuntimeValuesForVars(List<Variable> vars, List<ExecutionOutcome> execution)
           
static
<D extends Check>
List<Sequence>
getSequences(List<ExecutableSequence> exec)
           
 boolean hasCheck(Class<? extends Check> clazz)
           
 boolean hasCheck(int i, Class<? extends Check> clazz)
          True iff this sequences has at least one check of the given type at index i.
 boolean hasChecks(int i)
           
 boolean hasFailure()
           
 boolean hasFailure(int i)
           
 int hashCode()
           
 boolean hasNonExecutedStatements()
           
 boolean isNormalExecution()
           
 boolean isNormalExecution(int i)
          This method is typically used by ExecutionVisitors.
 void removeChecks()
           
 int seq_id()
          Returns an id based on the contents of the sequence alone.
 boolean throwsException()
           
 boolean throwsException(Class<?> exceptionClass)
           
 String toCodeString()
          Output this sequence as code.
 String toString()
           
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

sequence

public Sequence sequence

checks

protected List<List<Check>> checks

checksResults

protected List<List<Boolean>> checksResults

executionResults

protected transient Execution executionResults

gentime

public long gentime

exectime

public long exectime
Constructor Detail

ExecutableSequence

public ExecutableSequence(Sequence sequence)
Create an executable sequence that executes the given sequence.


ExecutableSequence

public ExecutableSequence(Sequence sequence,
                          Execution exec,
                          List<List<Check>> checks)
Create an executable sequence directly using the given arguments. Don't use this constructor! (Unless you know what you're doing.)

Method Detail

getChecks

public List<Check> getChecks(int i)
Get the checks for the i-th element of the sequence.


addCheck

public void addCheck(int i,
                     Check check,
                     boolean passed)
Adds the given check to the i-th element of the sequence. Only one check of class StatementThrowsException is allowed for each index, and attempting to add a second check of this type will result in an IllegalArgumentException.

Throws:
IllegalArgumentException - If the given check's class is StatementThrowsException and there is already an check of this class at the give index.

toString

public String toString()
Overrides:
toString in class Object

seq_id

public int seq_id()
Returns an id based on the contents of the sequence alone. The id will match for any identical sequences (no matter how they are constructed). Used for debugging


toCodeString

public String toCodeString()
Output this sequence as code. In addition to printing out the statements, this method prints the checks. If for a given statement there is an check of type StatementThrowsException, that check's pre-statement code is printed immediately before the statement, and its post-statement code is printed immediately after the statement.


execute

public void execute(ExecutionVisitor visitor)
Executes sequence, stopping on exceptions


execute

public void execute(ExecutionVisitor visitor,
                    boolean stop_on_exception)
Execute this sequence, invoking the given visitor as the execution unfolds. After invoking this method, the client can query the outcome of executing each statement via the method getResult(i).

Parameters:
visitor - can be null, in which case no visitor will be invoked during execution.

getRuntimeInputs

public static boolean getRuntimeInputs(Sequence s,
                                       List<ExecutionOutcome> outcome,
                                       int i,
                                       List<Variable> inputs,
                                       Object[] runtimeObjects)

getRuntimeValuesForVars

protected static Object[] getRuntimeValuesForVars(List<Variable> vars,
                                                  List<ExecutionOutcome> execution)

executeStatement

public static void executeStatement(Sequence s,
                                    List<ExecutionOutcome> outcome,
                                    int index,
                                    Object[] inputVariables)

getResult

public ExecutionOutcome getResult(int index)
This method is typically used by ExecutionVisitors. The result of executing the i-th element of the sequence.


getChecksResults

public List<List<Boolean>> getChecksResults()

getAllResults

public ExecutionOutcome[] getAllResults()
Returns:
all the execution outcomes for this sequence.

executedSize

public int executedSize()
Returns:
the number of elements in the sequence that were executed before an execution result of type randoop.NotExecuted.

isNormalExecution

public boolean isNormalExecution(int i)
This method is typically used by ExecutionVisitors. True if execution of the i-th statement terminated normally.


isNormalExecution

public boolean isNormalExecution()

getChecks

public List<Check> getChecks(int i,
                             Class<? extends Check> clazz)

removeChecks

public void removeChecks()

hasCheck

public boolean hasCheck(Class<? extends Check> clazz)

getContractCheckIndex

public int getContractCheckIndex(Class<? extends Check> clazz)
Returns:
the first index at which an check of the given type occurs, or -1 if there is no check of the given type in this sequence.

hasCheck

public boolean hasCheck(int i,
                        Class<? extends Check> clazz)
True iff this sequences has at least one check of the given type at index i.


hasChecks

public boolean hasChecks(int i)

hasFailure

public boolean hasFailure(int i)

hasFailure

public boolean hasFailure()

getFailures

public List<Check> getFailures(int idx)

getFailureIndex

public int getFailureIndex()

getExceptionIndex

public int getExceptionIndex(Class<?> exceptionClass)
Returns:
The index in the sequence at which an exception of the given class (or a class compatible with it) was thrown. If no such exception, returns -1.

throwsException

public boolean throwsException(Class<?> exceptionClass)
Returns:
True if an exception of the given class (or a class compatible with it) has been thrown during this sequence's execution.

throwsException

public boolean throwsException()
Returns:
True if an exception has been thrown during this sequence's execution.

hasNonExecutedStatements

public boolean hasNonExecutedStatements()

duplicate

public ExecutableSequence duplicate()

exceptionIndex

public int exceptionIndex()
Returns the index i for which this.isExceptionalExecution(i), or -1 if there is no such index.


getSequences

public static <D extends Check> List<Sequence> getSequences(List<ExecutableSequence> exec)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

compare_checks

public int compare_checks(ExecutableSequence es,
                          boolean remove_diffs,
                          boolean print_diffs)
Compares the results of the checks of two sequences (the code in each sequence should be the same). Returns the number of different checks. If remove_diffs is true any differing checks are removed from both sequences. Checks found in one sequence but not the other are also removed. Prints any differences to stdout if print_diffs is true. Different checks can be generated for two runs of the same test sequence because of changes in the environment (eg, static variables) between runs. Some checks are only created when the value involved in the check meets certain criteria and since the values can change, the checks may not always be created. Its also possible to throw exceptions in one run and not another. The get_id() method from the Check interface) is used to identify check uniquely. The id contains both the observer type (primitive, non-null, observer method call, etc) and the related variables. When comparing two lists of Checks, the code presumes that the checks will occur in the same order on each execution. Thus if the first remaining check in the first execution matches the second check from the second execution, the first check from the second execution is presumed to not match. The algorithm is far from completely optimized, but it should work pretty well if the two lists are pretty much the same (which they usually are).


checks_count

public static int checks_count(List<ExecutableSequence> seqs)
Return the total number of checks in a list of sequences