Capstone: Verify a Small Design End to End

Put the whole track together on one small design: a plan, a self-checking bench, two checks, hit counts and a sign-off. Then do it yourself for a FIFO with hidden bugs.

You Will Be Able To

  • Write plan rows for a small design, each with stimulus, check and coverage.
  • Build a self-checking bench with directed and random stimulus.
  • Use two checks of different kinds, and hit counts for the plan's situations.
  • Sign off against the plan, and say plainly when the answer is "not yet".
Lesson
B4.6
Time
30 min
Runs on
Your browser
Check
5 questions

The directed tests passed, every one. Then two hundred random cycles ran, and the first check reported 44 errors. Each one was a cycle where up and down arrived together, the one row of the plan that only random stimulus reached.

The Plan, the Bench, the Results and the Coverage Side by SideStep through. One small design is verified end to end. Plan rows lead to a bench and two checks, and then to results and coverage.
  • Design
  • Step
  • Driver
  • Test
  • Result
  • Control / FSM
  • Data
The Plan, the Bench, the Results and the Coverage Side by SideStep through. One small design is verified end to end. Plan rows lead to a bench and two checks, and then to results and coverage. design Specification sat_counter: up,down, stop at 0 and15, both = hold step Plan rows P1 to P5 driver Bench directed and randomstimulus test Two checks the model's value;never a jump of 2 result Hit counts top, bottom, both control Sign-off every row closed,every bin hit read intodriveschecked bycounted byall passno holes
  1. design Specificationsat_counter: up, down, stop at 0 and 15, both = hold
    • read into → Plan rows
  2. step Plan rowsP1 to P5
    • drives → Bench
  3. driver Benchdirected and random stimulus
    • checked by → Two checks
    • counted by → Hit counts
  4. test Two checksthe model's value; never a jump of 2
    • all pass → Sign-off
  5. result Hit countstop, bottom, both
    • no holes → Sign-off
  6. control Sign-offevery row closed, every bin hit
  1. Plan

    Read the specification into rows: what must be shown, how, and how to know it ran.

  2. Bench

    Directed stimulus for the ends; random stimulus for everything else.

  3. Checks

    Two checks look at every cycle: one against a model, one a rule that always holds.

  4. Coverage

    Hit counts show which plan situations the stimulus really reached.

  5. Sign-off

    Done means every check passed and every bin was hit, against the plan.

Read the diagram as text
  • Specification: sat_counter: up, down, stop at 0 and 15, both = hold
  • Plan rows: P1 to P5
  • Bench: directed and random stimulus
  • Two checks: the model's value; never a jump of 2
  • Hit counts: top, bottom, both
  • Sign-off: every row closed, every bin hit
  • Specification → Plan rows: read into
  • Plan rows → Bench: drives
  • Bench → Two checks: checked by
  • Bench → Hit counts: counted by
  • Two checks → Sign-off: all pass
  • Hit counts → Sign-off: no holes

An idea drawing of the lab below. Your capstone problem does the same for a FIFO.

Before You Start

This capstone uses the whole track. The design is the counter from Code Coverage: What Ran; the method is the plan from The Verification Plan.

Five questions this page answers
Question
1What goes into the plan of a small design?
2Why does the bench need both directed and random stimulus?
3Why two checks, and of what kinds?
4What do the hit counts add to passing checks?
5When is a design signed off, and what does "not yet" mean?

The Idea: One Design, the Whole Method

Each lesson so far took one idea and one tiny design. A real verification task uses them all at once, in a fixed order. First the plan says what must be shown. Then the bench drives the design and checks it. Then the results and the coverage say whether the plan was met.

The order matters. A bench written before the plan tests what was easy to write. A plan with no coverage cannot tell a passing row from one that was never reached. Sign-off is not a feeling at the end. It is a check of every plan row against what the run produced.

The design here is the saturating counter from Code Coverage: What Ran. There, full code coverage missed its bug. Here, the full method finds it, and shows exactly which row did.

New Words

New words on this page
WordMeaning
Self-checking benchA bench that decides pass or fail by itself, with no person reading waves.
End to endFrom the specification to sign-off, every step done on one design.
Hit countThe number of times a plan situation happened during the run: plain functional coverage.
Sign-offThe decision that verification is done, made against the plan.
Saturating counterA counter that stops at its smallest and largest values instead of wrapping round.

The Smallest Example: The Counter's Plan

The specification: count up or down by one; stop at 0 and at 15; up and down together hold the count. Read it into rows.

Five plan rows for sat_counter
RowFeatureStimulusCheckCoverage
P1Counts up by onedirected: 16 ups from 0model value-
P2Stops at 15directed: up past the topmodel value; never a jump of 2top: up while at 15
P3Counts down, stops at 0directed: 16 downsmodel valuebottom: down while at 0
P4Up and down together holdrandom up and downmodel valueboth: up and down together
P5Any mix of movesrandom, 200 cycles, seed 3both checks every cycleall three bins above

Each row has a way to reach it and a way to check it. Where it matters, a count proves it was reached. Row P4 is the one the code coverage lesson missed. Here it has its own bin, so it cannot be skipped quietly.

The Rules

  1. Rule 1: Plan first.

    Write the rows from the specification before the bench. The bench then serves the plan.

  2. Rule 2: Directed for the ends, random for the rest.

    Directed stimulus hits the exact corners; random stimulus reaches what nobody listed.

  3. Rule 3: Two checks of different kinds.

    A model comparison catches wrong values. A rule that must always hold catches what a model shares with the design.

  4. Rule 4: Count the plan's situations.

    A hit count per coverage row shows the stimulus reached it.

  5. Rule 5: Sign off against the plan.

    Done when every check passed and every bin was hit. Otherwise the answer is "not yet", with a reason.

Sources for These Rules

Basic testbench steps, from generating stimulus to measuring progress against the goals: Spear and Tumbush, section 1.3.

The plan and its parts: Mehta, ASIC/SoC Functional Design Verification, section 2.2.

The Lab: The Counter, End to End

The bench drives sat_counter with 16 ups and 16 downs, then 200 random cycles from seed 3. On every cycle it updates a model, runs both checks and updates the hit counts.

Here prev is the count before the edge, and want is the model's count. The bottom count works the same way as the top count.
if (cnt !== want) begin err_value++; want = cnt; end   // check 1: the model
if (cnt > prev + 1 || prev > cnt + 1) err_step++;      // check 2: never a jump of 2
if (u && want == 15 && !d) hit_top++;                  // coverage: up at the top
if (u && d) hit_both++;                                // coverage: up and down together
Printed by the lab (Icarus Verilog version 12.0).
directed: value errors 0, step errors 0
random:   value errors 44, step errors 0
hits: top 8, bottom 1, both 44
sign-off: not yet

Read it top to bottom, as a sign-off review would. The directed part passed. The random part found 44 value errors and no step errors: up won every time up and down arrived together. Rule 3 at work: the step check stayed silent, because the bug never jumps by two. Only the model saw it.

Rule 5 at work: "not yet". The specification says hold; the design says up. Fix the design, run the same bench and seed, and the review reads differently:

The same bench and seed on the fixed counter.
directed: value errors 0, step errors 0
random:   value errors 0, step errors 0
hits: top 1, bottom 4, both 44
sign-off: every check passed and every bin was hit

Every check passed and every bin was hit. The bin counts changed too, because the fixed counter follows a different path through the same random moves. That is why sign-off reads the numbers of the final run, not of an earlier one.

Why Two Checks and Hit Counts

Why two checks if the model already caught the bug? Because a model is written by a person who may misread the specification in the same way as the designer. A rule that must always hold is a second opinion that does not depend on the model. Here that rule is "never a jump of two".

Why count hits when the checks already pass? Because a check can only fail on situations that happen. If the random part had never pressed up and down together, P4 would pass by never being tested. The count is what turns "no errors" into "no errors, and every row was reached".

Traps

The first trap is signing off on checks alone. Zero errors with an empty bin means that situation was never tested. Read the coverage before the word "pass".

The second trap is a bench that follows the design. If the model copies the design's value after every cycle without counting a difference, it can never report one. Count a difference before you resynchronise, as this bench does.

The third trap is a capstone without its hidden bugs. A bench is only as good as the bugs it catches. Your problem checks your bench against a correct FIFO and against several broken ones. Each broken one must make your bench fail.

Your Turn: A FIFO with Hidden Bugs

The two problems of this lesson ask you to do the same for a FIFO four entries deep. First you write its plan rows. Then you write a self-checking bench with directed and random tests, two checks and two hit counts.

Your bench runs against a correct FIFO and against several FIFOs with hidden bugs. It must stay silent on the correct one and fail on every broken one. The corners of Corner Cases and How to Think of Them are a good start, and you may reuse its ideas.

Where This Goes Next

You have walked the whole method once. These tracks turn each step into a craft.

Where each idea is taught in depth
The idea from this pageWhere it is taught
A layered FIFO bench in SystemVerilog, step by stepBuild the Generator and Driver
The complete layered testbenchThe Complete Layered Testbench
The same bench built with UVMFrom a Layered Bench to UVM
A coverage model capstoneCapstone: A Coverage Model That Finds Holes
Signing off with formalThe Sign-Off Argument

Try It

Run it: directed then random stimulus, two checks, three hit counts, and a sign-off line.

Fix sat_counter so up and down together hold the count. Predict the last line.

Remove the random part. Which bin stays at 0, and what does the sign-off line say?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: directed: value errors 0, step errors 0 random: value errors 44, step errors 0 hits: top 8, bottom 1, both 44 sign-off: not yet

Check Yourself

Predict the outputThe counter now holds when up and down arrive together. The bench and seed are the same. What is the last line the lab prints?
// sat_counter: counts up or down, and stops at 0 and at 15.
// up and down together leave the count where it is.
module sat_counter (input logic clk, rst, up, down, output logic [3:0] cnt);
  always_ff @(posedge clk)
    if (rst)                       cnt <= 0;
    else if (up && down)        cnt <= cnt;
    else if (up && cnt != 15)    cnt <= cnt + 1;
    else if (down && cnt != 0)     cnt <= cnt - 1;
endmodule

module tb;
  logic clk = 0, rst = 1, up = 0, down = 0;
  logic [3:0] cnt, prev, want = 0;
  int seed = 3;
  int unsigned r;
  int err_value = 0, err_step = 0;  // check 1: the model's value; check 2: never a jump of more than 1
  int hit_top = 0, hit_bottom = 0, hit_both = 0;
  sat_counter dut (.clk(clk), .rst(rst), .up(up), .down(down), .cnt(cnt));
  always #5 clk = ~clk;
  task automatic cycle_with(input logic u, input logic d);
    @(negedge clk) begin up = u; down = d; prev = cnt; end
    if (u && want == 15 && !d) hit_top++;          // coverage: pushed up at the top
    if (d && want == 0 && !u) hit_bottom++;        // coverage: pushed down at the bottom
    if (u && d) hit_both++;                        // coverage: up and down together
    if (!(u && d)) begin
      if (u && want != 15) want++;
      else if (d && want != 0) want--;
    end
    @(posedge clk) #1;
    if (cnt !== want) begin err_value++; want = cnt; end   // count a wrong step once, then follow the design
    if (cnt > prev + 1 || prev > cnt + 1) err_step++;
  endtask
  initial begin
    @(posedge clk); @(negedge clk) rst = 0;
    repeat (16) cycle_with(1, 0);                  // directed: up past the top
    repeat (16) cycle_with(0, 1);                  // directed: down past the bottom
    $display("directed: value errors %0d, step errors %0d", err_value, err_step);
    r = $urandom(seed);
    repeat (200) cycle_with($urandom_range(1, 0), $urandom_range(1, 0));
    $display("random:   value errors %0d, step errors %0d", err_value, err_step);
    $display("hits: top %0d, bottom %0d, both %0d", hit_top, hit_bottom, hit_both);
    if (err_value == 0 && err_step == 0 && hit_top > 0 && hit_bottom > 0 && hit_both > 0) $display("sign-off: every check passed and every bin was hit");
    else $display("sign-off: not yet");
    $finish;
  end
endmodule
ConceptWhy does the bench use both directed and random stimulus?
ConceptThe step check stayed silent while the model check found 44 errors. Why?
ConceptZero errors, but the both bin is 0. What is the sign-off answer?
ConceptWhy does the bench count a difference before it copies the design's value into the model?

Common Mistakes

Wrong Write the bench first and the plan afterwards.

The bench then tests what was easy, and the plan is written to match.

Fix Write plan rows from the specification first.

Wrong Sign off because the checks report zero errors.

A situation that never happened cannot fail.

Fix Sign off only when every check passed and every bin was hit.

Wrong Use one check for everything.

A model can share a misreading with the design.

Fix Add a second check of a different kind, such as a rule that must always hold.

Remember

  • End to end means plan, bench, results and coverage, in that order, on one design.
  • Directed stimulus hits the corners; random stimulus reaches what nobody listed.
  • Two checks of different kinds, plus hit counts for the plan's situations.
  • Sign off against the plan: every check passed and every bin hit, or "not yet".

Practice

Report a problem with this page