$assertoff, $asserton and $assertkill
Switch assertions off and on during a run, and know which attempts survive $assertoff and which $assertkill cancels.
You Will Be Able To
- Predict which attempts report after
$assertoff,$assertonand$assertkill. - Choose between off and kill around a reset in the middle of a test.
- Read the levels and scope arguments of the three tasks.
- Tell the standard's behaviour from what Verilator 5.052 does.
- Lesson
- A7.5
- Time
- 25 min
- Runs on
- Verilator
- Check
- 5 questions
A test resets the design in the middle of a run. The handshake rule req |-> ##3 ack fails one cycle after the reset ends: an attempt started before the reset was still waiting for ack. Switching the rule off for the reset did not help. Killing it did.
$assertoff stops new attempts only. $assertkill also cancels the attempts already running.
$assertoff: No New Attempts
$assertoff stops new attempts from starting. Attempts already running go on, and their pass or fail statements still run.
Standard (IEEE 1800-2023 20.11)
// $assertoff at 27, never on again
// the attempt from 15 fails at 45
t=45 late fails
A running attempt is not affected, even while the rule stays off.
Verilator 5.052 (measured)
// $assertoff at 27, never on again
// nothing printed
The failure is dropped when the rule is still off at 45. It is reported only if the rule is on again by then.
$asserton: Checking Resumes
$asserton lets new attempts start again, from the next clock tick. It does not bring back attempts that a kill cancelled, or edges that passed while the rule was off.
$assertkill: Cancel the Running Attempts
$assertkill cancels every attempt that is running, then stops new ones like $assertoff. Only $asserton starts checking again.
- Control / FSM
- Control
- $assertoff
New attempts stop. The running ones go on and report as usual.
- $assertkill
The running attempts are cancelled with no report, and new ones stop.
- $asserton
New attempts start again from the next tick.
Read the diagram as text
- checking: new attempts start at each tick
- not checking: no new attempts
- running attempts: finish and report
- running attempts: cancelled, no report
- checking → running attempts: $assertoff
- running attempts → not checking: then
- checking → running attempts: $assertkill
- running attempts → not checking: then
- not checking → checking: $asserton
IEEE 1800-2023 20.11.
Levels and Scope Arguments
Each task takes optional arguments: a number of levels, then a list of scopes or assertions. levels counts like $dumpvars: 0 means the scope and everything below it, 1 means the scope alone.
| Call (hierarchy: tb with top_r; tb.u1 and tb.u2, each with u_r and inner.r) | Standard: switched off | Verilator 5.052 (measured) |
|---|---|---|
$assertoff; | every assertion | every assertion |
$assertoff(0, tb.u1); | tb.u1.u_r and tb.u1.inner.r | every assertion |
$assertoff(1, tb.u1); | tb.u1.u_r only | every assertion |
$assertoff(0, tb.top_r); | tb.top_r only | every assertion |
$assertoff(0, tb.u2.inner); | tb.u2.inner.r only | every assertion |
Standard behaviour, IEEE 1800-2023 20.11 and 21.7.1.2 (docs/sva-standard-traces, sva-182). Measured by tools/probes/sva-w1b/departures.mjs.
Verilator 5.052 ignores the levels and the list: every call switches every assertion. To switch one instance on this site, give its rules an enable input and put it in the antecedent. No attempt starts while it is low, and running attempts go on: the same effect as $assertoff for that scope.
Try It
The reset kills the attempt from 15 that was waiting for ack, and the rule is off for the whole reset. It comes back on at the first edge after the reset, so the attempt from 65 is checked and fails at 95.
Replace $assertkill with $assertoff and predict the output. The attempt from 15 then survives the reset and fails at 45.
t=95 late failsCheck Yourself
Common Mistakes
Wrong Switch a handshake rule off for a reset with $assertoff.
An attempt started before the reset keeps running and fails when the reset ends.
Fix Use $assertkill at the start of the reset, or disable iff (rst) in the rule.
always @(posedge rst) $assertoff;
always @(negedge rst) $asserton;always @(posedge rst) $assertkill;
always @(negedge rst) $asserton;Wrong Forget $asserton after the reset.
Off and kill last until $asserton, so the rest of the test runs unchecked.
Fix Pair every off or kill with an $asserton.
Wrong Trust $assertoff(0, tb.u1) to switch off one instance on Verilator 5.052.
The tool ignores the scope list, so the call switches every assertion in the design.
Fix Give the instance's rules an enable input and use it in the antecedent.
Remember
$assertoffstops new attempts; running attempts finish and report.$assertkillalso cancels the running attempts.$assertonresumes checking from the next tick; killed attempts stay cancelled.- Levels count like
$dumpvars: 0 is the scope and below, 1 is the scope alone. - Verilator 5.052 ignores the scope list and drops reports of attempts that end while off.