Randomization 1
Randomization 1
Introduction
• As designs grow larger, it becomes more difficult to create
a complete set of stimuli needed to check their
functionality.
• we can write a directed testcase to check a certain set of
features, but you cannot write enough directed testcases
when the number of features keeps doubling on each
project.
• The solution is to create testcases automatically using
constrained-random tests (CRT). A directed test finds the
bugs you think are there, but a CRT finds bugs you never
thought about, by using random stimulus.
• we restrict the test scenarios to those that are both valid
and of interest by using constraints.
Introduction
Introduction
• A CRT is made of two parts:
• The test code that uses a stream of random values to
create input to the DUT.
• A seed to the pseudo-random number generator
(PRNG), we can make a CRT behave differently just
by using a new seed.
• This feature allows you to leverage each test so each
is the functional equivalent of many directed tests, just
by changing seeds. You are able to create more
equivalent tests using these techniques than with
directed testing
What to Randomize
class BusOp;
... constraint c_len_rw {
if (op == READ)
len inside {[BYTE:LWRD]};
else
len == LWRD; }
Constraint block with implication operator
Equivalence operator
Solution Probabilities
Here are the possible solutions and probability. we can see that the random
solver recognizes that there are eight combinations of x and y, but all the
solutions where x==0 (A–D) have been merged together.
Implication and bidirectional constraints
• Note that the implication operator says that when x==0, y is
forced to 0, but when y==0, there is no constraint on x.
• However, implication is bidirectional in that if y were forced to
a nonzero value, x would have to be 1.
• Example has the constraint y>0, so x can never be 0.
class Imp2;
rand bit x; // 0 or 1
rand bit [1:0] y; // 0, 1, 2, or 3
constraint c_xy {
y > 0;
(x==0) -> y==0; }
endclass
Solution for imp2 Example
Guiding Distribution with solve/before
Controlling Multiple Constraint Blocks
• A class can contain multiple constraint blocks. Your class
might naturally divide into two sets of variables, such as
data vs. control.
• They can interact with each other in unexpected ways, and the
extra code to enable and disable them adds to the test complexity.
Using the inside constraint lets you set a lower and upper
boundary on the array size. In many cases you may not want
an empty array, that is, size==0.
Randomizing an array of handles
Atomic Stimulus Generation vs. Scenario
Generation
An Atomic generator with History
Usage of atomic generator w/ history
Randsequence
• The next way to generate a sequence of transactions is by
using the randsequence construct in SystemVerilog. With
randsequence you describe the grammar of the transaction,
using a syntax similar to BNF (Backus-Naur Form).
Verilog has a single PRNG that is used for the entire simulation.
In SystemVerilog Testbenches often have several stimulus generators
running in parallel.
creating data for the design under test. If two streams share the same
PRNG, they each get a subset of the random values.
There are two stimulus generators and a single PRNG producing
values a, b, c, etc. Gen2 has two random objects, so during every cycle,
it uses twice as many random values as Gen1
Random Stability — multiple generators
An important part of your DUT to test is the configuration of both the
internal DUT settings and the system that surrounds it.
The eth_cfg class describes the configuration for a 4-port Ethernet
switch. It is instantiated in an environment class, which in turn is used
in the test.
The test overrides one of the configuration values, enabling all 4 ports.
Random Device Configuration
Random Device Configuration