Follow $assertfailoff, $assertpassoff, $assertfailon and $assertpasson through a run, and count what the log shows.
Hardware context: A regression log flooded by pass messages of a mostly idle handshake rule. Silence pass messages without losing a single failure report.
A log-cleanup script switches the action blocks of a handshake rule during a run. The rule is checked at every edge; only its action blocks are switched.
Write answer(q). Questions 3 to 7 ask what the pass and fail actions record in the main program.
Questions 0 to 2 are worked examples on a smaller program. Questions 3 to 7 are graded only by the full check.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 4 | input of each check |
Full specification
module tb;
logic clk = 0;
always #5 clk = ~clk; // rising edges at 5, 15, ..., 95
logic req = 0, ack = 0;
int passes = 0, fails = 0, passes_50 = 0;
hs: assert property (@(posedge clk) req |-> ack)
begin passes++; $display("hs passes at %0t", $time); end
else begin fails++; $display("hs fails at %0t", $time); end
initial begin
#17 $assertfailoff; // t=17
#20 $assertpassoff; // t=37
#13 passes_50 = passes; // t=50
#7 $assertfailon; // t=57
#20 $assertpasson; // t=77
end
initial begin
#12 req = 1; ack = 1; // edge 15: real pass
#10 ack = 0; // edge 25: fail
#10 ack = 1; // edge 35: real pass
#10 ack = 0; // edge 45: fail
#10 req = 0; // edge 55: vacuous
#10 req = 1; // edge 65: fail
#10 ack = 1; // edge 75: real pass
#10 ack = 0; // edge 85: fail
#10 ack = 1; // edge 95: real pass
#6 $finish; // t=98
end
endmodule
| q | Return | Program |
|---|---|---|
| 0 | the value of p printed at 34 | worked example |
| 1 | the value of f printed at 34 | worked example |
| 2 | the time of the first chk failure print | worked example |
| 3 | the value of fails at the end | main, graded |
| 4 | the time of the first "hs fails" print | main, graded |
| 5 | the value of passes at the end | main, graded |
| 6 | the value of passes_50 | main, graded |
| 7 | the time of the last "hs passes" print | main, graded |
module tb;
logic clk = 0;
always #4 clk = ~clk; // rising edges at 4, 12, 20, 28
logic ok = 1;
int p = 0, f = 0;
chk: assert property (@(posedge clk) ok)
begin p++; end
else begin f++; $display("chk fails at %0t", $time); end
initial begin
#10 $assertpassoff; // t=10
#14 ok = 0; // t=24
#10 $display("p=%0d f=%0d", p, f); // t=34
$finish;
end
endmodule
Simulator note: The key was measured on Verilator 5.052 and agrees with IEEE 1800-2023 20.11. Your answer function is checked by a small bench on Icarus 12.
Examples
Example 1
Passes Before the Switch- Input
answer(0)
- Output
answer = 1
Only the pass at 4 comes before $assertpassoff at 10.
Example 2
Failures Are Untouched- Input
answer(1)
- Output
answer = 1
$assertpassoff does not touch the else action. The failure at 28 counts.
Example 3
The Rule Still Checks- Input
answer(2)
- Output
answer = 28
ok falls at 24, and the edge at 28 fails.
Constraints and Contract
- Return one value per question from answer(q).
- Keep the function header.
Hints
Hint 1
Write the result of each edge first: real pass, vacuous pass or failure. The controls never change these.
Hint 2
Then mark, for each edge, whether pass actions and fail actions are on at that moment.
Hint 3
A vacuous success runs the pass action too, while pass actions are on.
What the grader checks: Eight constant answers: three worked examples and five graded questions, measured on Verilator 5.052.
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