public class Bloodhound extends java.lang.Object implements TypedOperationSelector
Bloodhound computes a weight for each method under test by taking a weighted combination of
Modifier and Type | Field and Description |
---|---|
private static double |
alpha
Parameter for balancing branch coverage and number of times a method was chosen.
|
private static int |
branchCoverageInterval
Branch coverage is recomputed after this many successful invocations (= this many new tests
were generated).
|
private CoverageTracker |
coverageTracker
Coverage tracker used to get branch coverage information of methods under test.
|
private long |
lastUpdateTime
System.currentTimeMillis() when branch coverage was last updated. |
private int |
maxSuccM
Maximum number of times any method under test has been successfully invoked.
|
private java.util.Map<TypedOperation,java.lang.Integer> |
methodInvocationCounts
Map from methods under test to the total number of times they have ever been successfully
invoked by the
AbstractGenerator . |
private java.util.Map<TypedOperation,java.lang.Integer> |
methodSelectionCounts
Map from methods under test to the number of times they have been recently selected by the
ForwardGenerator to construct a new sequence. |
private java.util.Map<TypedOperation,java.lang.Double> |
methodWeights
Map from methods under test to their weights.
|
private SimpleArrayList<TypedOperation> |
operationSimpleList
List of operations, identical to
ForwardGenerator 's operation list. |
private static double |
p
Parameter for decreasing weights of methods between updates to coverage information.
|
private static long |
t
Time interval, in milliseconds, at which to recompute weights.
|
private int |
totalSuccessfulInvocations
The total number of successful invocations of all the methods under test.
|
private double |
totalWeightOfMethodsUnderTest
The total weight of all the methods that are under test.
|
Constructor and Description |
---|
Bloodhound(java.util.List<TypedOperation> operations,
java.util.Set<ClassOrInterfaceType> classesUnderTest)
Initialize Bloodhound.
|
Modifier and Type | Method and Description |
---|---|
void |
incrementSuccessfulInvocationCount(TypedOperation operation)
Increments the number of times a method under test was successfully invoked.
|
private void |
logMethodWeights()
For debugging, print all method weights to standard output.
|
void |
newRegressionTestHook(Sequence sequence)
Increment the number of successful invocations of the last method in the newly-created sequence
that was classified as a regression test.
|
TypedOperation |
selectOperation()
Selects a method under test for the
ForwardGenerator to use to construct a new
sequence. |
private void |
updateBranchCoverageMaybe()
When an interval is reached, the branch coverage information for all methods under test is
updated and the weight for every method under test is recomputed.
|
private double |
updateWeight(TypedOperation operation)
Recompute weight for a method under test.
|
private void |
updateWeightsForAllOperations()
Computes and updates weights in
methodWeights map for all methods under test. |
private final CoverageTracker coverageTracker
private final java.util.Map<TypedOperation,java.lang.Double> methodWeights
private final java.util.Map<TypedOperation,java.lang.Integer> methodSelectionCounts
ForwardGenerator
to construct a new sequence. This map is cleared every time branch
coverage is recomputed.private final java.util.Map<TypedOperation,java.lang.Integer> methodInvocationCounts
AbstractGenerator
. The integer value for a given method is
non-decreasing during a run of Randoop.private final SimpleArrayList<TypedOperation> operationSimpleList
ForwardGenerator
's operation list. Used for making
random, weighted selections for a method under test.private static final double alpha
private static final double p
private static final long t
private long lastUpdateTime
System.currentTimeMillis()
when branch coverage was last updated.private static final int branchCoverageInterval
private int totalSuccessfulInvocations
private int maxSuccM
private double totalWeightOfMethodsUnderTest
Randomness
to
randomly select an element from a list of weighted elements.public Bloodhound(java.util.List<TypedOperation> operations, java.util.Set<ClassOrInterfaceType> classesUnderTest)
operations
- list of operations under testclassesUnderTest
- set of classes under testpublic TypedOperation selectOperation()
ForwardGenerator
to use to construct a new
sequence. A method under test is randomly selected with a weighted probability.selectOperation
in interface TypedOperationSelector
TypedOperation
for the new sequenceprivate void updateBranchCoverageMaybe()
There are two choices for when to update branch coverage information:
t
milliseconds have elapsed since
branch coverage was last updated. This is GRT's approach and is the default. It makes
Randoop non-deterministic.
branchCoverageInteral
successful invocations (of any method under test).
private void logMethodWeights()
private void updateWeightsForAllOperations()
methodWeights
map for all methods under test.
Recomputes the totalWeightOfMethodsUnderTest
to avoid problems with round-off error.private double updateWeight(TypedOperation operation)
operation
- method to compute weight forpublic void incrementSuccessfulInvocationCount(TypedOperation operation)
operation
- the method under test that was successfully invokedpublic void newRegressionTestHook(Sequence sequence)
newRegressionTestHook
in interface TypedOperationSelector
sequence
- newly-created sequence that was classified as a regression test