Lesson 8: From Verification Plan to Coverage Model

A coverage model is the verification plan's coverage goals written as code. Each plan row becomes a covergroup, or a coverpoint inside one, whose bins are exactly the cases the row says must be exercised, so a coverage report can be read row by row against the plan. Holes in the report then point at specific plan rows, and closing coverage means adding the stimulus that exercises those rows until every goal is met.

Learning objectives

  • Map each row of a verification plan to a covergroup or coverpoint whose bins match the row's goal
  • Write bins for values, transitions and crosses, and sample them on the right event
  • Read a coverage report against the plan and name the stimulus each hole needs
  • Close coverage with directed traffic and confirm the scoreboard still passes

Prerequisites

  • Lesson 1: the FIFO's verification plan this lesson implements
  • Lesson 7: covergroups, coverpoints, bins and crosses
  • The running example is the synchronous FIFO: 16 entries of 8 bits, one clock, flags full and empty and an occupancy count; writes when full are dropped, reads when empty are ignored, and read data appears one clock after the read. Its shared testbench code is in the site's repository under scripts/verification/fifo, and every example runs in AMD Vivado xsim 2025.2.

From plan rows to bins

Each plan row's coverage goal becomes bins. F1 asks for the corner data values, so it gets four value bins on accepted writes. F2 to F4 ask for empty, full and every count in between, so one coverpoint with a bin per count value covers all three. F5 and F6 are about operations at the two ends, so they are a cross. F7, F8 and F9 need state the signals do not show directly, so the model tracks it and samples by hand. F10 is an invariant and stays an assertion.

Each FIFO verification plan row mapped to the covergroup that measures it, with its number of bins
Each FIFO plan row and the covergroup that measures it, with its number of bins. F10 has no bins: it is checked by an assertion on every clock.

The coverage model

The covergroups live in one module bound into the FIFO, like the assertions in Lesson 9. Clocked covergroups sample on the rising edge with iff, so F1 only counts writes that were accepted. The others have a sample function, called by the always block that tracks read runs, reset levels and the slot each pointer is on.

fifo/fifo_plan_cov.sv: one covergroup per plan row
  // F1: data goes in and comes out unchanged. Goal: the corner values were written at least once.
  covergroup cg_f1_data @(posedge clk iff (!rst && wr_en && !full));
    cp_data: coverpoint wr_data { bins zero = {0}; bins max = {255}; bins h55 = {8'h55}; bins hAA = {8'hAA}; }
  endgroup

  // F2, F3, F4: empty at 0, full at 16, and every count value in between.
  covergroup cg_f4_count @(posedge clk iff (!rst));
    cp_count: coverpoint count { bins value[] = {[0:16]}; }
  endgroup

  // F5, F6: every operation at both ends of the FIFO (a write when full, a read when empty, and both together).
  covergroup cg_f5_f6_ends @(posedge clk iff (!rst));
    cp_end: coverpoint count { bins empty = {0}; bins full = {16}; }
    cp_op: coverpoint {wr_en, rd_en} { bins idle = {2'b00}; bins read = {2'b01}; bins write = {2'b10}; bins both = {2'b11}; }
    end_x_op: cross cp_end, cp_op;
  endgroup

  // F7: runs of back-to-back reads, up to all 16 entries.
  covergroup cg_f7_burst with function sample(int len);
    cp_len: coverpoint len { bins two_three = {[2:3]}; bins four_seven = {[4:7]}; bins eight_fifteen = {[8:15]}; bins sixteen = {16}; }
  endgroup

  // F8: reset from any state: empty, part full and full.
  covergroup cg_f8_reset with function sample(bit [4:0] level);
    cp_level: coverpoint level { bins empty = {0}; bins middle = {[1:15]}; bins full = {16}; }
  endgroup

  // F9: both pointers wrap from slot 15 to slot 0.
  covergroup cg_f9_wrap with function sample(bit [3:0] wr_slot, bit [3:0] rd_slot);
    cp_wr: coverpoint wr_slot { bins wrap = (15 => 0); }
    cp_rd: coverpoint rd_slot { bins wrap = (15 => 0); }
  endgroup
fifo/fifo_plan_cov.sv: the state the plan needs
  // The plan rows that need state: read runs, reset levels and the slot each pointer is on.
  int run_len;
  bit [3:0] wr_slot, rd_slot;
  bit was_rst = 1;
  always @(posedge clk) begin
    if (rst && !was_rst) f8.sample(count);
    was_rst = rst;
    if (rst) begin
      run_len = 0; wr_slot = 0; rd_slot = 0;
    end else begin
      if (rd_en && !empty) run_len++;
      else begin if (run_len >= 2) f7.sample(run_len); run_len = 0; end
      if (wr_en && !full)  begin f9.sample(wr_slot, rd_slot); wr_slot++; end
      if (rd_en && !empty) begin rd_slot++; f9.sample(wr_slot, rd_slot); end
    end
  end

Worked example: closing the plan's coverage

Phase A is Lesson 7's phased random traffic, checked by the scoreboard. The report reads row by row:

xsim output: phase A
664 clocks checked, 273 writes, 272 reads, 0 errors: PASS
phase A, random traffic:
  F1     data corners          100.0%
  F2-F4  count 0 to 16         100.0%
  F5-F6  ops at both ends      100.0%
  F7     back-to-back reads     75.0%
  F8     reset levels            0.0%
  F9     pointer wrap          100.0%
  plan coverage                 79.2%

Two rows have holes. F7 is at 75%: no run of reads reached 16, because random traffic rarely fills the FIFO and then reads it dry without a write in between. F8 is at 0%: nothing in the random traffic resets the FIFO. Each hole names its fix. Phase B resets the FIFO together with the scoreboard's model, fills it and reads all 16 back, and resets it when empty, at 8 entries and when full.

fifo_covplan_tb.sv: phase B helpers
  // Phase B helpers: send transactions through the environment, and reset the FIFO and the model together.
  task automatic send(bit wr, bit rd, bit [7:0] data = 0);
    fifo_txn t = new(wr, rd, data);
    env.g2d.put(t);
  endtask
  task automatic settle();
    while (env.g2d.num() != 0) @(posedge clk);
    repeat (2) @(posedge clk);
  endtask
  task automatic reset_now();
    settle();
    @(negedge clk) vif.rst = 1;
    @(negedge clk) vif.rst = 0;
    env.sb.model = new();
  endtask
fifo_covplan_tb.sv: phase B
    // Phase B: the holes.
    reset_now();                                                  // from wherever phase A left it
    reset_now();                                                  // F8: reset when empty
    send(1, 0, 0); send(1, 0, 255); send(1, 0, 8'h55); send(1, 0, 8'hAA);   // F1: the corner values
    for (int i = 0; i < 4; i++) begin send(1, 0, 8'(i)); end
    reset_now();                                                  // F8: reset at 8 entries
    for (int i = 0; i < 16; i++) begin send(1, 0, 8'(i)); end
    for (int i = 0; i < 16; i++) begin send(0, 1); end          // F7: 16 reads in a row
    for (int i = 0; i < 16; i++) begin send(1, 0, 8'(i)); end
    reset_now();                                                  // F8: reset when full
    settle();
xsim output: phase B
phase B: 729 clocks checked, 0 errors: PASS
phase B, after closing the holes:
  F1     data corners          100.0%
  F2-F4  count 0 to 16         100.0%
  F5-F6  ops at both ends      100.0%
  F7     back-to-back reads    100.0%
  F8     reset levels          100.0%
  F9     pointer wrap          100.0%
  plan coverage                100.0%
Coverage per FIFO plan row: random traffic leaves bursts and resets short, directed closure reaches 100%
Coverage of each plan row after phase A and after phase B, from the run. The two hatched cells are the holes random traffic left; phase B's directed traffic closes both.

Every row is at 100% and the scoreboard checked 729 clocks with 0 errors, so the plan's coverage goals are met by traffic that was also checked. This is the coverage closure loop with the plan in it: run, read the holes against the plan rows, add stimulus for those rows, and run again.

Coverage closure loop: run the regression, merge coverage, find holes, steer stimulus and run again
The coverage closure loop: the plan gives the coverage model; run, merge coverage, find the holes, steer the stimulus or add tests, and run again until every goal is met.

Common mistakes

  • Writing covergroups from the design's signals instead of the plan's rows, so 100% coverage does not mean the plan was met.
  • Sampling on every clock when the row is about one event, such as accepted writes; use iff or a sample function, or the bins fill with clocks that tested nothing.
  • Resetting the design in the middle of a run without resetting the scoreboard's model, so closure traffic reports false errors.
  • Using automatic bins on a wide value where the plan asks for specific cases, so the report has hundreds of bins and no meaning.
  • Treating a plan row with no bins (an invariant like F10) as uncovered: it is an assertion, checked on every clock.

Quick check

1. Why do F2, F3 and F4 share one coverpoint?

Empty is count 0, full is count 16, and F4 asks for every count from 0 to 16. A bin per count value covers all three goals.

2. Random traffic left F8 at 0%. Why can more random traffic not close it?

Nothing in the random traffic resets the FIFO. Coverage only grows with the stimulus that can reach a bin; F8 needs a test that resets on purpose.

3. Why does phase B reset the scoreboard's model with the FIFO?

The model is a queue of what the FIFO should hold. After a reset in the middle of a run the FIFO is empty; if the model is not, every later check fails.

Exercises

Graded from easy to hard. Try each one before you open the solution; every solution was run in xsim 2025.2, and its output is shown.

E1 (easy). F10-style rules can also be coverage: make count values above 16 an illegal bin.

illegal_bins are not counted toward coverage; a hit is reported as an error. In xsim 2025.2 the run continues after printing the error, so check the log for it. This run has none.

fifo_covplan_ex_tb.sv: E1
  // E1: plan row F10 says count never goes past 16. As coverage, that is an illegal bin.
  covergroup cg_e1 @(posedge clk iff (!vif.rst));
    cp_count: coverpoint vif.count { bins legal[] = {[0:16]}; illegal_bins too_big = {[17:31]}; }
  endgroup
  cg_e1 e1 = new();
xsim output
E1: count 0 to 16 covered 100.0%
E2 (easy). F7's bin sixteen stayed empty in phase A. Measure the longest run of back-to-back reads to see why.

The longest run was 9 reads. Random traffic would need 16 reads in a row starting from full, so the hole is real, not a sampling mistake.

fifo_covplan_ex_tb.sv: E2
  // E2: the longest run of back-to-back reads, to see why a bin is empty.
  always @(posedge clk) if (!vif.rst) begin
    if (vif.rd_en && !vif.empty) begin run++; if (run > longest) longest = run; end else run = 0;
  end
xsim output
E2: longest run of back-to-back reads: 9; bin sixteen needs 16
E3 (medium). The plan asks for every slot to be read at least 10 times. Write that goal with option.at_least.

A bin only counts as covered after 10 hits. Random traffic read every slot at least 10 times, so this goal was already met by phase A.

fifo_covplan_ex_tb.sv: E3
  // E3: plan row F1 asks for every slot to be read at least 10 times.
  bit [3:0] rd_slot;
  covergroup cg_e3 with function sample(bit [3:0] slot);
    option.at_least = 10;
    cp_slot: coverpoint slot { bins slot[] = {[0:15]}; }
  endgroup
  cg_e3 e3 = new();
  always @(posedge clk) if (vif.rst) rd_slot = 0; else if (vif.rd_en && !vif.empty) begin e3.sample(rd_slot); rd_slot++; end
xsim output
E3: slots read at least 10 times: 100.0% of 16
E4 (hard). Close the plan automatically: after phase A, look at each covergroup below 100% and run the directed fix for its row, until nothing is left.

Each row's fix is a small directed sequence. The loop found F7 and F8 below goal in the first round, fixed both, found nothing in the second and stopped, with the scoreboard still passing.

fifo_covplan_ex_tb.sv: E4
        // E4: close the plan automatically: for each covergroup below 100%, run the directed fix for its row.
        int rounds;
        while (rounds < 3) begin
          bit any;
          any = 0;                                   // assigned each round: the declaration only runs once
          if (dut.plan_cov.f7.get_coverage() < 100) begin
            $display("E4: F7 at %0.1f%%: fill, then 16 reads in a row", dut.plan_cov.f7.get_coverage());
            reset_now();
            for (int i = 0; i < 16; i++) begin send(1, 0, 8'(i)); end
            for (int i = 0; i < 16; i++) begin send(0, 1); end
            any = 1;
          end
          if (dut.plan_cov.f8.get_coverage() < 100) begin
            $display("E4: F8 at %0.1f%%: reset when empty, at 8 and when full", dut.plan_cov.f8.get_coverage());
            reset_now(); reset_now();
            for (int i = 0; i < 8; i++) begin send(1, 0, 8'(i)); end
            reset_now();
            for (int i = 0; i < 16; i++) begin send(1, 0, 8'(i)); end
            reset_now();
            any = 1;
          end
          if (dut.plan_cov.f1.get_coverage() < 100) begin
            $display("E4: F1 at %0.1f%%: write the corner values", dut.plan_cov.f1.get_coverage());
            send(1, 0, 0); send(1, 0, 255); send(1, 0, 8'h55); send(1, 0, 8'hAA);
            any = 1;
          end
          settle();
          rounds++;
          if (!any) break;
        end
        $display("E4: %0d clocks checked, %0d errors: %s", env.sb.cycles, env.sb.errors, env.sb.errors ? "FAIL" : "PASS");
        dut.plan_cov.report($sformatf("E4: after %0d rounds", rounds));
      end
xsim output
E4: F7 at 75.0%: fill, then 16 reads in a row
E4: F8 at 33.3%: reset when empty, at 8 and when full
E4: 733 clocks checked, 0 errors: PASS
E4: after 2 rounds
  F1     data corners          100.0%
  F2-F4  count 0 to 16         100.0%
  F5-F6  ops at both ends      100.0%
  F7     back-to-back reads    100.0%
  F8     reset levels          100.0%
  F9     pointer wrap          100.0%
  plan coverage                100.0%

Interview questions

  • Q1. How do you build a coverage model? Answer: from the verification plan, one covergroup or coverpoint per row, with bins that are exactly the row's goal. Then the report reads row by row against the plan, as it does here for the FIFO's F1 to F9.
  • Q2. Coverage is stuck below 100%. What do you do? Answer: find which plan rows the holes belong to and ask what stimulus could reach them. More random traffic never reset the FIFO here, so F8 stayed at 0% until a directed reset test was added.
  • Q3. Should every plan row have coverage bins? Answer: no. An invariant such as full and empty never both high is checked by an assertion on every clock; there is no case to reach, only a rule that must never break.

Summary

  • A coverage model is the plan's coverage goals as code: one covergroup or coverpoint per row.
  • Value bins, transition bins, crosses and sample functions each fit a different kind of goal.
  • Random traffic covered 79.2% of the FIFO's plan; the holes, 16-read bursts and resets, named their own fixes.
  • Directed closure brought every row to 100% with the scoreboard still checking every clock.

Related

Sources

Last verified

Run in Vivado xsim 2025.2 on 26 November 2026: phases A and B of the coverage model, and all four exercise solutions. Outputs are copied from those runs and kept in scripts/verification/results; lib/verificationCourse.test.js checks them against this page.

Keep going