Algorithm Search⌘K

Conceptcore

Functional coverage

Also called covergroups, coverage model.

User-written coverage points and crosses over design and test values that record which features of the specification have been exercised.

Functional coverage measures which features of a specification the simulation runs of a design have exercised, by counting hits on coverage items that the verification engineer writes: points that sample a value and sort it into bins, crosses of several points, sequences of values, and temporal cover goals. The set of items is the coverage model. Its score is the share of bins hit, under a stated rule for combining items. Unlike code coverage and FSM coverage, whose items come from the source text, functional coverage items come from the specification, so a feature that the code forgets can still have an item. The price is that the model is only as complete as its author made it.

In plain words

Before testing, the team lists the situations that matter: every instruction type, every packet length class, every instruction type with and without a carry, a full buffer followed by a read. Each situation becomes a box with a name. During simulation, a monitor looks at the design at chosen moments and puts a tick in each box whose situation it sees. At the end, the boxes with no tick show what the tests never tried.

Because the boxes come from the specification and not from the code, a box can exist for behavior that the code is missing. A ticked box says only that the situation happened, not that the design handled it right; a checker must say that. And a situation that nobody wrote a box for is never reported as missing.

The idea

Coverage items and bins. A coverage point is an expression ee sampled at an event, for example the operation code of an ALU at each clock edge where a transaction is valid. Its bins are sets of values; a bin is hit when a sample of ee falls in it. Bins can be single values, ranges, or automatic bins (one per value, or ranges when the value set is large). Illegal bins report an error when hit, and ignore bins remove values from the count. In SystemVerilog these are written inside a covergroup with coverpoint and bins (IEEE Std 1800-2017, Clause 19).

Crosses. A cross of points e1,…,eke_1, \ldots, e_k has one bin per tuple of bins (b1,…,bk)(b_1, \ldots, b_k), and that bin is hit when one sample hits b1,…,bkb_1, \ldots, b_k at the same time. With mim_i bins on point ii, the cross has ∏imi\prod_i m_i bins before ignored tuples are removed. The product grows fast, so a cross of a few points can hold more bins than a regression ever hits, and many of its tuples may be impossible by the specification.

Transitions and sequences. A transition bin such as (IDLE => BUSY => DONE) is hit when consecutive samples of a point take those values. Temporal cover goals, cover property in SVA and cover in PSL, are hit when a sequence over clock cycles matches; they come from assertion-based verification.

The score. Let the model have items C1,…,CrC_1, \ldots, C_r, and let item CjC_j have the set BjB_j of bins, of which the runs hit HjH_j. Two ways to combine them are common:

flat=∑j∣Hj∣∑j∣Bj∣,weighted=∑jwj ∣Hj∣/∣Bj∣∑jwj.\text{flat} = \frac{\sum_j |H_j|}{\sum_j |B_j|}, \qquad \text{weighted} = \frac{\sum_j w_j \, |H_j| / |B_j|}{\sum_j w_j}.

SystemVerilog computes the coverage of a coverage group as the weighted average of the coverage of its points and crosses, with the weights given by an option (default 1). The two rules give different numbers for the same hits, so a report must name its rule. A bin can also require a minimum number of hits (at_least) before it counts.

What a full score guarantees. Every bin of the model was hit at least the required number of times, at the sampling events of the model. That is all.

What it does not guarantee.

  • That the design was right. A hit records a stimulus or a state, not a correct response. Checkers, assertions or a scoreboard must judge the response, and the check must be active when the bin is hit.
  • That the model is complete. A situation with no bin is never reported. This is the main weakness and the reason why the model is reviewed against the specification.
  • That the right moment was sampled. A point sampled at the wrong event, or without the condition that a transaction is valid, records values that never mattered.
  • That combinations were hit. Full coverage of two points does not cover their cross. Two points with m1m_1 and m2m_2 bins can be fully hit with max⁡(m1,m2)\max(m_1, m_2) samples, while their cross needs m1m2m_1 m_2.

The cost of random hits. Under purely random stimulus, if each sample hits one of mm equally likely bins, the expected number of samples to hit all of them is mHm≈mln⁡mm H_m \approx m \ln m, the coupon collector bound. Rare bins take much longer. This is one reason for constrained random stimulus with biases and for coverage-directed generation.

Examples

A model with a hole. An 8-bit ALU takes op in {ADD, SUB, AND, OR}, two operands a and b, and a carry in cin, and returns a result and a carry out cout. The model is

covergroup alu_cg @(posedge clk iff valid);
  cp_op    : coverpoint op;          // 4 bins
  cp_cin   : coverpoint cin;         // 2 bins
  op_x_cin : cross cp_op, cp_cin;    // 8 bins
endgroup

Eight transactions, one per (op, cin) pair, with operands below 16, hit all 14 bins: the score is 100 percent by both rules. Suppose the design computes cout wrong whenever a+b+cin≥256a + b + \mathit{cin} \ge 256. With operands below 16 the sum is at most 31, so no transaction triggers the bug, and the model has no bin that asks for it. Add cp_cout : coverpoint cout; with 2 bins. The bin cout = 1 stays empty. Now 15 of 16 bins are hit, a flat score of 15/16=93.7515/16 = 93.75 percent, and the weighted score with unit weights is (1+1+1+1/2)/4=87.5(1 + 1 + 1 + 1/2)/4 = 87.5 percent. Both show the hole, and filling it means generating sums of 256 or more, which exposes the bug.

Bins from the specification. A packet length from 1 to 64 bytes, where the specification treats 1 to 4, 5 to 63 and 64 differently and forbids 0:

coverpoint len { bins small = {[1:4]}; bins mid = {[5:63]}; bins max = {64}; illegal_bins zero = {0}; }

Three bins, plus an error if a length 0 is ever seen. Automatic bins would have made 64 bins and given no extra weight to the boundary 64.

A cross that cannot be closed. A cross of op (4 bins) with a 3-bin mode point has 12 bins. If the specification forbids SUB in one mode, one tuple is impossible, and the score is capped at 11 of 12 until that tuple is declared as an ignore bin. Deciding that a tuple is impossible in the design, rather than only in the specification, is a reachability question that a formal tool can answer through a cover goal.

Coverage versus fault coverage. A fault coverage of 98 percent for a set of manufacturing test patterns and a functional coverage of 98 percent for a regression measure different things on different objects: detected stuck-at faults in a netlist, and bins of a model of the specification.

Where it is used

  • Verification plans and sign-off. A plan lists the features of the specification and maps each one to items. Closure means that every bin is hit or justified as impossible, together with clean checker results and the agreed code coverage.
  • Steering random stimulus. The empty bins tell the engineer which constraints and biases to change, or which directed tests to write. Automating that loop is coverage-directed test generation.
  • Regression ranking. Choosing a small set of runs that hits the same bins is a set cover problem, and tools rank runs with the greedy method.
  • Formal tools. A cover goal given to a model checker either gets a witness trace or is proved unreachable, which justifies removing its bin from the denominator.

References

  1. IEEE Standard for SystemVerilog, Unified Hardware Design, Specification, and Verification Language, IEEE Std 1800-2017, Clause 19 (Functional coverage, with coverage groups, coverage points, bins, transition bins, cross coverage, options and the computation of coverage)
  2. Andrew Piziali, Functional Verification Coverage Measurement and Analysis, Kluwer, 2004, the chapters on the verification plan, on the design of a coverage model from the specification, and on coverage analysis and closure (general locator)
  3. Serdar Tasiran and Kurt Keutzer, Coverage metrics for functional validation of hardware designs, IEEE Design and Test of Computers 18(4), 36 to 45, 2001, the comparison of specification-based metrics with code and state-machine metrics

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/VT7FQR/text.yaml