A7.5.2 Off or Kill?

EasyDebugIcarus · browser samples / server checksReview the topic

Follow a run of $assertoff, $asserton and $assertkill calls with levels and scopes, and count what each assertion reports.

Hardware context: A bench with rule instances at three levels of hierarchy, switched by assertion control calls. Predict which instances report after calls with levels and scopes, and which attempts survive.

The program below has five assertions in three levels of hierarchy. Four of them fail at every edge they check. A run of control calls switches them on and off.

Write answer(q). For questions 3 to 7, return how many times an assertion reports a failure, by the standard.

Questions 0 to 2 are worked examples on other calls. Questions 3 to 7 are graded only by the full check.

Signals in the Timeline

SignalWidthRole
question4input of each check
Full specification
The program, questions 3 to 7
module rules (input logic clk, ok);
  r: assert property (@(posedge clk) ok) else $display("%m fails");
endmodule
module unit (input logic clk, ok);
  u_r: assert property (@(posedge clk) ok) else $display("%m fails");
  rules inner (.clk(clk), .ok(ok));
endmodule
module tb;
  logic clk = 0;
  always #5 clk = ~clk;                         // rising edges at 5, 15, ..., 95
  logic ok = 0, req = 0, ack = 0;               // ok stays 0: every checked edge fails
  unit u1 (.clk(clk), .ok(ok));
  unit u2 (.clk(clk), .ok(ok));
  top_r: assert property (@(posedge clk) ok) else $display("%m fails");
  late:  assert property (@(posedge clk) req |-> ##3 ack) else $display("%m fails");
  initial begin
    $assertoff(0, tb.u1);                       // t=0
    #12 req = 1;                                // edge 15: late starts an attempt, due at 45
    #10 $asserton(1, tb.u1);                    // t=22
    req = 0;
    #5  $assertoff(0, tb.late);                 // t=27
    #15 $assertkill(0, tb.top_r);               // t=42
    #20 $asserton;                              // t=62
    #38 $finish;                                // t=100
  end
endmodule
qReturnProgram
0how many failures one: assert property (@(posedge clk) 0) reports in 5 ... 45, with $assertoff at 12 and $asserton at 32worked example
1a rule x \|-> ##3 y with x high only at 5 and y never high: its failures, with $assertkill at 12 and $asserton at 32worked example
2how many of tb.a.x and tb.a.b.y $assertoff(1, tb.a) switches offworked example
3failures of tb.u1.u_rgraded
4failures of tb.u1.inner.rgraded
5failures of tb.top_rgraded
6failures of tb.u2.inner.rgraded
7failures of tb.lategraded

Simulator note: The key follows IEEE 1800-2023 20.11. Verilator 5.052 ignores the levels and the scope list, so it would print other counts. Your answer function is checked by a small bench on Icarus 12.

Examples

Example 1

Edges Skipped While Off
Input
answer(0)
Output
answer = 3

The edges at 15 and 25 come while the rule is off. 5, 35 and 45 are checked.

Example 2

A Kill Cancels the Running Attempt
Input
answer(1)
Output
answer = 0

The attempt from 5 would fail at 35. The kill at 12 cancels it, so it never reports.

Example 3

Level 1 Is the Scope Alone
Input
answer(2)
Output
answer = 1

tb.a.x is in tb.a. tb.a.b.y is one level below, so it stays on.

Constraints and Contract

  • Return one value per question from answer(q).
  • Keep the function header.

Hints

Hint 1

The levels count like $dumpvars: 0 is the scope and everything below it, 1 is the scope alone.

Hint 2

$asserton with no arguments switches every assertion on.

Hint 3

$assertoff lets an attempt that is already running finish and report.

What the grader checks: Eight constant answers: three worked examples and five graded questions, keyed from IEEE 1800-2023 20.11 and derived by hand.

8 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Edges Skipped While Off

Input
answer(0)
Expected output
answer = 3

The edges at 15 and 25 come while the rule is off. 5, 35 and 45 are checked.

Run samples executes all 3 public checks. Check all tests runs 8 checks on the server.

Icarus · browser samples / server checks