Assertions for Beginners
Learn how SystemVerilog assertions automatically detect incorrect behavior and turn protocol requirements into executable checks.
Learning objectives
- Explain what an assertion is and why verification environments use them.
- Write simple immediate assertions using
assert. - Understand the difference between immediate and concurrent assertions.
- Write basic temporal properties using SystemVerilog Assertions (SVA).
- Use implication operators to describe protocol relationships.
- Use
$pastto check behavior across clock cycles. - Disable assertions during reset using
disable iff. - Recognize how assertions complement UVM monitors, scoreboards, and reports.
Step 1: Why verification needs assertions
A testbench does not only generate stimulus. It must also determine whether the DUT behaved correctly.
One simple way to check behavior is with procedural code:
if (data !== expected_data) begin
$error("Data mismatch");
end
This works, but many hardware requirements are naturally expressed as rules about values and time:
- A request must eventually receive a response.
- A signal must remain stable while
validis asserted. - A FIFO must never report empty and full at the same time.
- A request must not occur while reset is active.
- When
valid && readyis true, a transfer occurs.
Assertions allow these requirements to become executable checks.
Step 2: Your first assertion
The simplest SystemVerilog assertion checks a Boolean expression.
assert (data == expected_data);
If the expression is true, the assertion passes. If it is false, the assertion fails.
You can provide an explicit failure message:
assert (data == expected_data)
else
$error("Data mismatch: expected=%0h actual=%0h",
expected_data,
data);
This is called an immediate assertion because it evaluates the expression when the statement executes.
Step 3: Immediate assertions
Immediate assertions are procedural statements. They are useful when the testbench already has a specific point in time at which it wants to check a condition.
task check_result(
bit [31:0] actual,
bit [31:0] expected
);
assert (actual == expected)
else
$error(
"Mismatch: actual=%0h expected=%0h",
actual,
expected
);
endtask
You can use immediate assertions inside procedures, classes, functions where appropriate, and other procedural code.
Step 4: Assertions for simple protocol rules
Suppose a protocol says that valid and ready
must not both be unknown.
assert (!$isunknown({valid, ready}))
else
$error("Protocol signals contain X or Z");
Another example is checking that a counter does not exceed its maximum value:
assert (count <= MAX_COUNT)
else
$error("Counter exceeded maximum value");
These checks are useful because they automatically detect failures during simulation rather than relying on a human to inspect every waveform.
Step 5: The limitation of immediate assertions
Immediate assertions are excellent for checking a condition at one point in time, but hardware protocols often describe relationships between multiple clock cycles.
Consider this requirement:
req is asserted, ack must be
asserted on the next clock cycle.
This is a temporal requirement. It describes what should happen now and what should happen later.
This is where concurrent assertions become useful.
Step 6: Concurrent assertions
A concurrent assertion evaluates behavior in relation to a clock.
property req_ack;
@(posedge clk)
req |-> ##1 ack;
endproperty
assert property (req_ack);
Read this as:
clk, if req
is true, then ack must be true one clock cycle later.
This is much closer to the way hardware engineers naturally describe synchronous protocol requirements.
Step 7: Understanding the property
Break the assertion into pieces:
property req_ack;
@(posedge clk)
req |-> ##1 ack;
endproperty
-
property req_ackgives the property a name. -
@(posedge clk)defines the clock used to evaluate it. -
reqis the condition that starts the check. -
|->is an implication operator. -
##1means one clock tick later. -
ackis the expected result.
Step 8: Implication
Implication is one of the most useful ideas in assertions.
It lets you express:
IF this happens
THEN this must happen
For example:
req |-> ack
This means that when the antecedent req is true,
the consequent ack must satisfy the property.
You will commonly see two implication operators:
| Operator | Meaning |
|---|---|
|-> |
Overlapped implication; the consequent can begin in the same clock cycle. |
|=> |
Non-overlapped implication; the consequent begins on the following clock cycle. |
For example:
req |=> ack
means that if req is true on one clock edge,
ack must be true on the next clock edge.
Step 9: Checking behavior one cycle later
The $past() system function lets an assertion refer to
a value from a previous clock cycle.
assert property (
@(posedge clk)
valid |-> $past(request)
);
A more intuitive example is a register update:
assert property (
@(posedge clk)
enable |-> data == $past(data) + 1
);
The exact property you write depends on the DUT specification,
but the key idea is that $past() lets an assertion
reason about previous sampled values.
Step 10: Checking signal stability
Many protocols require a signal to remain stable while another condition is active.
For example:
valid is asserted and ready is low,
the transaction data must remain unchanged.
One way to express this is:
property data_stable;
@(posedge clk)
valid && !ready |=> $stable(data);
endproperty
assert property (data_stable);
The $stable() system function checks whether the sampled
value has remained unchanged.
This kind of property is extremely useful for handshake protocols.
Step 11: Assertions and reset
Assertions often should not check normal protocol behavior while the DUT is being reset.
SystemVerilog provides disable iff for this purpose.
assert property (
@(posedge clk)
disable iff (!reset_n)
valid |-> ready
);
Here, the property is disabled whenever reset_n is low.
Step 12: Assertion pass and failure messages
An assertion is most useful when a failure tells you what went wrong.
assert property (
@(posedge clk)
disable iff (!reset_n)
req |=> ack
)
else
$error("REQ was asserted without ACK on the next cycle");
The failure message should describe the violated requirement rather than simply saying "assertion failed."
Step 13: A small FIFO example
Assertions become especially useful when checking simple hardware invariants.
Suppose a FIFO has full and empty status
signals. They should never both be asserted at the same time.
assert property (
@(posedge clk)
!(full && empty)
)
else
$error("FIFO cannot be full and empty simultaneously");
Another requirement might be that a read should not occur while the FIFO is empty:
assert property (
@(posedge clk)
read |-> !empty
)
else
$error("FIFO read attempted while empty");
These checks run automatically throughout the simulation.
Step 14: Assertions vs. procedural checks
Assertions do not replace every other verification technique. Different checks are useful for different problems.
| Technique | Good for |
|---|---|
| Immediate assertion | Checking a condition at a specific procedural point. |
| Concurrent assertion | Checking temporal and clock-based behavior. |
| Scoreboard | Comparing actual transactions against expected transactions. |
| Coverage | Measuring whether important scenarios were exercised. |
| Waveform | Debugging what happened during simulation. |
Step 15: Assertions and UVM
Assertions are part of SystemVerilog, not UVM itself. UVM provides the framework for organizing the verification environment, while SystemVerilog assertions provide powerful behavioral checks.
Later in the course, you will see assertions used alongside:
- UVM monitors.
- UVM drivers.
- Scoreboards.
- Reference models.
- Coverage collectors.
- UVM reporting.
A useful mental model is:
Verification Environment
|
+--------------+--------------+
| | |
Stimulus Observation Checking
| | |
Driver Monitor Assertions
| | Scoreboard
v v |
DUT |
| |
+-------------+
Assertions are especially good at detecting local protocol and temporal violations close to the signals being checked.
Step 16: A practical protocol example
Consider a simple valid/ready interface:
interface stream_if(input logic clk);
logic reset_n;
logic valid;
logic ready;
logic [31:0] data;
endinterface
Suppose the protocol has these requirements:
- A transfer occurs when
valid && readyis true. - If
validis high andreadyis low, data must remain stable. - Neither
validnorreadyshould contain unknown values during normal operation.
These requirements can become assertions:
assert property (
@(posedge clk)
disable iff (!reset_n)
valid && !ready |=> $stable(data)
);
assert property (
@(posedge clk)
disable iff (!reset_n)
!$isunknown({valid, ready})
);
Now the protocol specification is executable. If the DUT violates one of these rules during simulation, the simulator can report it immediately.
Step 17: Common mistakes
Mistake 1: Checking the wrong clock
A concurrent assertion must use a clock that represents the timing of the behavior being checked.
Mistake 2: Misreading implication timing
|-> and |=> have different timing semantics.
Draw the clock cycles when you are learning them.
Mistake 3: Forgetting reset
A property that is valid during normal operation may produce
meaningless failures during reset. Consider whether
disable iff is appropriate.
Mistake 4: Writing assertions without a specification
An assertion should represent a real design requirement. Do not write checks simply because the syntax looks interesting.
Mistake 5: Using assertions for everything
A temporal assertion is not always the right tool for transaction comparison. A scoreboard may be much better for comparing complex expected and actual transactions.
Mistake 6: Ignoring the failure message
A useful assertion should help the verification engineer understand the failure quickly.
Step 18: Your assertion-writing workflow
When writing a new assertion, use this process:
- Write the requirement in plain English.
- Identify the clock.
- Identify the triggering condition.
- Identify what must happen afterward.
- Determine whether reset should disable the check.
- Write the property.
- Add a useful failure message.
- Create a test that intentionally violates the rule.
Try it yourself
Create assertions for a simple valid/ready protocol.
-
Assert that
validandreadynever contain unknown values during normal operation. -
Assert that when
validis high andreadyis low,dataremains stable on the next clock. -
Add
disable iff (!reset_n)to both properties. -
Add an
else $error(...)message to each assertion. - Create a testbench scenario that intentionally violates one of the properties.
- Observe the assertion failure in the simulator output and waveform.
Bonus:
Write an assertion for a request/acknowledge protocol where
req must be followed by ack on the
next clock cycle.
Quick check
- What is an assertion?
- What is the difference between an immediate and concurrent assertion?
- Why do concurrent assertions normally use a clock?
- What does
|->mean? - What does
|=>mean? - What does
$past()allow an assertion to do? - What does
$stable()check? - Why is
disable iffcommonly used with reset? - Why might a scoreboard be more appropriate than an assertion for comparing complex transactions?
- Why should you intentionally make an assertion fail during verification?
Show answers
- An executable check that verifies a condition or behavioral requirement.
- An immediate assertion checks a condition when procedural code executes it; a concurrent assertion checks behavior over clocked simulation time.
- Because many hardware requirements describe relationships between clock cycles.
- Overlapped implication; the consequent can begin in the same clock cycle as the antecedent.
- Non-overlapped implication; the consequent begins on the following clock cycle.
- It allows an assertion to reference a previously sampled value.
- It checks whether a value has remained unchanged.
- To prevent normal reset activity from producing irrelevant assertion failures.
- Scoreboards are generally better suited to comparing complete or complex transaction objects.
- To verify that the assertion actually detects the failure it was designed to catch.
Module 1 checkpoint
You have now completed the SystemVerilog foundation needed to begin learning UVM.
Before moving on, make sure you can explain this chain:
Verification problem
|
v
SystemVerilog data types
|
v
Classes and objects
|
v
Randomization and constraints
|
v
Queues and collections
|
v
Tasks and concurrency
|
v
Interfaces and timing
|
v
Assertions
|
v
UVM
UVM will build on these concepts rather than replace them.
Key takeaways
- An assertion turns a verification requirement into an executable check.
- Immediate assertions check conditions at a specific procedural point.
- Concurrent assertions are designed to check temporal behavior relative to a clock.
- Implication expresses "if this happens, then that must happen."
-
$past()allows properties to reason about previous clock cycles. -
$stable()is useful for checking that signals remain unchanged. -
disable iffis commonly used to disable properties during reset. - Assertions complement, rather than replace, scoreboards, monitors, coverage, and other verification techniques.
- Assertions are part of SystemVerilog; UVM provides the framework for organizing the broader verification environment.
- You should validate an assertion by intentionally creating the failure it is supposed to detect.