Code and Toggle Coverage on a Whole Chip
Read a code and toggle report of a whole chip. Learn which zeros are holes, which are ties and which are unused logic, and what the report costs.
You Will Be Able To
- Name what line, branch and toggle coverage count, and what each cannot see.
- Sort the zeros of a chip toggle report into ties, holes and unused logic.
- Read the cost of structural coverage from a measurement and decide when to run it.
- Keep structural and functional coverage apart, and use each to check the other.
- Lesson
- V12.3
- Time
- 26 min
- Runs on
- Your browser
- Check
- 5 questions
The first code coverage report of the whole chip arrives. Tens of thousands of toggle points, and red everywhere. The team has a week. Which zeros matter?
- Clock / reset
- Control / FSM
- Debug
- Control
- Reset
- Alive
The timer's gate enable rose and fell: a test stopped and restarted that clock.
- Half alive
The UART gate enable rose at every reset and never fell. No test stopped the UART clock.
- Dead, and closable
The software reset request never moved. One test that writes SOFT_RESET would move it.
- Dead, and expected
The debug reset request is tied low by the chip. No test can move it; the report lists it as a tie.
Read the diagram as text
- u_crg: clocks and resets
- timer_gate.enable: rose 10, fell 2
- uart_gate.enable: rose 8, fell 0
- soft_reset_req: never toggled
- debug_reset_req: tied low
- timer_gate.enable → u_crg: alive
- uart_gate.enable → u_crg: half
- soft_reset_req → u_crg: dead
- debug_reset_req → u_crg: tie
Toggle counts summed over the eight runs of the E11 suite on the structural build (record-v12-labs.mjs coverage).
Before You Start
Read What Coverage Means at Chip Level first. Toggling every wire on purpose, as a test, is Toggle Tests in Simulation; this lesson reads the coverage report instead. What Coverage Measures introduces code coverage.
| Question | |
|---|---|
| 1 | What do line, branch and toggle coverage count? |
| 2 | Why is a chip toggle report mostly zeros, and which zeros matter? |
| 3 | What is a tied port, and how is it kept out of the way? |
| 4 | What does structural coverage cost on the chip bench? |
| 5 | How do structural and functional coverage check each other? |
The Idea: A Map of What the Suite Never Touched
Code coverage is counted by the simulator, with no plan at all. It counts which lines ran, which branches were taken and which bits moved. Nobody writes its bins, so it finds what nobody thought to plan for.
On a whole chip that is both its strength and its trouble. The report covers every instance, so most of it is block logic the block benches already closed. And many zeros can never become ones. Some are inputs the chip ties to a constant. Others are logic for a feature this chip does not use.
So you read a chip report at the joints first: the ports of each block. A port that never moved has one of three stories. The chip ties it, or no test used it, or the chip does not use it at all. Only the second kind is a hole.
New Words
| Word | Meaning |
|---|---|
| Line coverage | Which statements ran at least once. |
| Branch coverage | Which way each if or case went, counted per outcome. |
| Toggle coverage | Which bits rose and which fell; each bit has two directions. |
| Structural coverage | Line, branch and toggle coverage together: counted from the design's structure, with no plan. |
| Tied port | A block input the chip connects to a constant; connect.csv lists each one with its reason. |
| Per-instance counting | Counting each instance of a module separately, so two identical blocks get two sets of points. |
The Smallest Example: Six Ports, Counted by Hand
Six one-bit ports, named after the timer's: capture, event_in, online, kick, pwm and irq. online is tied high, as the chip ties it. The test pulses pwm three times and irq once, and never touches the others. Count rises and falls.
| Port | 0 to 1 | 1 to 0 | Kind |
|---|---|---|---|
| capture | 0 | 0 | hole: no test pulsed it |
| event_in | 0 | 0 | hole |
| online | 0 | 0 | tie: it is held at 1 |
| kick | 0 | 0 | hole |
| pwm | 3 | 3 | alive |
| irq | 1 | 1 | alive |
The runnable example below prints these counts.
Four ports read zero, and they are not alike. online cannot move on this chip, so you list it with its reason and stop. The other three can move: a test that pulses each would close it.
The Rules
Rule 1: Read block ports before block insides.
The ports are where integration shows. The insides were the block bench's.
Rule 2: List every tie with its reason, then leave it.
connect.csv says which inputs the chip ties and why. The report should carry that list.
Rule 3: A port that moved one way only is a hole.
A gate enable that rose but never fell means no test stopped that clock. A tie may rise once as each run starts; its reason, not its count, decides.
Rule 4: Argue unused logic out with the design team, in writing.
A feature this chip does not use stays at zero forever. Remove it from the count only with a written reason.
Rule 5: Never add structural and functional percentages.
They count different things over different totals.
Rule 6: Run structural coverage on purpose, not always.
It costs several times the run time. Run it on a chosen suite, then read it.
Sources for These Rules
The structural option uses Verilator --coverage-line, --coverage-toggle and --coverage-per-instance. Its tied-port list and separate denominators: tools/soc/ap_soc/bench/soc_tb/README.md, "Chip coverage (E11)". The ties come from connect.csv rows whose kind is const.
Leverage code coverage beside functional coverage at SoC level: MEHTA-DV 16.9 (PDF p327-328). States are seen by code coverage, but transitions between them need functional points: the same page.
Toggle coverage counts the two directions of each bit separately: the measured counts of this lab.
The Lab: The Chip's Structural Report
First the toy, on the site's Icarus. Icarus has no toggle coverage, so the example counts rises and falls itself:
capture 0->1 0 1->0 0 never toggled both ways
event_in 0->1 0 1->0 0 never toggled both ways
online 0->1 0 1->0 0 never toggled both ways
kick 0->1 0 1->0 0 never toggled both ways
pwm 0->1 3 1->0 3
irq 0->1 1 1->0 1Now the chip. The eight runs of the coverage suite ran again on the structural build. It keeps a counter for every line, branch and bit of every instance. Five blocks of the report follow.
| Block | Line | Branch | Toggle directions |
|---|---|---|---|
| u_timer | 17/17 | 26/32 | 427/998 |
| u_crg | 30/33 | 73/78 | 257/488 |
| u_dm | 2/12 | 8/30 | 13/772 |
| u_tap | 4/27 | 4/50 | 6/268 |
| u_fabric | 61/62 | 265/306 | 8896/16294 |
Eight runs, summed. Verilator 5.053 devel.
u_dm and u_tap, the debug module and the TAP, are nearly all zero: the suite ran no debug session. That is one test missing, not hundreds. The block u_timer has every line, 17/17, yet 427/998 toggle directions: lines ran, but many bits never moved.
| Port | 0 to 1 | 1 to 0 | Reading |
|---|---|---|---|
| u_crg.uart_gate.enable | 8 | 0 | hole: no test stopped the UART clock (rule 3) |
| u_crg.soft_reset_req | 0 | 0 | hole: no software reset in the suite |
| u_crg.debug_reset_req | 0 | 0 | tie: the v1.5 debug module asks for no reset (rule 2) |
| u_timer.online | 8 | 0 | tie: held at 1; it rose once per run, at start |
| u_timer.event_in | 0 | 0 | hole: no test routed the event pad |
11 tied ports and spare inputs are listed with their reasons in the report.
The UART gate row and the functional bin gate.uart.shut say the same thing in two languages. When structural and functional coverage agree on a hole, you know exactly which test to write.
| Build | Median of three runs (s) | Against the bare coverage tool |
|---|---|---|
| The bench's own build (Verilator 5.032) | 5.933 | 1.08× |
| Coverage tool, no coverage (5.053) | 5.475 | 1.00× |
| With the functional sampler | 5.645 | 1.03× |
| With line, branch and toggle counters too | 14.45 | 2.64× |
1,300,028 system cycles a run, on the laptop while other jobs ran (record-v12-labs.mjs coverage). On a quiet laptop, stage E11 measured the sampler at +4.6% and the counters at 3.05× (plan §6.2).
Rule 6 in numbers: the structural build took 2.64 times as long as the same simulator without counters. The quiet measurement of the plan gave 3.05 times. Either way it costs several times the run. So you run it on a chosen suite, not on every test of every night.
Why It Is Built This Way
Why count per instance? The chip has five APB guards, built from one module. Counted together, a toggle seen in any guard covers all five. Counted per instance, the report shows that the SPI guard's bits barely moved while the GPIO guard's did.
Why keep the structural build apart from the build the problems run on? Because of rule 6. The problems run learners' tests many times a day and need speed. The structural report is made offline, on purpose, and read by a person.
Traps
The first trap is the week spent on ties. A team assigns every zero of the report to a person. Half of them are inputs the chip ties to a constant. Nobody can move them, and the week ends with no new test.
The second trap is the waiver list that only grows. Points are excluded one at a time, each with a short note, and nobody reviews the list. A feature that a later revision starts to use is still excluded, and its real hole hides under an old waiver.
The third trap is mixing builds. Two reports from different builds of the chip are merged. Point names that look the same mean different logic, and the merged numbers are fiction. The chip's merge refuses runs with differing build fingerprints for that reason.
At Scale
This section looks ahead. ap_soc's report fits in a table; a large chip's has millions of points.
Exclusion files
Teams keep reviewed lists of excluded points, ties and unused features. Each entry has a reason and a reviewer, and every report applies the list.
Coverage on a subset
Structural coverage runs weekly on a chosen suite; nightly runs keep only functional coverage.
Formal unreachability
A formal tool can prove a point unreachable, so it leaves the count with evidence instead of an argument.
Try It
Run it: six ports, their rises and falls, and which never moved both ways.
Pulse capture once (the predict question below). Which line changes?
Tie event_in high instead of low. Does its line change? Why or why not?
capture 0->1 0 1->0 0 never toggled both ways event_in 0->1 0 1->0 0 never toggled both ways online 0->1 0 1->0 0 never toggled both ways kick 0->1 0 1->0 0 never toggled both ways pwm 0->1 3 1->0 3 irq 0->1 1 1->0 1Check Yourself
Common Mistakes
Wrong Chase every zero of the chip toggle report.
Many zeros are ties or logic this chip does not use; no test can move them.
Fix Sort zeros into ties, unused logic and holes; write tests for the holes only.
Wrong Average structural and functional percentages into one number.
They count different things over different totals.
Fix Report them apart, and use each to explain the other's holes.
Wrong Turn on structural coverage for every nightly run.
It made each run several times slower in the measurement.
Fix Run it on a chosen suite, on purpose, and read the report.
Remember
- Code coverage needs no plan, so it finds what nobody planned for.
- A chip report's zeros are ties, unused logic or holes; only holes need tests.
- Read block ports first; list ties with their reasons.
- Structural coverage is expensive: run it on purpose, and keep its numbers apart from functional ones.