RTL Design / Module 10: Verification for RTL Designers
Lesson 10.4

Coverage basics — did I even stimulate that?

Your tests pass — but did simulation actually exercise the logic you care about? Coverage answers that question. It tells you which lines ran, which branches flipped, and whether the scenarios in your test plan ever happened.

Core question

Coverage doesn't prove correctness — it proves stimulation. If a line never executed, your passing tests are silent about it. If a functional scenario never occurred, you have a hole in your test plan.

1

Code coverage vs functional coverage

Code coverage vs functional coverage

Code coverage is free (tool does it). Functional coverage requires you to define what "done" means.

MetricWhat it measuresWho defines itTypical goal
LineEach RTL statement executed ≥1×Simulator (auto)95%+
BranchBoth true and false paths of if/caseSimulator (auto)90%+
ToggleEach bit flipped 0→1 and 1→0Simulator (auto)80%+ (diminishing returns)
FSM stateEvery state entered ≥1×Simulator (auto)100%
CovergroupUser-defined scenario bins hitYou (manual)100% of planned bins
2

Line & branch — reading a coverage report

After simulation, your tool highlights unexecuted lines in red. A typical report looks like this:

Coverage summary — acc_8bit Line: 87.5% (7/8 lines hit) Branch: 75.0% (3/4 branches hit) Toggle: 62.5% (avg across signals) UNCOVERED: line 24: else if (en) acc_r <= acc_r + din; ← never disabled path branch line 22: if (!rst_n) — false branch never taken during sim

Red lines tell you where to add tests. But green lines don't mean correct — they only mean executed.

Trap — 100% line ≠ verified

A line can execute with the wrong inputs and still show green. Line coverage says "this code ran" — not "this code produced the right answer." That's what your self-checking TB is for. Coverage and checking are complementary, not interchangeable.

3

Toggle coverage — the gotcha

Toggle coverage requires every bit of every signal to go 0→1 and 1→0. Sounds thorough — but:

  • Tied-off signals (e.g. op[1] always 0) will never toggle — false hole.
  • Wide buses need many patterns to toggle all bits — expensive, low value.
  • Reset values that never change create permanent toggle gaps.

Practical advice: aim for high line + branch coverage on your DUT. Use toggle coverage selectively on control signals (FSM states, handshake flags) — not on 32-bit data buses.

4

Covergroups lite — functional coverage you write

A covergroup defines bins (buckets) and records when simulation hits them. This is how you track test-plan completion.

covergroup_lite.sv
covergroup alu_cg @(posedge clk);
  option.per_instance = 1;

  // Did we test each opcode?
  cp_op: coverpoint op {
    bins add = {2'b00};
    bins mul = {2'b01};
    bins and_op = {2'b10};
    bins illegal = {2'b11};
  }

  // Did backpressure last more than 1 cycle?
  cp_backpressure: coverpoint m_ready {
    bins no_bp  = {1'b1};
    bins held   = {1'b0};
  }

  // Cross: every opcode under backpressure
  cx_op_bp: cross cp_op, cp_backpressure;

  // Did overflow occur? (a + b wraps 8-bit)
  cp_overflow: coverpoint (a + b) {
    bins normal  = {[0:254]};
    bins wrapped = {255};
  }
endgroup

alu_cg alu_cov = new();

// In final block — print coverage
initial begin
  // ... run all tests ...
  $display("Opcode coverage: %0.1f%%", alu_cov.cp_op.get_coverage());
  $display("Cross coverage:  %0.1f%%", alu_cov.cx_op_bp.get_coverage());
end
🪣

Bins

Discrete buckets: each opcode, each FSM state, each error code. Hit all bins = scenario tested.

✖️

Cross coverage

Combinations: opcode × backpressure. Catches "we tested MUL but never MUL under stall."

📋

Maps to test plan

Each bin in the covergroup should correspond to a row in your test plan table from lesson 10.2.

5

Cover property — lightweight alternative

If covergroups feel heavy, use cover property for one-off scenario tracking (pairs with lesson 10.3 assertions):

cover_property_lite.sv
// Did we ever see a reset mid-transfer?
cover property (@(posedge clk)
  (s_valid && !rst_n));

// Did FIFO ever reach full?
cover property (@(posedge clk)
  (count == DEPTH));

// Did we test backpressure > 3 cycles?
reg [2:0] bp_cnt;
always @(posedge clk) begin
  if (!m_ready && m_valid) bp_cnt <= bp_cnt + 1;
  else bp_cnt <= 0;
end
cover property (@(posedge clk) (bp_cnt >= 3));
▶ Run with coverage in simulator
6

What 100% line coverage does NOT mean

ClaimReality
"100% line — we're done"Lines ran, but possibly with wrong data. Checker must still pass.
"No red lines — no bugs"Bugs in executed lines with untested input combos still hide.
"High toggle — thorough"Data bus bits toggled ≠ meaningful scenarios tested.
"Coverage replaces directed tests"Coverage finds holes; directed tests fill them. Both needed.
"100% functional — ship it"Bins hit ≠ correct behavior. Bins track stimulation, not correctness.
Self-checking TB+Directed corners+Code coverage+Functional coverage=Confidence
7

Waivers — when to accept a hole

Not every uncovered line is a bug waiting to happen. Document waivers for legitimate gaps:

WaivableNot waivable
default branch for unreachable opcodesError handling path in active protocol
Debug-only $display blocksReset sequence logic
Tied-off parameter paths (if (0))Backpressure / flow-control branches
Synthesis pragma exclusionsFSM states reachable per spec
waiver_template.txt
Waiver: acc_8bit.v line 28 (else branch)
Reason:  en=0 hold path — exercised functionally but branch
         tool reports miss due to optimization
Evidence: T03_en_low_hold passes; waveform shows acc_r stable
Reviewer: [name]  Date: [date]  Milestone: RTL freeze
8

Coverage closure workflow

  1. Run sim with code coverage enabled.
  2. Review report — sort by lowest coverage modules first.
  3. Map holes to test plan — is there a directed test for each red line?
  4. Add tests or waive — dead code, tied-off bits, and debug-only paths get documented waivers.
  5. Check functional bins — are all covergroup bins hit?
  6. Re-run until line/branch goals met and functional bins closed.
9

Coverage checklist

  • Code coverage (line + branch) enabled for every regression run
  • Uncovered lines reviewed — new directed test or documented waiver
  • Covergroup bins map 1:1 to test plan scenarios
  • Cross coverage for critical combinations (opcode × backpressure, etc.)
  • Understand that 100% line ≠ verified — checker must still pass
  • Toggle coverage used selectively on control signals, not data buses
  • Coverage report archived with each milestone signoff

🎯 What to remember

  • Code coverage = "was the RTL touched?" Functional coverage = "did the scenario happen?"
  • 100% line coverage is necessary but never sufficient — it says nothing about correctness.
  • Covergroups map your test plan to measurable bins; crosses catch combo gaps.
  • Coverage finds holes; directed tests and checkers fill and validate them.
Advertisement