How a Test Ends

A run can end in a pass, a fail, a hang or a false pass. The last looks just like the first. Learn how a test decides it is finished, why it needs a time limit, and why it must count what never arrived.

You Will Be Able To

  • Name the four ways a run can end.
  • Say what a test must check before it may print PASS.
  • Explain what a time limit is for and what it does not prove.
Lesson
B2.5
Time
18 min
Runs on
Your browser
Check
5 questions

A test sends three requests, waits a while, finds no wrong answers and prints PASS. The design under test never answered at all. Every check the test made was right; it simply had nothing to check.

Four Ways a Run EndsStep through the four endings. Two of them print PASS. Only one of those deserves it.
  • Test
  • Result
  • Control
Four Ways a Run EndsStep through the four endings. Two of them print PASS. Only one of those deserves it. test A test runs stimulus sent,answers awaited result Pass every answer came,every answer right result Fail a check found a wronganswer result Hang waits for ever, unlessa limit stops it result False pass stopped early, orchecked nothing all answers, all righta mismatchno answerlooks the same
  1. test A test runsstimulus sent, answers awaited
    • all answers, all right → Pass
    • a mismatch → Fail
    • no answer → Hang
  2. result Passevery answer came, every answer right
    • looks the same → False pass
  3. result Faila check found a wrong answer
  4. result Hangwaits for ever, unless a limit stops it
  5. result False passstopped early, or checked nothing
  1. Pass

    Every expected answer arrived and every one was right. Only then is PASS true.

  2. Fail

    A check saw a wrong answer. The honest ending: the test caught something.

  3. Hang

    The design never answers and the test waits for ever. A time limit turns a hang into a failure with a reason.

  4. False pass

    The test stopped before the answers came, or never checked them, and printed PASS anyway. It looks exactly like a real pass.

Read the diagram as text
  • A test runs: stimulus sent, answers awaited
  • Pass: every answer came, every answer right
  • Fail: a check found a wrong answer
  • Hang: waits for ever, unless a limit stops it
  • False pass: stopped early, or checked nothing
  • A test runs → Pass: all answers, all right
  • A test runs → Fail: a mismatch
  • A test runs → Hang: no answer
  • Pass → False pass: looks the same

The four endings of a run. A test must be able to tell the top two apart.

Before You Start

Read The Simplest Test That Can Fail first. It showed that a test that cannot fail is worse than none. Where the Right Answer Comes From warned that a scoreboard must be empty at the end.

Five questions this page answers
Question
1What are the four ways a run can end?
2What must be true before a test may print PASS?
3What is a time limit for?
4Why does a test that checks every answer still pass on a silent design?
5What does the end of a test look at that the middle does not?

The Idea: The End Is a Check Too

Most of a test is about answers that arrive: each one is compared, and a wrong one is counted. But some bugs produce no answer at all. A design that stops responding, drops a request, or locks up gives the checks nothing to compare. No comparison, no mismatch, no error.

So the end of a test needs its own checks. Did every expected answer arrive? Is anything still waiting in the scoreboard? Did the run end because the work was done, or because time ran out?

There is a second danger: waiting for ever. If the test waits for an answer that never comes, the run hangs. A time limit stops it and turns the hang into a failure with a clear reason. Nobody has to kill the job by hand.

New Words

New words on this page
WordMeaning
End-of-test conditionWhat must be true for a test to finish: all stimulus sent and all expected answers received.
HangA run that never finishes, usually because it waits for something that never happens.
TimeoutA limit on waiting. When it runs out, the test stops and reports a failure.
False passA run that reports PASS although the design was wrong or was never really checked.
DrainWaiting, after the last stimulus, for answers still inside the design to come out.

Four Endings, Decided by Hand

A test sends three requests to a design that should answer each one. Apply the end checks to four runs by hand.

Deciding how each run ended
What happenedAnswers arrivedWrong answersHonest verdict
Three right answers3 of 30pass
The second answer is wrong3 of 31fail
No answer ever comes; the test waits0 of 30hang, stopped by the timeout: fail
Two answers come, then nothing2 of 30timeout: fail (2 of 3)

Look at the "wrong answers" column. Three of the four runs have zero. A test that looks only at that column passes three runs, two of them falsely. The "answers arrived" column is what tells them apart.

The Rules

  1. Rule 1: PASS needs every expected answer to arrive and be right.

    Zero errors alone is not enough: a silent design has zero errors.

  2. Rule 2: Every wait has a time limit.

    A timeout turns a hang into a failure with a reason.

  3. Rule 3: A timeout is a failure, never a pass.

    It means the work did not finish, whatever the error count says.

  4. Rule 4: Drain, then sweep.

    After the last stimulus, wait for answers in flight; then report anything still expected and never received.

Sources for These Rules

Spear and Tumbush (2012), section 1.12: the run phase waits for the test to complete. It uses time-out checkers so the DUT or bench cannot lock up. The wrap-up phase sweeps the final transactions out, then reports. Lost data can sit in the scoreboard.

The Lab: A Design That Never Answered

The lab's design is doubler: it answers each request with twice its data, three clocks later. A second copy is built to never answer. Two tests watch the same run of each design: a naive one and an honest one.

The watcher, simplified from the lab: each clock, check an answer if one arrived; give up after 20 quiet clocks.
while (quiet < 20) begin
  @(negedge clk);
  if (ack) begin got++; quiet = 0; if (q !== want.pop_front()) errors++; end
  else quiet++;
end

Every arriving answer is compared with the expected one, which waits in a queue. quiet counts clocks with no answer; 20 quiet clocks end the wait. The naive test then looks only at errors. The honest test also looks at got, the number of answers that arrived.

Printed by the lab (Icarus).
a design that answers: naive test says PASS
a design that answers: honest test says PASS
a design that never answers: naive test says PASS
a design that never answers: honest test says FAIL (timeout: 0 of 3 answers)

On the working design both tests say PASS, and both are right. On the silent design the naive test still says PASS: zero answers, zero errors. That is a false pass, and rule 1 is what it broke. The honest test says FAIL with a reason: a timeout, with 0 of 3 answers.

Notice that the naive test made no wrong comparison. Every check it ran was correct. The bug was in deciding when it was finished, and what finished had to mean.

Why the Work Decides the End

Why not give every test a long fixed wait, then report? Because a fixed wait is wrong both ways. Too short, and it cuts off a slow but correct design. Too long, and every test wastes time after its work is done. Neither one counts missing answers.

A better end is driven by the work. Finish when every expected answer has arrived, after a short drain for stragglers. Keep a time limit only for the case where the work never finishes. Measure that limit from the last sign of progress, so a long but busy test is not cut off.

Traps

The first trap is the false pass in the lab: errors counted, arrivals not. It hides every bug that makes a design go quiet, which includes many of the worst ones.

The second trap is a timeout reported as a warning, or as a pass because no error was seen. A run that ran out of time did not finish its work. It is a failure, and its reason should say "timeout" so nobody mistakes it for a wrong answer.

The third trap is ending at the last stimulus. Answers are still inside the design, three clocks behind. A test that stops when it sends its last request never checks the last answers.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. Big benches have many parts, each with work in flight.

  1. Everyone agrees to stop

    Each part of the bench says when it is busy; the run ends only when all of them are done. UVM calls this raising and dropping objections.

  2. Watchdogs everywhere

    Large benches put a progress watchdog on each interface, so a hang is named where it happens.

Where This Goes Next

This lesson ended a test honestly. These lessons teach the tools for it.

Where each idea is taught in depth
The idea from this pageWhere it is taught
Running many tests every night, and sorting what failedRegressions, Seeds and the Life of a Bug
Waiting for a response with a boundA Bounded Response Wait
Running a watcher and a stimulus side by sideFork, Join and Cancellation
Ending a UVM test: objectionsObjections and Premature Completion
What the end of a run means for an assertionWeak and Strong: What the End of a Test Means
Ending a chip-level test honestlyEnding a Test Honestly

Try It

Run the lab. Compare the two verdicts for the silent design.

Build a design that answers only twice (MODE 2). Predict the honest verdict before you run it.

Lower the quiet limit to 2 clocks. What happens to the working design, and why?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: a design that answers: naive test says PASS a design that answers: honest test says PASS a design that never answers: naive test says PASS a design that never answers: honest test says FAIL (timeout: 0 of 3 answers)

Check Yourself

Predict the outputA new design answers the first two requests and then goes silent. What is the last line printed?
module doubler #(parameter int MODE = 0) (input logic clk, req, input logic [7:0] d,
                                     output logic ack, output logic [7:0] q);
  logic [7:0] pipe [0:2]; logic v [0:2]; int answered = 0;
  always_ff @(posedge clk) begin
    v[0] <= req; pipe[0] <= d * 2;
    v[1] <= v[0]; pipe[1] <= pipe[0];
    v[2] <= v[1]; pipe[2] <= pipe[1];
    if (v[2]) answered <= answered + 1;
  end
  assign ack = v[2] && (MODE == 0 || (MODE == 2 && answered < 2));
  assign q = pipe[2];
endmodule

module tb;
  logic clk = 0;
  always #1 clk = ~clk;
  logic req0 = 0, ack0; logic [7:0] d0 = 0, q0;
  doubler #(.MODE(2)) dut0 (.clk, .req(req0), .d(d0), .ack(ack0), .q(q0));
  // The naive test: send three requests, check every answer that arrives, wait a while, report.
  // The honest test watches the same run, but also counts the answers and gives up after 20 quiet cycles.
  task automatic run(input int k, input string name);
    int errors, got, quiet;
    logic [7:0] want [$];
    errors = 0; got = 0; quiet = 0;
    fork
      for (int i = 1; i <= 3; i++) begin
        @(negedge clk); set(k, 1, 8'(10 * i)); want.push_back(8'(20 * i));
        @(negedge clk); set(k, 0, 0);
      end
      while (quiet < 20) begin
        @(negedge clk);
        if (ack_of(k)) begin got++; quiet = 0; if (q_of(k) !== want.pop_front()) errors++; end
        else quiet++;
      end
    join
    if (errors == 0) $display("%s: naive test says PASS", name);
    else $display("%s: naive test says FAIL", name);
    if (errors) $display("%s: honest test says FAIL (wrong answer)", name);
    else if (got < 3) $display("%s: honest test says FAIL (timeout: %0d of 3 answers)", name, got);
    else $display("%s: honest test says PASS", name);
  endtask
  task automatic set(input int k, input logic r, input logic [7:0] d);
    if (k == 0) begin req0 = r; d0 = d; end
  endtask
  function automatic logic ack_of(input int k);
    case (k) 0: return ack0; default: return 0; endcase
  endfunction
  function automatic logic [7:0] q_of(input int k);
    case (k) 0: return q0; default: return 0; endcase
  endfunction
  initial begin
    run(0, "a design that answers twice");
    $finish;
  end
endmodule
ConceptWhat must be true before a test may print PASS?
ConceptWhat is a timeout for?
ConceptIn the lab, why did the naive test pass on the silent design?
ConceptA run ends because its time limit ran out, with zero errors. What is its verdict?

Common Mistakes

Wrong Print PASS when the error count is zero.

A design that never answers has zero errors.

Fix Print PASS only when every expected answer arrived and all were right.

Wrong Wait a fixed time, then report.

Too short cuts off correct answers; too long wastes time; neither counts missing answers.

Fix End when the work is done, after a drain, with a timeout from the last progress.

Wrong Treat a timeout as a warning.

The work did not finish, so nothing about it was shown.

Fix Report a timeout as a failure, with its reason.

Remember

  • A run ends in a pass, a fail, a hang or a false pass, and a false pass looks like a pass.
  • PASS needs every expected answer to arrive and be right; zero errors is not enough.
  • Every wait needs a time limit, and a timeout is always a failure.
  • End when the work is done: drain the answers in flight, then report what never arrived.

Practice

Report a problem with this page