2. INTRODUCTION
As designs grow larger, it becomes more difficult to
create a complete set of stimuli
needed to check their functionality.
Directed test cases can be written to check a certain
set of features,
The number of features keeps doubling on each
project.
3. The solution is to create test cases Automa- tically
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.
Trade-off of test-authoring time (your work) for CPU
time (machine work) is what makes CRT so valuable.
4. A simple directed test just applies stimulus, and then
manually check the result.
These results are captured as a golden log file and
compared with future simulations to see whether the
test passes or fails.
A CRT environment needs not only to create
the stimulus but also to predict the result.
5. 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).
Just by changing seeds, each test can be made the
functional equivalent of many directed tests
6. What can be Randomized?
Integral variables, that is, variables that contain a
simple set of bits.
Randomization only works with 2-state values. Can
have integers, bit vectors, etc.
Can’thave a random string, or refer to a handle in a
constraint.1
7. Call $random.
Only find data-path
bugs, perhaps with bit-
level mistakes.
The test is still
inherently directed.
The challenging bugs -
control logic.
As a result, you need to
randomize all decision
points in your DUT.
Wherever control paths
diverge, randomization
increases the probability
that you’ll take a
different path in each
test case
8. DESIGN INPUTS
Device configuration
Environment
configuration
Primary input data
Encapsulated input data
Protocol exceptions
Delays
Transaction status
Errors and violations
Protocol exceptions
9. RANDOM STIMULUS GENERATION
Most useful when used with OOPs.
First create a class to hold a group of related random
variables.
Then have the random-solver fill them with random
values
. You can create constraints to limit the random values
to legal values, or to test-specific features.
10. SIMPLE RANDOM CLASS
class Packet;
// The random variables
rand bit [31:0] src, dst,
data[8];
randc bit [7:0] kind;
// Limit the values for src
constraint c {src > 10;
src < 15;}
endclass
Packet p;
initial begin
p = new();// Create a
packet
assert (p.randomize())
else $fatal(0,
"Packet::randomize
failed");
transmit(p);
end
11. Randc - means random cyclic,
The random solver does not repeat a random value until
every possible value has been assigned
A randc array with eight elements has eight different
patterns
12. Grouped using curly braces: {}.
code is declarative, not procedural.
A constraint is just a set of relational expressions
that must be true for the chosen
value of the variables.
The randomize() function returns 0 if a problem is
found with the constraints.
13. Checking the Result
The randomize() function assigns random values to any
variable in the class that has been labeled as rand or randc
Also makes sure that all active constraints are obeyed.
May fail due to conflicting constraints.
One should always check the status, else, the variables
may get unexpected values, causing your simulation to
fail.
14. checks the status from randomize() by using a procedural
assertion.
If randomization succeeds, the function returns 1.
If it fails, randomize() returns 0.
$fatal stops the simulation.
.
15. The assertion checks the result and prints an error if
there was a failure. The simulator’s switches should
be set to terminate when an error is found.
The assertion checks the result and prints an error if
there was a failure.
Alternatively, call a special routine to end simulation.
16. Constraint without random
variables
class Child;
bit [31:0] age; // Error Ð
should be rand or randc
constraint c_teenager {age
> 12;
age < 20;}
Endclass
Here since there are no
random variables,
randomize() just checks
the value of child to see
if it is in the bounds
specified by the
constraint c_teenager.
17. Constrained-random class
class Stim;
const bit [31:0]
CONGEST_ADDR = 42;
typedef enum {READ,
WRITE, CONTROL}
stim_e;
randc stim_e kind; //
Enumerated var
rand bit [31:0] len, src, dst;
bit congestion_test;
constraint c_stim {
len < 1000;
len > 0;
if (congestion_test) {
dst inside
{[CONGEST_ADDR-
100:CONGEST_ADDR+1
00]};
src == CONGEST_ADDR;
}
else
src inside {0, [2:10],
[100:107]};
}
endclass
6.4.2 Simple Expressions