Day 102: Functional coverage: covergroups, coverpoints, bins
Functional coverage: covergroups
Random stimulus is only useful if you *measure* what it exercised. Functional coverage does this: a covergroup samples signals/variables at defined events; coverpoints track which values occurred; bins group values into buckets of interest (each opcode, each FIFO occupancy level, each error type). The percentage of bins hit is your coverage — a direct, quantitative answer to 'did we test that scenario?'.
covergroup cg_uart @(posedge clk);
cp_data: coverpoint txn.data {
bins low = {[0:63]};
bins mid = {[64:191]};
bins high = {[192:255]};
bins corners = {0, 255}; // explicitly track the extremes
}
cp_err: coverpoint txn.parity_err { bins ok = {0}; bins err = {1}; }
endgroup
cg_uart cov = new();
// call cov.sample() (or rely on @event) as transactions occur
Coverage vs assertions
A crucial distinction interviewers probe: assertions check correctness (did something *wrong* happen?), while coverage measures completeness (did something *interesting* happen?). You need both — a design can pass every assertion simply because a scenario was never stimulated. Coverage tells you the assertions were actually exercised.
Key terms
- Functional coverage
- A measure of which interesting scenarios the stimulus actually exercised.
- Covergroup
- A sampling construct grouping coverpoints, triggered at a defined event.
- Coverpoint
- A variable/signal whose observed values are tracked for coverage.
- Bin
- A bucket of values a coverpoint counts; coverage = fraction of bins hit.
Before moving on, you should be able to
What is the key difference between an assertion and a functional coverage point?