Functional Coverage: What Was Tested
Count the situations the plan asks for, not the lines of code. Cross two features into bins, read the empty ones, and aim new stimulus at each hole.
You Will Be Able To
- Turn plan rows into coverage bins, and cross two features into a table of bins.
- Leave out the pairs that cannot happen, and say why.
- Read a hit table, find its holes, and choose a way to fill each one.
- Explain how functional coverage differs from code coverage.
- Lesson
- B3.6
- Time
- 22 min
- Runs on
- Your browser
- Check
- 5 questions
Three hundred random ALU operations, three hundred passes. The hit table has eleven bins, and three are still zero. One of them is an addition whose result wraps to zero, the very place the ALU bug of the directed-tests lesson lived.
- Design
- Storage
- Control / FSM
- Step
- Data
- Read the plan
The plan names what must be tested: each operation, and each kind of result.
- Cross them
Every legal pair becomes a bin. Some pairs cannot happen, such as an AND with a carry, and are left out.
- Find the holes
After the run, a bin with a count of 0 is a situation no test reached.
- Aim at them
A new constraint or a directed case fills the hole, and the run is repeated.
Read the diagram as text
- Plan rows: each operation with each kind of result
- Operations: ADD, SUB, AND, XOR
- Result kinds: ordinary, carry, zero, zero with carry
- Cross: 11 bins: every legal pair of the two
- Empty bins: a situation never reached
- Aimed stimulus: a new constraint or a directed case
- Plan rows → Operations: names
- Plan rows → Result kinds: names
- Operations → Cross: 11 bins: crossed with
- Result kinds → Cross: 11 bins: crossed with
- Cross: 11 bins → Empty bins: count 0
- Empty bins → Aimed stimulus: answered by
An idea drawing of the coverage model in the lab below.
Before You Start
Read Random and Constrained-Random Stimulus and Code Coverage: What Ran first. The ALU, its flags and its bug come from Directed Tests.
| Question | |
|---|---|
| 1 | What does functional coverage count, and who writes it? |
| 2 | What is a cross, and why leave some of its pairs out? |
| 3 | What does an empty bin mean? |
| 4 | What can you do about a hole? |
| 5 | How is functional coverage different from code coverage? |
The Idea: A Record of What the Tests Reached
Code coverage, in the last lesson, counted the design's own lines. It could not count a rule the designer forgot. Functional coverage turns the question round. You read the plan, list the situations that must happen in the tests, and count how often each one did.
Each situation is a bin. "An ADD that carries" is a bin. "A SUB that gives zero" is a bin. Every checked transaction drops a count into the bins it matches. After the run, the table says exactly which situations your stimulus reached, and which it never did.
This matters most with random stimulus. You no longer choose the inputs, so you cannot know from the test what it did. Functional coverage is how a random bench reports its own reach. An empty bin is a hole: a situation the plan asked for and no test produced.
New Words
| Word | Meaning |
|---|---|
| Functional coverage | Counts, written by you from the plan, of which situations the tests reached. |
| Bin | One situation with its own count, such as "ADD with a carry". |
| Coverage model | The full set of bins for a design, written from its plan. |
| Cross | Every pair of the values of two features, each pair its own bin. |
| Hole | A bin with a count of 0: a situation no test reached. |
| Sample | Recording one transaction into the bins it matches. |
The Smallest Example: Build the Cross by Hand
The ALU has four operations and its result has two flags, carry and zero. Cross the operation with the pair of flags. Which pairs can happen?
| ordinary | carry | zero | zero with carry | |
|---|---|---|---|---|
| ADD | bin | bin | bin (only 0 + 0) | bin (sum is 256) |
| SUB | bin | bin (a borrow) | bin (a = b) | cannot happen |
| AND | bin | cannot happen | bin | cannot happen |
| XOR | bin | cannot happen | bin (a = b) | cannot happen |
AND and XOR never set the carry, and a borrow never leaves a zero result. So 16 pairs become 11 bins. A bin that cannot happen is left out, or it would stay empty forever and hide the real holes.
The Rules
Rule 1: Bins come from the plan.
Each bin is a situation the specification asks for. You write them; no tool can.
Rule 2: Cross what interacts.
A cross finds pairs no single bin would ask for, such as a carry and a zero together.
Rule 3: Leave out what cannot happen.
Impossible bins stay empty forever and hide the real holes. Say why each is left out.
Rule 4: A hole means the stimulus never got there.
Answer it with a new constraint, a directed case, or a written reason.
Rule 5: Count only checked results.
A bin filled by a transaction that nobody checked records reach, not correctness.
Sources for These Rules
Functional coverage as feedback to stimulus, finding holes, many seeds: Spear and Tumbush, sections 1.6 and 1.8.
Functional coverage comes from the specification and measures design intent; cross coverage: Mehta, ASIC/SoC Functional Design Verification, sections 7.1 and 7.8.
The Lab: Eleven Bins, Three Holes
The lab draws 300 random ALU operations from one seed. For each, it works out the expected flags with the reference model and drops one count into the matching bin. The bins are a plain table of counters.
want = model(op, a, b); // the expected y, c and z
hits[op][{want[0], want[1]}]++; // bin: [operation][zero, carry]op ordinary carry zero zero+carry
ADD 22 46 0 0
SUB 33 32 0 -
AND 78 - 5 -
XOR 83 - 1 -
8 of 11 bins hit, 3 emptyRule 4 at work: three holes, all in the zero column. ADD with zero, SUB with zero, and ADD with zero and carry. Random operands are almost never equal, and almost never sum to exactly 256. XOR with zero was hit once, by luck. The ALU bug from the directed-tests lesson lives in the last empty bin.
Now aim at the holes. In one draw in four, the lab sets b to make the result zero. It uses b = a for SUB and XOR, and b = 256 - a for ADD. The table becomes 10 of 11 bins hit, 1 empty. ADD with zero and carry now has 20 hits. One hole stays: ADD with a zero result and no carry, which needs a = b = 0.
Why Bins Are Written by Hand
Why write bins by hand when code coverage is free? Because only you know the plan. No tool could guess that "a sum of exactly 256" matters for this ALU. That knowledge is the whole value of the model.
Why count instead of just running longer? Because a longer run spends most of its time in bins that are already full. The table shows exactly where the stimulus is thin. Then a small, aimed change does more than millions of extra cycles.
Traps
The first trap is a model copied from the design. Someone makes one bin per state of the design's code. The model then repeats code coverage and adds nothing. Bins come from the plan.
The second trap is filling bins with unchecked traffic. A transaction is sampled whether or not the checker compared it. The table says 100 percent while half the results were never checked. Sample only what a check has looked at.
The third trap is the impossible bin. A bin that cannot happen stays at 0 forever. The team gets used to "one hole that is fine", and a real hole hides beside it. Leave impossible pairs out, and write down why.
Where This Goes Next
This lesson counted hits in plain code. The Coverage track teaches the language built for it, and how to close holes.
| The idea from this page | Where it is taught |
|---|---|
| What coverage measures, with covergroups | What Coverage Measures |
| Covergroups and coverpoints | Covergroups and Coverpoints |
| Choosing bins | Choosing Bins |
| Cross coverage, and leaving pairs out | Cross Coverage |
| Closing coverage holes | Closing Holes |
Try It
Run it: 300 random operations, each counted into its bin of the cross.
Change seed to another number. Do the same three bins stay empty?
Add the aimed line from the lesson after the draw of b. Predict the last line, then find the bin that stays empty.
op ordinary carry zero zero+carry ADD 22 46 0 0 SUB 33 32 0 - AND 78 - 5 - XOR 83 - 1 - 8 of 11 bins hit, 3 emptyCheck Yourself
Common Mistakes
Wrong Write bins by reading the design's code.
The model then repeats code coverage and misses what the plan asks for.
Fix Write each bin from a plan row.
Wrong Keep bins that cannot happen.
They stay empty forever and hide the real holes.
Fix Leave them out and record why.
Wrong Fix a hole by running more cycles.
Random draws keep landing in the bins that are already full.
Fix Aim at the hole with a constraint or a directed case.
Remember
- Functional coverage counts the situations the plan asks for; you write its bins.
- A cross pairs the values of two features; leave out the pairs that cannot happen.
- An empty bin is a hole in the stimulus; answer it with aimed stimulus or a reason.
- Code coverage counts the design's code; functional coverage counts the plan. A project needs both.