Debugging a Failing Assertion

Find the attempt behind a failure and print what it saw. Split a long rule to find the broken step, and tell real failures from false ones.

You Will Be Able To

  • Name the attempt and the edge behind a reported failure.
  • Print sampled values in an action block.
  • Split a long sequence into anchored pieces to find the broken step.
  • Recognise vacuous passes, reset failures and blocking action blocks.
Lesson
A10.2
Time
30 min
Runs on
Verilator
Check
5 questions

The log says "late fails at 45". The engineer opens the waveform at 45 and sees nothing wrong there. The bug happened 30 ns earlier: the failure time is where an attempt ended, not where it began.

A Debugging Routine for One FailureFour questions, in order, before touching the design.
  • Step
  • Control
connect() link
A debugging routine for one failureFour questions, in order, before touching the design. step Which attempt? failure time minus thedelays step What did it see? $sampled values step Which stepbroke? split the sequence step Is the failurereal? vacuity, reset, clock thenthenthen
  1. step Which attempt?failure time minus the delays
    • then → What did it see?
  2. step What did it see?$sampled values
    • then → Which step broke?
  3. step Which step broke?split the sequence
    • then → Is the failure real?
  4. step Is the failure real?vacuity, reset, clock
  1. Locate

    Walk back from the failure time to the edge where the attempt started.

  2. Observe

    Print the values the assertion used, not the values after the edge.

  3. Narrow

    A long sequence hides which step broke; pieces name it.

  4. Question the rule

    Before blaming the design, rule out a vacuous rule, a reset and the wrong clock.

Read the diagram as text
  • Which attempt?: failure time minus the delays
  • What did it see?: $sampled values
  • Which step broke?: split the sequence
  • Is the failure real?: vacuity, reset, clock
  • Which attempt? → What did it see?: then
  • What did it see? → Which step broke?: then
  • Which step broke? → Is the failure real?: then

SVA-FC 2.15-2.16, 17.9, 17.11.

Which Attempt, Which Edge

A failure is reported at the edge where its attempt fails. For req |-> ##3 ack, that is three edges after the attempt began.

$sampled in the Action Block

The action block runs after the edge. By the standard, a signal read there directly can already hold its new value. $sampled returns the value the assertion used.

Standard (IEEE 1800-2023 16.14.1, 4.4)

// the same program, printing cnt directly too
t=35 cnt=4 sampled=3

The action block runs in the Reactive region, after the edge has updated cnt.

Verilator 5.052 (measured)

// the same program, printing cnt directly too
t=35 cnt=3 sampled=3

Its action block runs before the update, so the direct read shows the old value. Only $sampled is portable.

Splitting into Subsequences

A long rule fails as one piece. Split it into pieces, each anchored on the steps before it, and the failing piece names the broken step.

Each piece keeps the steps before it as its antecedent. A piece without them, such as data_v |=> resp, fires on unrelated traffic.

Vacuity: A Rule That Never Triggers

A rule whose antecedent never matches passes at every edge, vacuously. Zero failures then mean nothing. A cover of the antecedent shows whether it ever matched.

False Failures from Reset and Clocks

An attempt that crosses a reset fails because the design was cleared, not because it broke. disable iff (rst) cancels such attempts. The wrong clock, or a gated one, gives false failures too (A1.6).

Blocking Action Blocks

An action block that waits, with a delay or an event control, is still running when the next failure comes. Verilator 5.052 drops that failure's action; the standard does not say what must happen, so other tools may queue it.

Try It

The whole rule only says that something in the chain broke. The anchored pieces say which link: the step from data_v to resp.

Remove the line that raises grant and predict the four counts.

RUNVerilator · simulator service
Edit the code, then run it
Expected: whole=1 p1=0 p2=0 p3=1

Check Yourself

Predict the outputRequests at 15 and 25; ack at 45. Predict the output.
module tb;
  logic clk = 0;
  always #5 clk = ~clk;                        // rising edges at 5, 15, 25, ...
  logic req = 0, ack = 0;
  two: assert property (@(posedge clk) req |-> ##2 ack)
    else $display("t=%0t two fails", $time);
  initial begin
    #12 req = 1;                               // edges 15 and 25
    #20 req = 0;                               // t=32
    #10 ack = 1;                               // t=42: ack at 45
    #10 ack = 0;
    #20 $finish;
  end
endmodule
Spot the bugThe last piece of the split rule must not fire on a stray data_v from another master. Which piece does?
ConceptA rule reports zero failures over a whole regression. What should be checked first?
Conceptreq |-> ##4 ack fails at 90 on a clock with edges every 10. When did the failing attempt start?
ConceptWhy print $sampled(x) in an action block rather than x?

Common Mistakes

Wrong Look for the bug at the time the failure was reported.

For a rule with delays, the cause is at the start of the attempt.

Fix Subtract the delays to find the attempt, and start there.

Wrong Split a long rule into pieces that drop the steps before them.

An unanchored piece fires on unrelated traffic and reports false failures.

Fix Keep the earlier steps in each piece's antecedent.

Before
data_v |=> resp
After
req ##1 grant ##2 data_v |=> resp

Wrong Wait in an action block.

Failures that come while it waits may lose their action.

Fix Record and return at once; do slow work in a separate process.

Remember

  • A failure is reported where its attempt ends; the cause is where the attempt began.
  • Print $sampled values in action blocks.
  • Anchored pieces of a long rule name the broken step.
  • Check vacuity with a cover, guard resets with disable iff, and keep action blocks non-blocking.

Practice

Report a problem with this page