Regressions, Seeds and the Life of a Bug

Run many tests with many seeds, and sort the failures into buckets. Report each bug so someone can fix it, and close it with a test that stays.

You Will Be Able To

  • Say what a regression is and why it runs every night with new seeds.
  • Sort failures into buckets by their first error, and find the condition they share.
  • Write a bug report that someone else can replay: seed, tool, version and the shortest failing run.
  • Close a bug with a test that stays in the regression.
Lesson
B4.3
Time
22 min
Runs on
Your browser
Check
5 questions

Eight seeds ran overnight, and three failed. Seed 303 lost byte 1, seed 606 and seed 909 lost byte 2, each with different values. It looks like three bugs, and it is one.

A Nightly Run with Forty Failures Falling into Four BucketsStep through. A regression runs every test with many seeds overnight. In the morning the failures are sorted by their first error message, and each bucket usually turns out to be one bug.
  • Engine
  • Result
  • Storage
  • Control / FSM
  • Data
A Nightly Run With Forty Failures Falling Into Four BucketsStep through. A regression runs every test with many seeds overnight. In the morning the failures are sorted by their first error message, and each bucket usually turns out to be one bug. engine Nightlyregression every test, manyseeds result Forty failures forty logs, fortyseeds storage Bucket 1 frame error after abyte storage Bucket 2 timeout waiting forbusy storage Buckets 3 and 4 other first errors control One bug reportper bucket shortest seed, tool,version morningsorted by first errorsorted by first errorsorted by first errorone report
  1. engine Nightly regressionevery test, many seeds
    • morning → Forty failures
  2. result Forty failuresforty logs, forty seeds
    • sorted by first error → Bucket 1
    • sorted by first error → Bucket 2
    • sorted by first error → Buckets 3 and 4
  3. storage Bucket 1frame error after a byte
    • one report → One bug report per bucket
  4. storage Bucket 2timeout waiting for busy
  5. storage Buckets 3 and 4other first errors
  6. control One bug report per bucketshortest seed, tool, version
  1. Run everything

    Overnight, every test runs with many seeds. Most pass.

  2. Collect the failures

    Forty runs fail. Forty failures are rarely forty bugs.

  3. Sort them

    Group failures by their first error message, not by test name.

  4. Report one bug per bucket

    Pick the shortest failing run of each bucket and report it with its seed.

Read the diagram as text
  • Nightly regression: every test, many seeds
  • Forty failures: forty logs, forty seeds
  • Bucket 1: frame error after a byte
  • Bucket 2: timeout waiting for busy
  • Buckets 3 and 4: other first errors
  • One bug report per bucket: shortest seed, tool, version
  • Nightly regression → Forty failures: morning
  • Forty failures → Bucket 1: sorted by first error
  • Forty failures → Bucket 2: sorted by first error
  • Forty failures → Buckets 3 and 4: sorted by first error
  • Bucket 1 → One bug report per bucket: one report

An idea drawing; the forty failures are an example, not a measured number. The lab below sorts three real failures.

Before You Start

Read Random and Constrained-Random Stimulus and The Verification Plan first. The transmitter and its plan come from The Verification Plan.

Five questions this page answers
Question
1What is a regression, and why does it run again and again?
2Why do forty failures rarely mean forty bugs?
3How do you find the condition that failing seeds share?
4What goes into a bug report?
5How is a bug closed so it cannot come back?

The Idea: Run Everything, Again and Again

A design changes every day. Each change can break something that worked yesterday. So a project keeps a regression: every test of the plan, run again after every change, usually overnight. A test that passed yesterday and fails today points at today's change.

Random tests make the regression grow in a second direction. Each night they run with new seeds, so the same test explores new paths. A failure on night forty may come from a path that existed since day one. Neither direction is wasted. Old seeds guard against breakage; new seeds hunt for what nobody has seen.

Then comes the morning. Failures need sorting before anyone debugs anything, because one bug can fail many runs in many different-looking ways. This sorting is called triage. After triage, each bug lives a short life: reported, fixed, checked, and closed with a test that stays.

New Words

New words on this page
WordMeaning
RegressionThe full set of tests, run again after changes to catch anything that broke.
TriageSorting failures into groups that share one cause, before debugging any of them.
SignatureWhat a failure looks like: its first error message, and the condition that led to it.
BucketA group of failures with the same signature, usually one bug.
Bug reportA note that lets someone else see the bug: what failed, the seed, the tool and its version, the shortest run.
Regression testA test added when a bug is fixed, kept forever so the bug cannot return unseen.

The Smallest Example: Sort Three Failures by Hand

Each seed of the lab sends five random bytes, with a random gap of 0 to 9 idle clocks before each one. Here are the three failures and the gaps their seeds drew.

Three failing seeds, side by side
SeedFirst bad byteGaps before bytes 0 to 4
303byte 15 0 9 3 8
606byte 20 4 0 2 8
909byte 26 7 0 2 8

The bytes differ and the positions differ. Look for what they share. In every case, the bad byte had a gap of 0 before it: it was sent straight after the previous byte finished. Seed 606 also drew a 0 before byte 0, but byte 0 has no byte before it.

The Rules

  1. Rule 1: Run the regression after every change.

    A test that passed yesterday and fails today points at today's change.

  2. Rule 2: New seeds every night.

    Old seeds guard against breakage; new seeds explore new paths.

  3. Rule 3: Triage before debugging.

    Sort failures by their first error and the condition behind it. One bucket is usually one bug.

  4. Rule 4: Report so it can be replayed.

    Seed, test, tool and version, and the shortest failing run. A bug that cannot be replayed cannot be fixed.

  5. Rule 5: Close with a test that stays.

    Add the failing case to the regression, with its seed, so the bug can never return unseen.

Sources for These Rules

Simulation regressions, and faster platforms when they are too slow: Mehta, section 2.2, item 11.

Many runs with different seeds, holes and minimal changes: Spear and Tumbush, section 1.6.

Verification through the product life cycle, from the test plan to functional and gate-level runs: Mehta, section 15.5.

The Lab: Eight Seeds, Three Failures, One Bug

The lab runs the transmitter with a planted bug under eight seeds. Each run sends five random bytes with random gaps and compares what a receiver model collected. The heart of one run.

wait_until_free() and send() stand for the bench's small tasks. The gap and the byte both come from the seed.
seed = s; r = $urandom(seed);              // this run's own sequence
for (int k = 0; k < 5; k++) begin
  g = $urandom_range(9, 0);                 // idle clocks before this byte
  d = $urandom;                             // the byte
  wait_until_free();  repeat (g) @(negedge clk);
  send(d);
end
Printed by the lab (Icarus Verilog version 12.0).
seed 101: PASS, 5 bytes
seed 202: PASS, 5 bytes
seed 303: FAIL, byte 1: got 3b, want 6f, 4 frame error(s)
seed 404: PASS, 5 bytes
seed 505: PASS, 5 bytes
seed 606: FAIL, byte 2: got 56, want 59, 2 frame error(s)
seed 707: PASS, 5 bytes
seed 909: FAIL, byte 2: got b4, want a2, 2 frame error(s)

Three failures with three different messages. Rule 3 says: do not debug yet. Put the gaps beside them, as the table above did, and one condition stands out. Every first bad byte came straight after another byte.

That points at the end of a frame. In this transmitter, busy falls one bit too early, as the stop bit begins. With an idle gap after it, the line stays high and the short stop bit looks normal. With no gap, the next start bit cuts it short, and the receiver sees a frame error. Seeds 404 and 505 drew gaps of 1, which was just enough.

Fix the one line, and rule 5 adds a test: the back-to-back case, with seed 606, stays in the regression. After the fix: seed 909: PASS, 5 bytes, and all eight seeds pass.

Why Sort First and Keep the Test

Why sort failures before debugging them? Because debugging is the slowest work in verification. Three engineers debugging three messages from one bug waste two-thirds of their day. Ten minutes of sorting saves hours.

Why keep the failing seed as a test forever? Because the same mistake is easy to make again. A later change to the stop-bit logic would break the back-to-back case silently, unless a test is waiting for exactly that.

Traps

The first trap is debugging the first failure in the list. It may be the longest, messiest run of the bucket. Pick the shortest failing run of each bucket; it has the least noise between the cause and the error.

The second trap is a bug report nobody can replay. "The UART test failed last night" is not a report. The seed, the test name, the tool and its version, and the first error line are. Without them, the bug waits until chance brings it back.

The third trap is closing a bug without a test. The fix goes in, the failing seed passes, and nothing stays to guard it. Six months later a clean-up changes the same line, and the bug returns with nobody watching.

Where This Goes Next

Regressions and triage are daily work on every project. These pages go further.

Where each idea is taught in depth
The idea from this pageWhere it is taught
Following one failure back to its causeDebugging: From a Failure to a Cause
Seeds and directed closure in a UVM regressionSeeds, Coverage and Directed Closure
Reports that support a verdictReports That Support a Verdict
Reproducible stress on a FIFOReset, Wrap and Reproducible Stress
Ending a chip test honestly, and sorting by reasonEnding a Test Honestly

Try It

Run it: eight seeds of five random bytes each, on a transmitter with a planted bug.

In uart_tx, change bits == 2 back to bits == 1. Predict the line for seed 909.

Add seed 1212 to the list. Does it fail, and does the gap before its first bad byte fit the bucket?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: seed 101: PASS, 5 bytes seed 202: PASS, 5 bytes seed 303: FAIL, byte 1: got 3b, want 6f, 4 frame error(s) seed 404: PASS, 5 bytes seed 505: PASS, 5 bytes seed 606: FAIL, byte 2: got 56, want 59, 2 frame error(s) seed 707: PASS, 5 bytes seed 909: FAIL, byte 2: got b4, want a2, 2 frame error(s)

Check Yourself

Predict the outputThe stop bit is fixed: busy now falls at the end of the stop bit. What does the last line, for seed 909, print?
// uart_tx: sends one byte as a frame: a start bit (0), eight data bits low bit first, a stop bit (1).
// Each bit lasts CPB clocks. start is taken only while busy is 0; data is read in the same clock.
module uart_tx #(parameter int CPB = 4) (input logic clk, rst, start, input logic [7:0] data,
                                          output logic tx, busy);
  logic [9:0] frame;                // the bits still to send, low bit first
  logic [3:0] bits;                 // how many bits are left
  logic [7:0] ticks;                // clocks spent in this bit
  assign tx = busy ? frame[0] : 1'b1;
  always_ff @(posedge clk)
    if (rst) begin busy <= 0; bits <= 0; ticks <= 0; frame <= '1; end
    else if (!busy) begin
      if (start) begin frame <= {1'b1, data, 1'b0}; bits <= 10; ticks <= 0; busy <= 1; end
    end else begin
      if (ticks == CPB - 1) begin
        ticks <= 0;
        frame <= {1'b1, frame[9:1]};
        bits <= bits - 1;
        if (bits == 1) busy <= 0;
      end else ticks <= ticks + 1;
    end
endmodule

module tb;
  logic clk = 0, rst = 1, start = 0, tx, busy;
  logic [7:0] data = 0;
  uart_tx #(.CPB(4)) dut (.clk(clk), .rst(rst), .start(start), .data(data), .tx(tx), .busy(busy));
  always #5 clk = ~clk;
  // The far end of the wire: wait for a falling edge, then sample each bit in its middle.
  logic [7:0] got [$];              // bytes received, in order
  int frame_errors = 0;
  initial forever begin
    logic [7:0] byte_in;
    @(negedge tx);
    repeat (2) @(posedge clk);      // the middle of the start bit
    if (tx === 1'b0) begin
      for (int i = 0; i < 8; i++) begin repeat (4) @(posedge clk); byte_in[i] = tx; end
      repeat (4) @(posedge clk);    // the middle of the stop bit
      if (tx !== 1'b1) frame_errors++;
      got.push_back(byte_in);
    end
  end
  logic [7:0] sent [$];
  int gaps [$];
  int seed;
  int unsigned r;
  task automatic run(input int s);
    int first_bad = -1;
    int unsigned g;
    logic [7:0] d;
    seed = s; r = $urandom(seed);
    sent.delete(); gaps.delete(); got.delete(); frame_errors = 0;
    rst = 1; @(negedge clk) rst = 0;
    for (int k = 0; k < 5; k++) begin
      g = $urandom_range(9, 0);
      d = $urandom;
      gaps.push_back(g);
      sent.push_back(d);
      @(negedge clk); while (busy) @(negedge clk);
      repeat (gaps[k]) @(negedge clk);
      data = sent[k]; start = 1;
      @(negedge clk) start = 0;
    end
    @(negedge clk); while (busy) @(negedge clk);
    repeat (48) @(negedge clk);
    for (int k = 0; k < 5 && first_bad < 0; k++) if (k >= got.size() || got[k] !== sent[k]) first_bad = k;
    if (first_bad < 0 && frame_errors == 0) $display("seed %0d: PASS, 5 bytes", s);
    else if (first_bad < 0) $display("seed %0d: FAIL, %0d frame error(s), bytes right", s, frame_errors);
    else $display("seed %0d: FAIL, byte %0d: got %h, want %h, %0d frame error(s)", s, first_bad,
                  first_bad < got.size() ? got[first_bad] : 8'h00, sent[first_bad], frame_errors);
  endtask
  initial begin
    run(101);
    run(202);
    run(303);
    run(404);
    run(505);
    run(606);
    run(707);
    run(909);
    $finish;
  end
endmodule
ConceptWhy does a regression run with new seeds every night?
ConceptThree seeds fail with three different messages. What comes first?
ConceptWhat must a bug report contain so that someone else can see the bug?
ConceptIn the lab, why did seeds 404 and 505 pass, although each drew a gap of 1?

Common Mistakes

Wrong Debug every failure separately, as soon as it appears.

One bug often fails many runs in different-looking ways.

Fix Sort failures into buckets first, and debug one per bucket.

Wrong Report a failure without its seed and tool version.

Nobody else can make it happen again.

Fix Report the seed, test, tool, version and the first error.

Wrong Close a bug once the failing seed passes.

Nothing guards against the same mistake later.

Fix Keep the failing case in the regression for good.

Remember

  • A regression runs every test again after each change; random tests also get new seeds every night.
  • Triage sorts failures by first error and shared condition; one bucket is usually one bug.
  • A bug report gives the seed, test, tool, version and first error, with the shortest failing run.
  • A bug is closed with a test that stays in the regression.

Practice

Report a problem with this page