Professional Documents
Culture Documents
Lecture 12
Assertions
2/5/2013
Assertions
What is an assertion?
In Simple English, it is just a statement or a declaration.
A bowler, says Howzzzaaat? When he bowls an inswinger that hits the batsmans pad. The Howzzzaat is
an assertion. When, the umpire raises his finger, the
assertion is Validated, based on a property.
That property is that If a batsman blocks a ball that was
heading to the wicket with his Legs, then he is OUT.
Properties can be quite complicated in Cricket, There are
multiple ways a batsman can be out! What are some
other simple properties?
2/5/2013
SystemVerilog Assertions
SVA
Assertions are like monitors and checkers
You can also use a high level language like C C++ to write
assertions
vcs provides two constructs assert and expect to check the
behavior of the DUT from within the TestBench
assert construct is used to check the behavior of the property you are
checking during the current simulation time
expect construct is used to check the behavior of the property you are
checking over many clock cycles.
Syntax is
[label:] assert (expression) [action block] [else statement]
[label:] expect (property spec) [action block] [else statement]
2/5/2013
SVA example
Check SVA (SystemVerilog assertions)
program automatic test (arbiter_if.TEST arbif);
//synchronosly drive request
initial begin
arbif.cb.req <= 1;
//dont forget to use cb in signal reference
repeat (2) @arbif.cb;
arb1 : assert (arbif.cb.gnt == 1); //SystemVerilog assertion
end
endprogram
If SVA succeeds, then the clause after the assert keyword is executed
If it fails then it checks for else clause and executes it if it exists. If
there is no else clause it prints an error. In the example above since
there is no else clause it will print an error .
2/5/2013
SVA example
We can add the optional else clause if we want to add some custom
messages
You can use $info, $warn, $error and $failure for reporting messages
program automatic test (arbiter_if.TEST arbif);
initial begin
arbif.cb.req <= 1;
repeat (2) @arbif.cb;
arb1 : assert (arbif.cb.gnt == 1); //SystemVerilog assertion
else
$error ( grant failed)
end
.
endprogram
2/5/2013
SystemVerilog scheduling
2/5/2013
SystemVerilog Scheduling
There are 3 regions which are involved in the
evaluation and execution of the assertions
Preponed
Assertion variable values are sampled in this region. Since we are
sampling variables they cannot change state and must be stable.
Observed
All the property expressions are evaluated in this region. For e.g.
assert (arbif.cb.gnt == 1); property is evaluated here
Reactive
The property evaluation results are scheduled in this region. For
e.g. the pass fail results of the evaluation of arb.cb.gnt ==1 are
scheduled in this region.
2/5/2013
SVA
2 types of SystemVerilog Assertions Concurrent and
Immediate assertions
Concurrent Assertions
Based on clock cycles
Variables are sampled in the preponed region
Test Expressions are evaluated in the observed region based on
the value of the variables
Can be placed in procedural blocks, modules, interface or program
definition
Can be used with both static(formal verification) and dynamic
verification simulation tools
2/5/2013
SVA
e.g. of concurrent assertions
y_xor_z: assert property ( (@posedge clk) (y ^ z));
Important point to note is that the property is being evaluated on
every positive edge of clock irrespective of whether y or z changes.
In the waveform all successes are shown with an up arrow and all
failures are shown with a down arrow.
Immediate Assertions
Based on Simulation event schematics
Should be placed in a procedural block
Test expression is evaluated immediately in the procedural
block. Useful for checking combinatorial expressions
2/5/2013
10
Immediate Assertions
Immediate Assertions continued
Used only in dynamic simulations.
Keyword that differentiates Immediate from concurrent is
the keyword property
always_comb
begin
y_xor_z: assert (y ^ z);
end
2/5/2013
11
12
2/5/2013
13
2/5/2013
14
15
16
2/5/2013
17
Implication operator
property p1;
@(posedge clk) x ##5 y;
endproperty
a1: assert property (p1);
$display (assertion a1 passed \n);
else
$display (assertion a1 failed \n);
Property looks for a valid start of sequence on every clock cycle and in this
case, x to be high on every clock cycle. If x is not high then an error is
given by the checker which may not be of interest to us because that may
produce a lot of errors. We are only interested in the case where y is 1, 5
clock cycles after x is 1 and if x is 0 we are not interested. So we can use
an implication operator which is like an if else clause.
2/5/2013
18
Implication operator
There are two types overlapped and non overlapped
Overlapped implication operator |->
property p1;
@(posedge clk) x |-> y;
endproperty
a1: assert property (p1);
$display (assertion a1 passed \n);
else
$display (assertion a1 failed \n);
In this case a real success is when x is high and y is high on the same clock
cycle.
A vacuous success is where x is not high and the assertion succeeded by
default
2/5/2013
19
Implication operator
Non overlapped implication |=>
property p1;
@(posedge clk) x |=> y;
endproperty
a1: assert property (p1);
$display (assertion a1 passed \n);
else
$display (assertion a1 failed \n);
20
2/5/2013
21
Timing windows
property p1;
@(posedge clk) (x && z) |-> ##[1:3] y;
endproperty
a1: assert property (p1);
$display (assertion a1 passed \n);
else
$display (assertion a1 failed \n);
In this case a real success is when the Boolean expression (x&&z) is 1 and
y is high 1 to 3 clock cycle later.
A vacuous success is where the Boolean expression is not high and the
assertion succeeded by default
2/5/2013
22
2/5/2013
23
2/5/2013
24
$past construct
Syntax is
$past(signal name, number of clock cycles)
property p1;
@(posedge clk) (x && y) |-> ($past((c && d), 2) == 1);
endproperty
a1: assert property (p1);
$display (assertion a1 passed \n);
else
$display (assertion a1 failed \n);
2/5/2013
25
Repetition operators
SVA provides 3 types of repetition operators. Consecutive, go to and nonconsecutive repetition.
Consecutive repetition
Signal or sequence [*n] where n is the number of times the sequence
or signal should match repeatedly
go to operator
Signal [-> n] where n specifies the no of times the sequence or signal
should match not necessarily on consecutive clock cycles.
The last match for the go to should happen in the clock cycle before
the end of the entire sequence matching
Non-consecutive repetition
Signal or sequence [=n] similar to go to except that it does not require
that the last match happen in the clock cycle before the end of the
entire sequence matching
2/5/2013
26
Repetition operators
property no_two_ads;
disable iff (~reset) @(posedge clk) not (ads[*2]) ;
endproperty
a1: assert property (no_two_ads);
$display (assertion a1 passed \n);
else
$display (assertion a1 failed \n);
2/5/2013
27
Repetition operators
property p1;
@(posedge clk) $rose (start) |-> ##5 (a[*2] ) ##1 (stop) ##1 (!stop);
endproperty
a1: assert property (p1);
$display (assertion a1 passed \n);
else
$display (assertion a1 failed \n);
28
Repetition operators
Go to example:
property p1;
@(posedge clk) $rose (start) |-> ##5 (a[->2] ) ##1 (stop) ;
endproperty
a1: assert property (p1);
$display (assertion a1 passed \n);
else
$display (assertion a1 failed \n);
29
Repetition operators
Example non consecutive repetition
property p1;
@(posedge clk) $rose (start) |-> ##5 (a[=2] ) ##1 (stop) ##1 (!stop) ;
endproperty
a1: assert property (p1);
$display (assertion a1 passed \n);
else
$display (assertion a1 failed \n);
30
Throughout construct
The throughout construct is used to make sure certain condition holds true during
the evaluation of the entire sequence.
----------------------------------------------------------------------------------------------
property p1;
@(posedge clk) $rose (start) |-> (start) throughout ( ##5 (a[*2] ) ##1 (stop) ##1 (!stop) );
endproperty
a1: assert property (p1);
$display (assertion a1 passed \n);
Else
$display (assertion a1 failed \n);
----------------------------------------------------------------------------------------------
Property checks 5 clocks after start signal a remains high for 2 continuous clock
cycles and 1 clock after that signal stop is high and 1 clock after that signal stop is
low. During the entire test expression start should remain high.
A vacuous success is where start is not high and the assertion succeeded by
default
2/5/2013
31
32
The or operator
sequence s1;
@(posedge clk) a ##5 b;
endsequence
sequence s2;
@(posedge clk) c ##5 d;
endsequence
property p1 ;
@(posedge clk) s1 or s2;
endsequence
a1: assert property (p1);
33
34
35
Within construct
Within construct.
If there are two sequences s1 and s2 and you have the
construct
s1 within s2
2/5/2013
36
Within Construct
sequence s1;
@(posedge clk) a ##5 b;
endsequence
sequence s2;
@(posedge clk) c ##5 d;
endsequence
property p1 ;
@(posedge clk) s1 within s2;
endsequence
a1: assert property (p1);
Starting matching point of s2 which is c being 1 on posedge clock should happen before
the starting matching point of s1 which is a being 1 on posedge of clock
Ending matching point of s1 which is b being high should happen before ending
matching point of s2 which is d being high
2/5/2013
37
$onehot0(expression)
Checks to see if the expression is one hot zero i.e. only one bit in the
expression is high on any clock cycle or none of the bits are high on
any given clock edge
$isunknown(expression)
Checks to see if any bit in the expression is X or Z.
$countones(expression)
Count the no of bits that are high in an expression
2/5/2013
38
39
Assertions Assignment
Add Assertions to Project 2 for the following
Assert when the 3 FIFOs overflow or underflow.
Catch the condition where a command of 11 is received
by the DUT.
How can you verify mutually exclusive statements? and
use it to check if the full and empty ever occur
simultaneously.
Create an assertions sequence to check that the busy
signal is asserted only when all the FIFOs are full, and later
when the FIFO is Not full, it is de-asserted.
Also, write an assertion to check, that the DUT does not
assert an output_valid, when the output_busy is asserted.
2/5/2013
40