Class OrienteeringSelection
- java.lang.Object
-
- randoop.generation.InputSequenceSelector
-
- randoop.generation.OrienteeringSelection
-
public class OrienteeringSelection extends InputSequenceSelector
Implements the Orienteering component, as described by the paper "GRT: Program-Analysis-Guided Random Testing" by Ma et. al (appears in ASE 2015): https://people.kth.se/~artho/papers/lei-ase2015.pdf .Biases input selection towards sequences that have lower execution cost. Execution cost is measured by the number of method calls in a sequence and the time it takes to execute.
Our implementation of Orienteering differs from that described in the GRT paper in that we do not measure the time of every execution of a sequence. Instead, we assume that a sequence's execution time is equal to the execution time of its first run. We believe this assumption is reasonable since a sequence does not take any inputs (it is self-contained), so its execution time probably does not differ greatly between separate runs.
The GRT paper also does not describe how to handle input sequences that have an execution time of zero, such as one that only includes the assignment of a primitive type
byte byte0 = (byte)1;
. We assign these input sequences an execution time of 1 nanosecond to prevent division by zero when computing weights.The GRT paper also does not describe how to handle input sequences that have not yet been selected. We start ecah input sequences with a selection count of 1 to prevent division by zero when computing weights.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
OrienteeringSelection.SequenceDetails
Information used by Orienteering to compute a weight for a sequence.
-
Field Summary
Fields Modifier and Type Field Description private Map<Sequence,OrienteeringSelection.SequenceDetails>
sequenceDetailsMap
Map from a sequence to its details used for computing its weight.private Map<Sequence,Double>
weightMap
Map from a sequence to its weight.
-
Constructor Summary
Constructors Constructor Description OrienteeringSelection(Set<Sequence> seedSequences)
InitializeOrienteeringSelection
and assign a weight to eachSequence
within the given set of seed sequences.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private double
computeTotalWeightForCandidates(SimpleList<Sequence> candidates)
Compute the total weight of the list of candidateSequence
s.void
createdExecutableSequence(ExecutableSequence eSeq)
A hook that is called after a new sequence has been created and executed.private void
createSequenceDetailsWithExecutionTime(Sequence sequence, long executionTimeNanos)
Creates and stores aOrienteeringSelection.SequenceDetails
for the givenSequence
with the corresponding execution time.private static double
methodSizeSquareRoot(Sequence sequence)
Returns the the square root of the number of method call statements within the given sequence.Sequence
selectInputSequence(SimpleList<Sequence> candidates)
Bias input selection towards lower-cost sequences.
-
-
-
Field Detail
-
sequenceDetailsMap
private final Map<Sequence,OrienteeringSelection.SequenceDetails> sequenceDetailsMap
Map from a sequence to its details used for computing its weight.
-
-
Constructor Detail
-
OrienteeringSelection
public OrienteeringSelection(Set<Sequence> seedSequences)
InitializeOrienteeringSelection
and assign a weight to eachSequence
within the given set of seed sequences. This ensures that later, Orienteering will always have a correspondingOrienteeringSelection.SequenceDetails
and therefore a corresponding weight for everySequence
within a list of candidates for selection.- Parameters:
seedSequences
- set of seed sequences
-
-
Method Detail
-
selectInputSequence
public Sequence selectInputSequence(SimpleList<Sequence> candidates)
Bias input selection towards lower-cost sequences.- Specified by:
selectInputSequence
in classInputSequenceSelector
- Parameters:
candidates
- sequences to choose from- Returns:
- the chosen sequence
-
computeTotalWeightForCandidates
private double computeTotalWeightForCandidates(SimpleList<Sequence> candidates)
Compute the total weight of the list of candidateSequence
s.- Parameters:
candidates
- list of candidate sequences- Returns:
- the total weight of the input candidate list
-
createdExecutableSequence
public void createdExecutableSequence(ExecutableSequence eSeq)
A hook that is called after a new sequence has been created and executed.The default implementation does nothing. Subclasses may override it to add behavior.
This implementation creates and stores a
OrienteeringSelection.SequenceDetails
for the underlyingSequence
in the givenExecutableSequence
.- Overrides:
createdExecutableSequence
in classInputSequenceSelector
- Parameters:
eSeq
- the recently executed sequence which is new and unique, and has just been executed. It contains its overall execution time for the underlyingSequence
.
-
createSequenceDetailsWithExecutionTime
private void createSequenceDetailsWithExecutionTime(Sequence sequence, long executionTimeNanos)
Creates and stores aOrienteeringSelection.SequenceDetails
for the givenSequence
with the corresponding execution time.- Parameters:
sequence
- the sequence to addexecutionTimeNanos
- the execution time of the sequence, in nanoseconds
-
methodSizeSquareRoot
private static double methodSizeSquareRoot(Sequence sequence)
Returns the the square root of the number of method call statements within the given sequence.To prevent division by zero, we use 1 for a sequence with no method calls.
- Parameters:
sequence
- a sequence- Returns:
- square root of the number of method calls in the given sequence
-
-