System Verilog Assertions
System Verilog Assertions
ASSERTIONS
ROHIT KHANNA
Assertions and Coverage
Assertions
These are checks which used to verify that your design meets
the given requirements.
Example: grant should be high two clock cycles after request
Coverage
These are used to judge what percentage of your test plan or
functionality has been verified.
They are used to judge quality of stimulus.
They help us in finding what part of code remains untested.
Clock
Request
Assertion Passed
Grant
Assertion Failed
Grant
Types of Assertions
Immediate Assertions.
Concurrent Assertions.
These checks are Non Temporal i.e. checks are not performed
across time or clock cycles.
clk
req1
req2
always @ (state)
assert(state==$onehot) else $fatal;
//In a one-hot encoded state machine all states should be one-hot
Clk
Req
Assertion Passed
Gnt
property req_gnt;
@ (posedge clk) req ##2 gnt ##1 !req ##1 !gnt;
endproperty
assert property(req_gnt) else (“req_gnt property violated”);
If gnt is not high 2 clock cycles after req goes high, violation
will be reported.
If req and gnt come at proper time but req is not low in next
clock cycle, that will also lead to violations.
System Verilog Assertions
Assertion Region
Postponed Re-NBA
property disable_property;
@ (posedge clk) disable iff (reset)
a ##1 b ##1 c;
endproperty
property p1;
@ (posedge clk) disable iff (reset) assert property(p1);
s1 ##1 s2;
endsequence
sequence s1;
@(posedge clk) a ##1 !b ##1 c ##0 !d;
endsequence
clk
Syntax:
sequence sequence_name [ (arguments) ];
boolean_expression;
endsequence [ : sequence_name]
System Verilog Assertions
Sequence Arguments
property p1;
@ (posedge clk) en |-> (req ##2 ack);
endproperty
clk
en
req
gnt
clk
en
req
gnt
property p1;
@ (posedge clk) en |=> (req ##2 ack);
endproperty
clk
en
req
gnt
clk
en
req
gnt
clk
a
Assertion Passed
b
Assertion Passed
b
Assertion Passed
b
Assertion Failed
b
b must be true for two consecutively clock cycles after a goes high
a (##1 b ##1 c) [*2];
sequence s5;
@ (posedge clk) a ##1 b [=2];
endsequence
clk
b
Assertion Passed
b
Assertion Passed
sequence s6;
@ (posedge clk) a ##1 b [=2: 3];
endsequence
clk
a
b
seq1detected
Resultant Sequence Detected
c
d
e
seq detection started Seq2 detected
System Verilog Assertions
Example
(a and b)
clk
clk
a
b
d
e
clk
a
b
seq detection started
c
d
e
Seq1 Detected Seq2 Detected Resultant Sequence Detected
System Verilog Assertions
OR Operator
seq1 or seq2
clk
a
b
seq1detected
Resultant Sequence Detected
c
d
e
seq detection started Seq2 detected
System Verilog Assertions
Example
(a or b)
clk
clk
a
b
seq detection started
c
d
e
Seq1 Detected Seq2 Detected Resultant Sequence Detected
System Verilog Assertions
First_match Operator
first_match(a ##[2:4] b)
clk
clk
property nomatch;
@(posedge clk) start -> not (abc);
endproperty
property incorrect;
@ (posedge clk) not (a ##1 b -> c ##1 d);
endproperty
property correct;
@ (posedge clk) not(a ##1 b ##0 c ##1 d);
endproperty
System Verilog Assertions
If-else Expression
property test;
@(posedge clk) (req1 || req2) ->
if(req1)
##1 ack1;
else
##1 ack2;
endproperty
sequence s1;
int i;
(data_valid, (i = tag_in))
##7 (tag_out == i);
endsequence
p1 asserted p2 asserted
Note:
1) The “and” between intr and the recursive call will make sure that if intr
goes low before intrAck - the property/assertion fails
2) The “or” makes sure that property passes when intrAck goes high
System Verilog Assertions
Restrictions on Recursive Properties