$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, $asserton and $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.

One attempt across a reset
0123edge (ns)15253545reqrstwith $assertoff at 27, $asserton at 37startwaitsfailwith $assertkill at 27, $asserton at 37startwaitscancelled-a false failure after the reset
Scroll horizontally ↔

$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.

What Each Task Does to New and Running AttemptsAn assertion is either checking or not. Off and kill both stop new attempts; only kill touches the running ones.
  • Control / FSM
  • Control
call: who calls whomconnect() link
What each task does to new and running attemptsAn assertion is either checking or not. Off and kill both stop new attempts; only kill touches the running ones. control checking new attempts startat each tick control not checking no new attempts control running attempts finish and report control running attempts cancelled, no report $assertoffthen$assertkillthen$asserton
  1. control checkingnew attempts start at each tick
    • $assertoff → running attempts
    • $assertkill → running attempts
  2. control running attemptsfinish and report
    • then → not checking
  3. control not checkingno new attempts
    • $asserton → checking
  4. control running attemptscancelled, no report
    • then → not checking
  1. $assertoff

    New attempts stop. The running ones go on and report as usual.

  2. $assertkill

    The running attempts are cancelled with no report, and new ones stop.

  3. $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 offVerilator 5.052 (measured)
$assertoff;every assertionevery assertion
$assertoff(0, tb.u1);tb.u1.u_r and tb.u1.inner.revery assertion
$assertoff(1, tb.u1);tb.u1.u_r onlyevery assertion
$assertoff(0, tb.top_r);tb.top_r onlyevery assertion
$assertoff(0, tb.u2.inner);tb.u2.inner.r onlyevery 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.

RUNVerilator · simulator service
Edit the code, then run it
Expected: t=95 late fails

Check Yourself

Predict the outputPredict the output.
module tb;
  logic clk = 0;
  always #5 clk = ~clk;                        // rising edges at 5, 15, 25, ...
  logic ok = 0;
  int fails = 0;
  never_ok: assert property (@(posedge clk) ok) else fails++;
  initial begin
    #17 $assertkill;                           // t=17
    #20 $asserton;                             // t=37
    #5  $display("fails=%0d", fails);          // t=42
    $finish;
  end
endmodule
Spot the bugA reset from 27 to 37 interrupts an attempt that waits for ack. Which option reports a false failure?
ConceptAn assertion is switched off with $assertoff while an attempt is running, and stays off. What does the standard say about that attempt?
ConceptWhat does $assertoff(1, tb.u1) switch off?
ConceptAfter $assertkill, which call makes the assertions check again?

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.

Before
always @(posedge rst) $assertoff;
always @(negedge rst) $asserton;
After
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

  • $assertoff stops new attempts; running attempts finish and report.
  • $assertkill also cancels the running attempts.
  • $asserton resumes 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.

Practice

Report a problem with this page