$assertcontrol

Use one task, $assertcontrol, to lock, switch and kill assertions, filtered by assertion type and directive type.

You Will Be Able To

  • Read a $assertcontrol call: control type, assertion type, directive type, levels, list.
  • Lock checks that no later call may switch.
  • Switch only concurrent assertions, or only assert directives, and leave the rest alone.
  • Name the parts Verilator 5.052 does not follow.
Lesson
A7.7
Time
25 min
Runs on
Verilator
Check
5 questions

A power-down test needs three things at once. The design rules sleep with the block, the bench assumptions stay on, and a safety check stays on whatever a library calls. One task with filters does all three.

The Five Arguments of $assertcontrolThe first argument says what to do. The next two filter by kind of assertion and by directive. The last two pick the scope.
  • Neutral
  • Data
connect() link
The five arguments of $assertcontrolThe first argument says what to do. The next two filter by kind of assertion and by directive. The last two pick the scope. neutral control_type 1 Lock ... 11VacuousOff neutral assertion_type 1 concurrent, 2immediate, ... (default255) neutral directive_type 1 assert, 2 cover, 4assume (default 7) neutral levels as $dumpvars(default 0) neutral list scopes or assertions filtered byand bywithinof
  1. neutral control_type1 Lock ... 11 VacuousOff
    • filtered by → assertion_type
  2. neutral assertion_type1 concurrent, 2 immediate, ... (default 255)
    • and by → directive_type
    • within → levels
  3. neutral directive_type1 assert, 2 cover, 4 assume (default 7)
  4. neutral levelsas $dumpvars (default 0)
    • of → list
  5. neutral listscopes or assertions
  1. What to do

    The control type: Lock, Unlock, On, Off, Kill, or one of the six action controls.

  2. Which kinds

    Two bit masks: the kind of assertion and the directive. Values can be ORed: 3 means concurrent and simple immediate.

  3. Where

    Levels and a list of scopes or assertions, as for the older tasks.

Read the diagram as text
  • control_type: 1 Lock ... 11 VacuousOff
  • assertion_type: 1 concurrent, 2 immediate, ... (default 255)
  • directive_type: 1 assert, 2 cover, 4 assume (default 7)
  • levels: as $dumpvars (default 0)
  • list: scopes or assertions
  • control_type → assertion_type: filtered by
  • assertion_type → directive_type: and by
  • assertion_type → levels: within
  • levels → list: of

IEEE 1800-2023 20.11, Tables 20-5 to 20-7. $assertoff is $assertcontrol(4, 15, 7).

Lock and Unlock

Control type 1 locks the selected assertions: no later $assertcontrol, and so no $assertoff or $assertkill, changes them. Type 2 unlocks them.

On, off and Kill

Types 3, 4 and 5 are On, Off and Kill. They behave like $asserton, $assertoff and $assertkill, with the filters added.

Pass, Fail and Vacuous Types

Types 6 to 11 are the action controls of A7.6: PassOn, PassOff, FailOn, FailOff, NonvacuousOn and VacuousOff. On Verilator 5.052, types 10 and 11 depart from the standard as their named tasks do.

The Assertion-Type Filter

The second argument picks kinds of assertion: 1 concurrent, 2 simple immediate, 4 and 8 the two deferred kinds, 16 expect. Values 32 to 128 pick the unique and priority violation reports. The default, 255, is all of them.

The Directive-Type Filter

The third argument picks directives: 1 assert, 2 cover, 4 assume. Default 7 is all three. A plan can silence the design rules and keep the bench assumptions checking.

Levels and the List

The last two arguments work as for $assertoff: $assertcontrol(4, 15, 7, 0, tb.p1) switches off everything in tb.p1 and below. Verilator 5.052 ignores them, as it does for the older tasks, and acts on the whole design.

Try It

Three rules, three treatments. The safety check is locked, so the library's Off at 40 does nothing and the bug at 55 is caught. The design rule sleeps with the block. The bench assumption catches the request at 35 during the sleep.

Change the directive type in both calls from 1 to 5, assert and assume. Predict which count drops to 0.

RUNVerilator · simulator service
Edit the code, then run it
Expected: crit=1 hs=1 env=1

Check Yourself

Predict the outputOnly the concurrent assertions are locked. Predict the output.
module tb;
  logic clk = 0;
  always #5 clk = ~clk;                        // rising edges at 5, 15, 25, 35, 45
  logic ok = 0;
  int imm = 0, conc = 0;
  always @(posedge clk) imm_ok: assert (ok) else imm++;
  conc_ok: assert property (@(posedge clk) ok) else conc++;
  initial begin
    $assertcontrol(1, 1);                      // t=0: Lock the concurrent assertions
    #12 $assertoff;                            // t=12
    #20 $asserton;                             // t=32
    #16 $display("imm=%0d conc=%0d", imm, conc);   // t=48
    $finish;
  end
endmodule
Spot the bugAt 12 the plan must switch off the design rule and keep the bench rule (an assume) checking. Which call fails?
ConceptWhich call is the same as $assertkill;?
ConceptAn assertion is locked, then $assertcontrol(4) runs. What happens?
ConceptWhich assertion_type value selects concurrent and simple immediate assertions?

Common Mistakes

Wrong Pass directive type 2 to switch the design assertions off.

Directive type 2 selects cover directives; assert is 1 and assume is 4.

Fix Use 1 for assert directives, or 5 for assert and assume.

Before
$assertcontrol(4, 15, 2);
After
$assertcontrol(4, 15, 1);

Wrong Lock a check after a library may already have switched it off.

A lock freezes the current state, off included.

Fix Lock at time 0, before any other control runs.

Wrong Expect the levels and list arguments to limit a call on Verilator 5.052.

The tool ignores them and applies the call to the whole design.

Fix Filter by assertion type and directive type, which the tool follows, or use an enable input per instance.

Remember

  • $assertcontrol(control, assertion_type, directive_type, levels, list) is the general form of every control task.
  • Lock (1) freezes the state of the selected assertions until Unlock (2).
  • Assertion type and directive type are bit masks: 1 concurrent, 2 immediate; 1 assert, 2 cover, 4 assume.
  • Verilator 5.052 follows the type filters but ignores levels and the list.

Practice

Report a problem with this page