[Team Specman welcomes guest blogger Vitaly Lagoon, an Architect in the Generation Technology R&D group]
Consider the case where you have a generatable variable "x" taking random values from [0..99], i.e. all values are declared equal from the generation point of view. However, imagine that from a verification perspective you are most interested in checking the extreme cases x==0 and x==99, as well as a few random values in between 0 and 99 for safety's sake.
One approach would be to capture this in a coverage definition by defining three buckets [1..98]. However, running this code would actually give you really bad coverage of the extreme ends of the range because the generator would hit the middle bucket 98 times out of 100.
Fortunately, there is an easy and effective alternative. First, define a generatable variable – let’s call it 'range_x' in this example:
then constrain it using:
(range_x==min) == (x==0);
keep (range_x==max) == (x==99);
// The third case is implied so, you don't
need the constraint
Now, running with coverage on 'range_x' you will see things converge a lot faster -- in only five generation cycles we would have an 87% chance of filling all three ‘range_x’ buckets. And in 10 cycles, the chance of filling all three buckets is 98%! Clearly, making 'range_x' generatable has the effect of uniformly directing the solver towards one of the areas of interest.
Of course this example can be extended and specialized by using 'select' on 'range_x', e.g. you can easily put more weight on some buckets.
The general point: when taking coverage on generatable parameters it makes sense move the bucket (and also cross) definition out of coverage specification and into constraints. The buckets defined in coverage only help to observe things, whereas the equivalent definition in constraints actually targets the generator towards the interesting stuff.
One final note: this example / capability is only available with IntelliGen. With the legacy PGEN generator, the ordering of the fields would affect the order of generation. Thus, if you did not define "range_x" before "x" (or use a specific gen(range_x) before (x) statement) then you would not see a uniform generation on "range_x".
Generation Technology R&D