Package randoop.generation
Class Bloodhound
- java.lang.Object
-
- randoop.generation.Bloodhound
-
- All Implemented Interfaces:
TypedOperationSelector
public class Bloodhound extends Object implements TypedOperationSelector
Implements the Bloodhound 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 .Bloodhound computes a weight for each method under test by taking a weighted combination of
- the uncovered branch ratio and
- the ratio between the number of times the method has been successfully invoked (to be the last statement of a new regression test) and the maximum number of times any method under test has been successfully invoked.
-
-
Field Summary
Fields Modifier and Type Field 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 Map<TypedOperation,Integer>
methodInvocationCounts
Map from methods under test to the total number of times they have ever been successfully invoked by theAbstractGenerator
.private Map<TypedOperation,Integer>
methodSelectionCounts
Map from methods under test to the number of times they have been recently selected by theForwardGenerator
to construct a new sequence.private Map<TypedOperation,Double>
methodWeights
Map from methods under test to their weights.private SimpleArrayList<TypedOperation>
operationSimpleList
List of operations, identical toForwardGenerator
'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 Summary
Constructors Constructor Description Bloodhound(List<TypedOperation> operations, Set<ClassOrInterfaceType> classesUnderTest)
Initialize Bloodhound.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 theForwardGenerator
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 inmethodWeights
map for all methods under test.
-
-
-
Field Detail
-
coverageTracker
private final CoverageTracker coverageTracker
Coverage tracker used to get branch coverage information of methods under test.
-
methodWeights
private final Map<TypedOperation,Double> methodWeights
Map from methods under test to their weights. These weights are dynamic and depend on branch coverage.
-
methodSelectionCounts
private final Map<TypedOperation,Integer> methodSelectionCounts
Map from methods under test to the number of times they have been recently selected by theForwardGenerator
to construct a new sequence. This map is cleared every time branch coverage is recomputed.
-
methodInvocationCounts
private final Map<TypedOperation,Integer> methodInvocationCounts
Map from methods under test to the total number of times they have ever been successfully invoked by theAbstractGenerator
. The integer value for a given method is non-decreasing during a run of Randoop.
-
operationSimpleList
private final SimpleArrayList<TypedOperation> operationSimpleList
List of operations, identical toForwardGenerator
's operation list. Used for making random, weighted selections for a method under test.
-
alpha
private static final double alpha
Parameter for balancing branch coverage and number of times a method was chosen. The name "alpha" and the specified value are both from the GRT paper.- See Also:
- Constant Field Values
-
p
private static final double p
Parameter for decreasing weights of methods between updates to coverage information. The name "p" and the specified value are both from the GRT paper.- See Also:
- Constant Field Values
-
t
private static final long t
Time interval, in milliseconds, at which to recompute weights. The name "t" and the specified value are both from the GRT paper.- See Also:
- Constant Field Values
-
lastUpdateTime
private long lastUpdateTime
System.currentTimeMillis()
when branch coverage was last updated.
-
branchCoverageInterval
private static final int branchCoverageInterval
Branch coverage is recomputed after this many successful invocations (= this many new tests were generated).- See Also:
- Constant Field Values
-
totalSuccessfulInvocations
private int totalSuccessfulInvocations
The total number of successful invocations of all the methods under test.
-
maxSuccM
private int maxSuccM
Maximum number of times any method under test has been successfully invoked. This value is initialized to 1 because it is used as the denominator of a division in computing a method's weight. The name is from the GRT paper, which calls this quantity "maxSucc(M)".
-
totalWeightOfMethodsUnderTest
private double totalWeightOfMethodsUnderTest
The total weight of all the methods that are under test. This is used byRandomness
to randomly select an element from a list of weighted elements.
-
-
Constructor Detail
-
Bloodhound
public Bloodhound(List<TypedOperation> operations, Set<ClassOrInterfaceType> classesUnderTest)
Initialize Bloodhound. Branch coverage information is initialized and all methods under test are assigned a weight based on the weighting scheme defined by GRT's description of Bloodhound.- Parameters:
operations
- list of operations under testclassesUnderTest
- set of classes under test
-
-
Method Detail
-
selectOperation
public TypedOperation selectOperation()
Selects a method under test for theForwardGenerator
to use to construct a new sequence. A method under test is randomly selected with a weighted probability.- Specified by:
selectOperation
in interfaceTypedOperationSelector
- Returns:
- the chosen
TypedOperation
for the new sequence
-
updateBranchCoverageMaybe
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.There are two choices for when to update branch coverage information:
- Time: branch coverage is updated when more than
t
milliseconds have elapsed since branch coverage was last updated. This is GRT's approach and is the default. It makes Randoop non-deterministic. - Count of successful invocations: branch coverage is updated after every
branchCoverageInteral
successful invocations (of any method under test).
- Time: branch coverage is updated when more than
-
logMethodWeights
private void logMethodWeights()
For debugging, print all method weights to standard output.
-
updateWeightsForAllOperations
private void updateWeightsForAllOperations()
Computes and updates weights inmethodWeights
map for all methods under test. Recomputes thetotalWeightOfMethodsUnderTest
to avoid problems with round-off error.
-
updateWeight
private double updateWeight(TypedOperation operation)
Recompute weight for a method under test. A method under test is assigned a weight based on a weighted combination of- the number of branches uncovered and
- the ratio between the number of times this method has been recently selected and the maximum number of times any method under test has been successfully invoked.
- Parameters:
operation
- method to compute weight for- Returns:
- the updated weight for the given operation
-
incrementSuccessfulInvocationCount
public void incrementSuccessfulInvocationCount(TypedOperation operation)
Increments the number of times a method under test was successfully invoked.- Parameters:
operation
- the method under test that was successfully invoked
-
newRegressionTestHook
public 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.- Specified by:
newRegressionTestHook
in interfaceTypedOperationSelector
- Parameters:
sequence
- newly-created sequence that was classified as a regression test
-
-