Ending a Test Honestly

A firmware test that writes 0x900D has not necessarily passed. Learn the five ways soc_tb ends a run, in order of authority, and the false pass each rule stops. The bench's own gate shows each one.

You Will Be Able To

  • List the five ways a soc_tb run ends, in order of authority.
  • Name the false pass each rule prevents.
  • Explain why the first status word is the end of a test.
  • Tell a hang from a legal sleep, and say what the no-progress limit counts.
Lesson
V3.7
Time
26 min
Runs on
Your browser
Check
5 questions

Picture a log that says PASS in green. The firmware wrote 0x900D and the console is tidy. Two screens up sits a bus checker's line: a rule broken early in the run. The test passed on a broken chip, because nobody decided who has the last word.

Five Ways a Test Ends, in Order of AuthorityAt every cycle the bench asks these questions in order. The first that answers yes ends the run; a pass is only what is left when none of the others did.
  • Test
  • Control / FSM
  • Clock / reset
  • Result
  • Control
Five Ways a Test Ends, in Order of AuthorityAt every cycle the bench asks these questions in order. The first that answers yes ends the run; a pass is only what is left when none of the others did. test 1. A checkererror a bus rule, a monitor,the model, a benchcheck control 2. A fail word the first status wordthat counts clock reset 3. The cycle limit +max, 400,000 bydefault clock reset 4. No progress nothing retired ortransferred result 5. A pass word and main entered,zero errors elseelseelseelse
  1. test 1. A checker errora bus rule, a monitor, the model, a bench check
    • else → 2. A fail word
  2. control 2. A fail wordthe first status word that counts
    • else → 3. The cycle limit
  3. clock reset 3. The cycle limit+max, 400,000 by default
    • else → 4. No progress
  4. clock reset 4. No progressnothing retired or transferred
    • else → 5. A pass word
  5. result 5. A pass wordand main entered, zero errors
  1. The bench speaks first

    A checker error ends the run whatever the firmware says.

  2. Then the test

    The first fail word ends it; nothing after it counts.

  3. Then the limits

    A run that never ends, or stops moving, is ended and called a fail.

  4. Only then a pass

    A pass word with main entered, no errors and, with the core, at least one compared record.

Read the diagram as text
  • 1. A checker error: a bus rule, a monitor, the model, a bench check
  • 2. A fail word: the first status word that counts
  • 3. The cycle limit: +max, 400,000 by default
  • 4. No progress: nothing retired or transferred
  • 5. A pass word: and main entered, zero errors
  • 1. A checker error → 2. A fail word: else
  • 2. A fail word → 3. The cycle limit: else
  • 3. The cycle limit → 4. No progress: else
  • 4. No progress → 5. A pass word: else

The order of soc_tb (README, "The end of a test"; plan §3.5).

Before You Start

Read Passive Checkers: Bind and Listen and The First Run first.

Five questions this page answers
Question
1In what order does soc_tb decide how a run ended?
2Why does a checker error outrank a pass word?
3Why is the first status word the end?
4How does the bench tell a hang from a sleep?
5What must be true besides the pass word for a pass?

The Idea: The Bench Keeps the Last Word

Self-checking firmware is convenient: it writes a pass word when its checks hold. But firmware sees only what it reads back. A bus rule broken on the way, a byte that never reached the pad, a run that never ended. None of these reaches the firmware's checks.

So the bench keeps the last word. It asks a fixed list of questions in a fixed order, and the pass word is only the last of them. Each question stops one way a test can pass falsely. One of them was learned the hard way. Until the bench's own gate tested it, a fail word followed by a pass word counted as a pass.

New Words

New words on this page
WordMeaning
Pass wordTB_STATUS = 0x900D, written by the test to say it passed.
Fail wordTB_STATUS = 0xBAD0_0000 plus a code, written by the test to say it failed.
False passA run reported as a pass while the chip or the test did something wrong.
Cycle limitThe most cycles a run may take (+max); a budget, not a measurement of the chip.
No-progress limitThe most cycles with nothing retired (with the processor) or nothing transferred (with the seat).
Order of authorityThe order in which the bench's end rules are asked; the first that applies decides.
ObjectionUVM's way of ending a phase: components raise objections while they work and drop them when done.

The Smallest Example: Decide Three Runs by Hand

Apply the order to three runs. Ask the five questions top to bottom and stop at the first yes.

Three runs, decided by the order
What happenedFirst yesVerdict
A bus rule broke; later the firmware wrote 0x900D1: a checker errorfail (checker)
The firmware wrote 0xBAD0_0007, then 0x900D2: the first status word was a fail wordfail (status_fail)
The firmware wrote 0x900D but never TB_STATUS = 2none of 1 to 4; the pass lacks main enteredfail (pass_without_main)

The Rules

  1. Rule 1: A checker error ends the run, whatever the test says.

    A broken bus rule, a block monitor, a model mismatch, a failed bench check. It stops "the firmware passed, but the chip broke a rule".

  2. Rule 2: The first status word is the end.

    A fail word ends the test; a pass word written after it changes nothing. It stops "fail, carry on, pass".

  3. Rule 3: The cycle limit ends a run that does not end.

    It stops a hung test from passing by timeout in a script that only greps for errors.

  4. Rule 4: No progress ends a run that stopped moving.

    Nothing retired for +noretire cycles is a hang, unless the core sleeps in wfi with an interrupt enabled. It finds a hang long before the cycle limit.

  5. Rule 5: A pass needs more than the pass word.

    Main entered, zero checker errors, zero mismatches, and with the core at least one compared record. It stops "a pass word from code that never ran the test".

Sources for These Rules

The order, each rule and the result reasons: tools/soc/ap_soc/bench/soc_tb/README.md, "The end of a test"; soc_tb.sv; plan §3.5.

The nine cases: check-soc-bench.mjs, step ends (stage E7 of plan §3.10).

UVM ends a run phase when every objection has been dropped: UVM Cookbook, End of Test Mechanisms (UVM-CB). See also IEEE 1800.2-2020 clause 10.5 (uvm_objection).

The Lab: Nine Runs That Would Pass Falsely

The loop that ends a run (soc_tb.sv). It asks rules 1, 2 (done), 3 and 4 at every rising edge of clk_sys.
    while (!stop) begin
      @(posedge clk_sys);
      if (checker_errors != 0) begin stop = 1'b1; end_reason = "checker"; end
      else if (done) stop = 1'b1;
      else if ((cycles >= max_cycles) || (ticks >= max_cycles)) begin stop = 1'b1; end_reason = "cycle_limit"; end
      else if (idle >= no_retire) begin stop = 1'b1; end_reason = "no_progress"; end
    end

Each of the nine cases is a run that would have passed if its rule were missing. They ran again on the site's pre-built chip bench for this lesson.

Rule 1: a checker error outranks the pass word.
checker_bus      verdict=fail reason=checker status=0000900d cycles=19
checker_bench    verdict=fail reason=checker status=0000900d cycles=71
table_left       verdict=fail reason=checker status=0000900d cycles=325
What the bench said in each.
checker_bus: RULE align broken at edge 28: a 4-byte transfer at 0x40000002 is not aligned to its size
checker_bench: BENCH 63: row 0: no byte came on the UART pad, expected 41
table_left: BENCH 317: table: the test ended at row 0 of 2

In checker_bus the bus-manager seat made a word transfer at an address that is not a multiple of 4. Every answer was the expected one, so the table alone would have written 0x900D. The AHB checker ended the run at cycle 19. In checker_bench and table_left the firmware passed, but the bench's own side had not finished: a byte never came, rows never ran.

Rules 2 and 3.
fail_then_pass   verdict=fail reason=status_fail status=bad00007 cycles=25
cycle_limit      verdict=fail reason=cycle_limit status=00000002 cycles=2008
cycle_limit_off  verdict=pass reason=pass status=0000900d cycles=6024

fail_then_pass wrote 0xBAD0_0007 and then 0x900D; the status that counts is bad00007. cycle_limit is a slow program with +max=2000: it stopped at 2008 cycles with only "main entered" written. The same program passed with the default limit, at 6024 cycles. The limit measured the budget, not the chip.

Rules 4 and 5.
no_progress      verdict=fail reason=no_progress status=00000002 cycles=3027
wfi_armed        verdict=pass reason=pass status=0000900d cycles=5053
no_main          verdict=fail reason=pass_without_main status=0000900d cycles=21

no_progress sleeps in wfi with no interrupt enabled: found at 3027 cycles of a 200,000 limit. wfi_armed sleeps for 5,000 cycles with the timer armed, longer than the no-progress limit of 3,000. It passes, because the bench counts an armed sleep as waiting. no_main writes 0x900D and nothing else, and the bench calls it pass_without_main.

Why It Is Built This Way

Why put the checkers above the test? Because the test is the thing under suspicion. A checker has no stake in passing. A test that breaks a bus rule but writes 0x900D anyway is the case the bench exists to catch.

UVM solves the same problem differently: a run ends when every component has dropped its objection, and the report server counts errors. soc_tb's UVM front end keeps both. A UVM test writes the pass word only when UVM counted no error, and the bench's order still decides.

Traps

The first trap is a test that keeps going after a failure. A helper writes the fail word on a bad value and returns. The test runs on to print "done" and write 0x900D. The console looks perfect. The bench reports the first word, so read the status, not the console.

The second trap is a limit set too tight. Raise the clock divider in a test and its UART bytes take twice as long. The run now ends at its cycle limit. Read the reason before the verdict: cycle_limit says "the budget ran out", not "the chip is wrong".

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. One soc_tb run gives one result block.

  1. Regression triage

    Thousands of runs a night are sorted by reason first: checker, status_fail, limits. Each reason has an owner.

  2. Watchdogs everywhere

    Large benches add a watchdog per bus and per protocol model. A hang is then named at its place, long before the run limit.

  3. Signed results

    Farms check that the result block belongs to this run; soc_tb repeats the run's own word for it. So no test can print a fake pass.

Try It

Run it: the order of authority applied to what happened in each of the nine cases, against the reason the bench gave.

Swap rules 1 and 2 in decide. Which case changes, and what false result would it give?

Change no_main's facts so main is entered. What does the rule now say?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: checker_bus rule: checker, bench: checker checker_bench rule: checker, bench: checker table_left rule: checker, bench: checker fail_then_pass rule: status_fail, bench: status_fail cycle_limit rule: cycle_limit, bench: cycle_limit cycle_limit_off rule: pass, bench: pass no_progress rule: no_progress, bench: no_progress wfi_armed rule: pass, bench: pass no_main rule: pass_without_main, bench: pass_without_main 9 of 9 agree with the bench

Check Yourself

Predict the outputThe slice decides all nine cases by the order of authority. What is the last line it prints?
// What happened in each run, and the reason the bench gave (recorded on ap_soc v1.5).
module tb;
  task automatic decide(input bit broke, input int word, input bit limit, input bit stalled, input bit main_entered, output string reason);
    if (broke) reason = "checker";                            // 1: a checker error outranks everything
    else if (word == 2) reason = "status_fail";               // 2: the first status word was a fail word
    else if (limit) reason = "cycle_limit";                   // 3: the cycle limit
    else if (stalled) reason = "no_progress";                 // 4: the no-progress limit
    else if (word == 1 && !main_entered) reason = "pass_without_main";
    else if (word == 1) reason = "pass";                      // 5: a pass word, with main entered
    else reason = "none";
  endtask
  int agree = 0;
  string got;
  initial begin
    decide(1, 1, 0, 0, 1, got);
    $display("checker_bus      rule: %s, bench: %s", got, "checker");
    if (got == "checker") agree++;
    decide(1, 1, 0, 0, 1, got);
    $display("checker_bench    rule: %s, bench: %s", got, "checker");
    if (got == "checker") agree++;
    decide(1, 1, 0, 0, 1, got);
    $display("table_left       rule: %s, bench: %s", got, "checker");
    if (got == "checker") agree++;
    decide(0, 2, 0, 0, 1, got);
    $display("fail_then_pass   rule: %s, bench: %s", got, "status_fail");
    if (got == "status_fail") agree++;
    decide(0, 0, 1, 0, 1, got);
    $display("cycle_limit      rule: %s, bench: %s", got, "cycle_limit");
    if (got == "cycle_limit") agree++;
    decide(0, 1, 0, 0, 1, got);
    $display("cycle_limit_off  rule: %s, bench: %s", got, "pass");
    if (got == "pass") agree++;
    decide(0, 0, 0, 1, 1, got);
    $display("no_progress      rule: %s, bench: %s", got, "no_progress");
    if (got == "no_progress") agree++;
    decide(0, 1, 0, 0, 1, got);
    $display("wfi_armed        rule: %s, bench: %s", got, "pass");
    if (got == "pass") agree++;
    decide(0, 1, 0, 0, 0, got);
    $display("no_main          rule: %s, bench: %s", got, "pass_without_main");
    if (got == "pass_without_main") agree++;
    $display("%0d of 9 agree with the bench", agree);
  end
endmodule
ConceptFirmware writes 0xBAD0_0003, then 0x900D. What does soc_tb report?
ConceptA core sleeps in wfi with no interrupt enabled. Which rule ends the run?
ConceptIn the lab, why did wfi_armed pass although it slept for longer than the no-progress limit?
ConceptWhich false pass does the rule "a pass needs main entered" stop?

Common Mistakes

Wrong Grep the log for PASS.

A pass word can follow a fail word or a broken bus rule.

Fix Read the result block's verdict and reason; the bench decides.

Wrong Treat a cycle-limit failure as a chip bug.

The same program can pass with a larger budget.

Fix Read the reason first; size the limit from the test.

Wrong Let a helper write the fail word and return to the test.

The test runs on, and its later output misleads whoever reads the console.

Fix Write the fail word and stop, or let the start-up code report main's return value.

Remember

  • Order of authority: checker error, fail word, cycle limit, no progress, pass word.
  • Each rule stops one kind of false pass.
  • The first status word is the end; a later pass word does not mend a fail.
  • A pass also needs main entered, zero errors, zero mismatches and, with the core, a compared record.

Practice

Report a problem with this page