Today we continue with the Logic Design series on SystemVerilog in order to talk about Assertions.
So, without further ado, let's get straight into it!
Assertions
Assertions are used for the purpose of verification. They specify the expected behavior of a design and are commonly used in Functional Coverage. More specifically, properties of the design are checked by an assertion and if the behavior is unexpected the assertion will fail.
It's possible to write assertions in the usual procedural fashion (always blocks and conditional statements), but this makes the code difficult to maintain and scale, as shown below.
Thus, SystemVerilog provides assertions in the form of a declarative language.
For example:
assertproperty(@(posedgeclk)expression);
Types
SystemVerilog provides two types of assertions:
Immediate Assertions : which follow simulation event semantics and are executed like statements in procedural blocks.
Concurrent Assertions : which are based on clock semantics and get evaluated every time, like an always block with a clock.
Immediate Assertions
Immediate Assertions are included in procedural blocks and can be as simple as:
assert(expression);
which operates just like an if statement.
They can optionally include a label (but one is assigned by the simulator either way) and different code for pass / fail of the conditions (like an if-else).
assert_label:assert(expression)begin// if condition is true (pass)endelsebegin// if condition is false (fail)end
For example, such an assertion can be placed on the randomization method (randomize) for constraints, because it returns 1 if the randomization is successful, as shown below.
A concurrent assertion can be distinguished from an immediate assertion easily as it is always tied to a clock definition and uses the keyword property.
It has the following layers:
boolean
sequence
property
assert property
Boolean Expressions
The Boolean layer is where the conditions are specified. All operators except the assignment, increment and decrement operators can be used in it. It's also possible to include function calls, but with no output or ref arguments.
Sequence
The conditions are included in a sequence and are checked at every clock event. Sequential checks that may take several clock cycles can be achieved using the ## operator, which is followed by some time delay.
Sequences can be combined into properties. Either the sequence or the property must include some kind of clocking event, so that assertion is possible.
Constraints and Randomization → Testing and Verification, Random Variables (Standard, Random-Cyclic), Randomize Method (Constraint and Random Mode, Pre / Post Randomize)