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?

A Toggle Report with One Dead PortFour inputs of the chip's clock and reset block after the eight runs of the coverage suite. One toggled both ways. One is tied by the chip and can never move. Two never moved although a test could move them.
  • Clock / reset
  • Control / FSM
  • Debug
  • Control
  • Reset
A Toggle Report With One Dead PortFour inputs of the chip's clock and reset block after the eight runs of the coverage suite. One toggled both ways. One is tied by the chip and can never move. Two never moved although a test could move them. clock reset u_crg clocks and resets control timer_gate.enable rose 10, fell 2 control uart_gate.enable rose 8, fell 0 control soft_reset_req never toggled debug debug_reset_req tied low alivehalfdeadtie
  1. control timer_gate.enablerose 10, fell 2
    • alive → u_crg
  2. clock reset u_crgclocks and resets
  3. control uart_gate.enablerose 8, fell 0
    • half → u_crg
  4. control soft_reset_reqnever toggled
    • dead → u_crg
  5. debug debug_reset_reqtied low
    • tie → u_crg
  1. Alive

    The timer's gate enable rose and fell: a test stopped and restarted that clock.

  2. Half alive

    The UART gate enable rose at every reset and never fell. No test stopped the UART clock.

  3. Dead, and closable

    The software reset request never moved. One test that writes SOFT_RESET would move it.

  4. 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.

Five questions this page answers
Question
1What do line, branch and toggle coverage count?
2Why is a chip toggle report mostly zeros, and which zeros matter?
3What is a tied port, and how is it kept out of the way?
4What does structural coverage cost on the chip bench?
5How 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

New words on this page
WordMeaning
Line coverageWhich statements ran at least once.
Branch coverageWhich way each if or case went, counted per outcome.
Toggle coverageWhich bits rose and which fell; each bit has two directions.
Structural coverageLine, branch and toggle coverage together: counted from the design's structure, with no plan.
Tied portA block input the chip connects to a constant; connect.csv lists each one with its reason.
Per-instance countingCounting 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.

Rises and falls of each port
Port0 to 11 to 0Kind
capture00hole: no test pulsed it
event_in00hole
online00tie: it is held at 1
kick00hole
pwm33alive
irq11alive

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

  1. Rule 1: Read block ports before block insides.

    The ports are where integration shows. The insides were the block bench's.

  2. 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.

  3. 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.

  4. 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.

  5. Rule 5: Never add structural and functional percentages.

    They count different things over different totals.

  6. 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:

Icarus Verilog version 12.0 (stable), the runnable example.
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 1

Now 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.

Hit Over Total, by Block
BlockLineBranchToggle directions
u_timer17/1726/32427/998
u_crg30/3373/78257/488
u_dm2/128/3013/772
u_tap4/274/506/268
u_fabric61/62265/3068896/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.

Ports of u_crg and u_timer
Port0 to 11 to 0Reading
u_crg.uart_gate.enable80hole: no test stopped the UART clock (rule 3)
u_crg.soft_reset_req00hole: no software reset in the suite
u_crg.debug_reset_req00tie: the v1.5 debug module asks for no reset (rule 2)
u_timer.online80tie: held at 1; it rose once per run, at start
u_timer.event_in00hole: 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.

What Each Build Cost on the §6.2 Loop
BuildMedian of three runs (s)Against the bare coverage tool
The bench's own build (Verilator 5.032)5.9331.08×
Coverage tool, no coverage (5.053)5.4751.00×
With the functional sampler5.6451.03×
With line, branch and toggle counters too14.452.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

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. ap_soc's report fits in a table; a large chip's has millions of points.

  1. 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.

  2. Coverage on a subset

    Structural coverage runs weekly on a chosen suite; nightly runs keep only functional coverage.

  3. 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?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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 1

Check Yourself

Predict the outputThe test now pulses capture once. What is the first line printed?
// Toggle counting by hand: rises and falls of six single-bit ports, summed over one run.
// online is tied high, as connect.csv ties ap_timer's online input. The test pulses capture 1 time(s).
module tb;
  logic clk = 0, capture = 0, event_in = 0, online = 1'b1, kick = 0, pwm = 0, irq = 0;
  logic [5:0] now, last;
  int rise [6], fall [6];
  string note;
  function automatic string name(input int i);
    case (i) 0: return "capture"; 1: return "event_in"; 2: return "online"; 3: return "kick"; 4: return "pwm"; default: return "irq"; endcase
  endfunction
  bit started;
  assign now = {irq, pwm, kick, online, event_in, capture};
  always #5 clk = ~clk;
  always @(posedge clk) begin
    if (started) for (int i = 0; i < 6; i++) begin
      if (!last[i] && now[i]) rise[i]++;
      if (last[i] && !now[i]) fall[i]++;
    end
    last <= now;
    started <= 1;
  end
  initial begin
    repeat (2) @(negedge clk);
    repeat (3) begin pwm = 1; repeat (2) @(negedge clk); pwm = 0; repeat (2) @(negedge clk); end
    irq = 1; repeat (3) @(negedge clk); irq = 0;
    repeat (1) begin capture = 1; @(negedge clk); capture = 0; @(negedge clk); end
    repeat (2) @(negedge clk);
    for (int i = 0; i < 6; i++) begin
      note = (rise[i] && fall[i]) ? "" : "  never toggled both ways";
      $display("%-8s 0->1 %0d  1->0 %0d%s", name(i), rise[i], fall[i], note);
    end
    $finish;
  end
endmodule
Conceptu_crg.debug_reset_req never toggled. What do you do?
Conceptu_timer has every line covered but under half its toggle directions. What does that tell you?
ConceptWhy read block ports before block insides on a chip report?
ConceptThe structural build is several times slower. When should it run?

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.

Practice

Report a problem with this page