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.
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.
Code coverage is free (tool does it). Functional coverage requires you to define what "done" means.
| Metric | What it measures | Who defines it | Typical goal |
|---|---|---|---|
| Line | Each RTL statement executed ≥1× | Simulator (auto) | 95%+ |
| Branch | Both true and false paths of if/case | Simulator (auto) | 90%+ |
| Toggle | Each bit flipped 0→1 and 1→0 | Simulator (auto) | 80%+ (diminishing returns) |
| FSM state | Every state entered ≥1× | Simulator (auto) | 100% |
| Covergroup | User-defined scenario bins hit | You (manual) | 100% of planned bins |
After simulation, your tool highlights unexecuted lines in red. A typical report looks like this:
Red lines tell you where to add tests. But green lines don't mean correct — they only mean executed.
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.
Toggle coverage requires every bit of every signal to go 0→1 and 1→0. Sounds thorough — but:
op[1] always 0) will never toggle — false hole.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.
A covergroup defines bins (buckets) and records when simulation hits them. This is how you track test-plan completion.
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
Discrete buckets: each opcode, each FSM state, each error code. Hit all bins = scenario tested.
Combinations: opcode × backpressure. Catches "we tested MUL but never MUL under stall."
Each bin in the covergroup should correspond to a row in your test plan table from lesson 10.2.
If covergroups feel heavy, use cover property for one-off scenario tracking (pairs with lesson 10.3 assertions):
// 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));
| Claim | Reality |
|---|---|
| "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. |
Not every uncovered line is a bug waiting to happen. Document waivers for legitimate gaps:
| Waivable | Not waivable |
|---|---|
default branch for unreachable opcodes | Error handling path in active protocol |
Debug-only $display blocks | Reset sequence logic |
Tied-off parameter paths (if (0)) | Backpressure / flow-control branches |
| Synthesis pragma exclusions | FSM states reachable per spec |
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