Merging and Closing

Merge coverage across tests and across the processor and seat modes without fooling yourself. Then close the holes that are left with the cheapest tests that reach them.

You Will Be Able To

  • Merge runs by adding counts, and say which runs may not be merged.
  • Explain what a first contributor is and why it depends on the suite order.
  • Compare what the processor and the seat each add to the same plan.
  • Choose a test to close a hole by the new bins it gives per cycle spent.
Lesson
V12.5
Time
26 min
Runs on
Your browser
Check
5 questions

Three runs, three coverage files. One run looks useless: everything it hit, the others hit too. Can you drop it? And which test do you write next?

Three Runs' Coverage OverlaidThree processor runs of the chip's coverage suite. Each fills some bins. Laid over each other, most bins are filled by several runs. A few are filled by one run only, and the rest by none.
  • Test
  • Measure
  • Result
  • Analysis
Three Runs' Coverage OverlaidThree processor runs of the chip's coverage suite. Each fills some bins. Laid over each other, most bins are filled by several runs. A few are filled by one run only, and the rest by none. test gpio on theprocessor 45 bins test dma on theprocessor 59 bins test wake on theprocessor 58 bins measure Merge counts add result Merged 95 bins hit 45 new25 new25 newone ledger
  1. test gpio on the processor45 bins
    • 45 new → Merge
  2. measure Mergecounts add
    • one ledger → Merged
  3. test dma on the processor59 bins
    • 25 new → Merge
  4. test wake on the processor58 bins
    • 25 new → Merge
  5. result Merged95 bins hit
  1. One run

    The GPIO test fills 45 bins.

  2. Add a second

    The DMA test fills 59, but only 25 are new: the others were already hit.

  3. Add a third

    The wake test adds 25 new bins, mostly in power and interrupts.

  4. The merge

    95 bins hit in all, out of 349. Every other bin stays empty, however often these three run.

Read the diagram as text
  • gpio on the processor: 45 bins
  • dma on the processor: 59 bins
  • wake on the processor: 58 bins
  • Merge: counts add
  • Merged: 95 bins hit
  • gpio on the processor → Merge: 45 new
  • dma on the processor → Merge: 25 new
  • wake on the processor → Merge: 25 new
  • Merge → Merged: one ledger

Per-run hits recorded by tools/probes/socv/record-v12-labs.mjs (perrun); merged, they equal docs/soc/chip-coverage.json.

Before You Start

Read What Coverage Means at Chip Level and Covering Chip Events, From the Bench and From C first. The lesson Choosing the Mode compares the processor and the seat. Closure at block level is in Closing Coverage Holes.

Five questions this page answers
Question
1How are two runs' coverage merged?
2Which runs must never be merged?
3What does the first contributor of a bin tell you?
4What do the processor and the seat each add?
5How do you choose the next test when cycles are limited?

The Idea: One Ledger from Many Runs

Each run of the suite writes its own counts. The plan is closed by all runs together, so their counts are merged into one ledger. A bin is hit if any run hit it. Its count is the sum of all runs' counts.

Merging has rules, because a merge can lie. Runs of two different builds have bins with the same names but different logic. A run that failed half way may have counted things that never finished. And a percentage cannot be merged at all; only counts can.

After the merge come the holes. At chip level every cycle is expensive, so you close holes the way you would spend money. The test that fills the most holes for the fewest cycles goes first.

New Words

New words on this page
WordMeaning
MergeAdding the counts of several runs into one ledger.
First contributorThe earliest run, in the declared suite order, that hit a bin.
Build fingerprintA hash of the chip, the bench and the coverage model a run used. Runs merge only when it matches.
ClosureWriting tests until every bin is hit or waived.
Cost of a testThe system cycles it takes, which is what a chip bench spends.

The Smallest Example: Three Runs, Eight Bins

Three runs report hit counts for eight bins. The counts are exercise values; the cycle costs are those of three E11 runs. Merge them by hand.

Hits per run
BingpiodmawakeMerged
visit.gpio3003
dma.write.sram0202
window.sysctl1102
irq.claimed.90011
gate.uart.shut000hole
power.state.off0011
pin.io9.sel12002
debug.step000hole

Costs: gpio 580 cycles, dma 751 cycles, wake 356 cycles. Exercise counts; the example below merges them.

window.sysctl was hit by gpio and by dma. Its first contributor is gpio, because gpio comes first in the order. Reverse the order and the first contributor becomes dma, but the merged count stays 2. Order decides who gets the credit, never what is covered.

The Rules

  1. Rule 1: Merge counts, never percentages.

    A bin hit in one run of eight is hit. The mean of the runs' percentages hides it.

  2. Rule 2: Merge only runs of one build.

    The chip's merge refuses runs whose build fingerprints differ.

  3. Rule 3: Merge only passing runs.

    A failing run may have stopped half way, so its counts describe a scenario that never finished.

  4. Rule 4: The order decides first contributors, not hits.

    Declare the suite order; reorder it and only the credit moves.

  5. Rule 5: Close a hole with the cheapest test that reaches it.

    Rank candidate tests by new bins per cycle. Write a directed test when random runs keep missing.

  6. Rule 6: A run that adds nothing still has a job.

    It may add no coverage, yet its checks still catch bugs. Drop it from the coverage suite only, never from the regression.

Sources for These Rules

The merge of the chip ledger takes only passing runs and adds counts. The first contributor follows the declared suite order. Differing fingerprints and duplicate orders are refused. No percentage is averaged. Sources: tools/soc/ap_soc/bench/soc_tb/README.md, "Chip coverage (E11)"; facts §27.15; coverage/report.mjs.

A coverage problem's runs are merged the same way. Their cycles are summed against a budget with 10% margin: tools/soc-coverage-plan.mjs; facts §27.19.

Cover only what is of interest, so that every hole means something: MEHTA-DV 7.10.1 (PDF p167). The ranking by new bins per cycle is this lesson's method, computed from the recording.

The Lab: Merging the Chip's Eight Runs

First the toy, on the site's Icarus:

Icarus Verilog version 12.0 (stable), the runnable example (exercise counts).
visit.gpio       3 hits, first: gpio
dma.write.sram   2 hits, first: dma
window.sysctl    2 hits, first: gpio
irq.claimed.9    1 hits, first: wake
gate.uart.shut   hole
power.state.off  1 hits, first: wake
pin.io9.sel1     2 hits, first: gpio
debug.step       hole
6 bins hit, 2 holes, 1687 cycles in all

Rule 4 shows when the order is reversed: only the first contributor of window.sysctl changes, from gpio to dma.

Now the chip. Each of the eight E11 runs was recorded with its own counts. Merged, they give the published ledger exactly: 143 bins hit of 349. Here are six bins, run by run:

Six Bins, Eight Runs
Bingpio cpugpio bfmdma cpudma bfmtimer cputimer bfmwake cpuwake bfmMerged
visit.core.gpio700000007
irq.claimed.9000000112
dma.write.sram0066000012
window.bfm.sysctl0303020412
gate.timer.shut000000112
debug.step000000000

record-v12-labs.mjs perrun (the functional build of the coverage bench).

Read the rows. The bin visit.core.gpio comes only from processor runs. The bin window.bfm.sysctl comes only from seat runs: the bins name the mode. Both wake runs hit irq.claimed.9. And debug.step is zero everywhere, so merging more of the same runs will never fill it.

What Each Mode Added
ModeRunsBins hitHit in this mode onlySystem cycles
processor (cpu)4106432019
seat (bfm)410037468

From the same eight runs.

The processor runs cost 4.3 times the cycles of the seat runs, for boot code and an interpreter. They also fill 43 bins the seat never can, such as interrupts taken by the core. The seat fills 37 of its own. Both modes earn their place in the merge.

Rule 5 turns this into a ranking. Take the run with the most new bins per cycle and add its bins. Then rank the rest again against what is now hit:

The Eight Runs, Ranked by New Bins per Cycle
PickRunCyclesNew binsNew per 100 cyclesBins hit so farCycles so far
1timer bfm624166.14162
2wake bfm1372417.565199
3dma bfm1952713.892394
4gpio bfm74810.8100468
5timer cpu332216.3121800
6wake cpu35672.01281156
7dma cpu751101.31381907
8gpio cpu58050.91432487

Computed from the per-run recording when the site is built. A run's new bins depend on the picks before it.

The cheap runs come first. After 3 picks and 394 of the 2487 cycles, 92 of the 143 bins are hit. The last pick adds 5 bins for 580 cycles. On a budget, that tail is where a short directed test that reaches the same bins pays off. Rule 6 still holds: a run you rank last may stay in the regression for its checks.

The coverage problems of this track merge the same way. At stage E15 the check of that merge took two complementary runs in either order and got the same result. It also refused a run over its budget. A problem graded on a budget is graded on the merged count and the summed cycles.

Why It Is Built This Way

Why fingerprint every run? A merge of runs from two builds can look perfect and mean nothing. A bin of the old build may sit on logic that no longer exists. The fingerprint hashes the chip, the bench and the sampler, so the merge cannot mix them by accident.

Why keep the first contributor at all, if order is arbitrary? Because it answers a practical question: which single run would I need to keep that bin? With a fixed order, it shows which runs add nothing new, which is where suite time can be saved.

Traps

The first trap is merging a failing run. A test fails half way through a power cycle, after the sleep but before the wake. Its counts fill the sleep bins. Merged, the ledger says the power cycle was covered, and no passing test ever finished one.

The second trap is the run that seems useless. The seat's timer run adds few new bins after the processor's timer run, so it is dropped from the regression. A month later a bug shows only when the seat drives the bus, and nothing runs that test any more.

The third trap is closure by repetition. A hole stays open, so the team adds seeds to the random runs, night after night. The hole needs a stimulus the random generator never makes, and only a directed test fills it.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. Eight runs merge in a moment; a chip's nightly thousands do not.

  1. Ranked suites

    Tools rank tests by their unique contribution and build a short suite that keeps the same coverage for quick checks.

  2. Coverage-driven generation

    Some flows steer random stimulus toward open bins automatically, run after run.

  3. Merging across levels

    Block, subsystem and chip ledgers are merged by owner, each counting only its own plan.

Try It

Run it: merged hits, first contributors, holes and total cost.

Reverse the order of the three runs. Which line changes, and which stay the same?

Add a fourth run that hits only gate.uart.shut. What does the last line say?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: visit.gpio 3 hits, first: gpio dma.write.sram 2 hits, first: dma window.sysctl 2 hits, first: gpio irq.claimed.9 1 hits, first: wake gate.uart.shut hole power.state.off 1 hits, first: wake pin.io9.sel1 2 hits, first: gpio debug.step hole 6 bins hit, 2 holes, 1687 cycles in all

Check Yourself

Predict the outputThe three runs are merged in reverse order: wake, dma, gpio. What is the third line printed?
// Merging hit counts across runs: counts add, the first contributor follows the suite order, a zero is a hole.
module tb;
  string bin [8], test [3];
  int cost [3], hits [3][8];
  int merged [8], first [8], holes = 0, total = 0;
  initial begin
    bin[0] = "visit.gpio";
    bin[1] = "dma.write.sram";
    bin[2] = "window.sysctl";
    bin[3] = "irq.claimed.9";
    bin[4] = "gate.uart.shut";
    bin[5] = "power.state.off";
    bin[6] = "pin.io9.sel1";
    bin[7] = "debug.step";
    test[0] = "wake"; cost[0] = 356;
    hits[0][0] = 0;
    hits[0][1] = 0;
    hits[0][2] = 0;
    hits[0][3] = 1;
    hits[0][4] = 0;
    hits[0][5] = 1;
    hits[0][6] = 0;
    hits[0][7] = 0;
    test[1] = "dma"; cost[1] = 751;
    hits[1][0] = 0;
    hits[1][1] = 2;
    hits[1][2] = 1;
    hits[1][3] = 0;
    hits[1][4] = 0;
    hits[1][5] = 0;
    hits[1][6] = 0;
    hits[1][7] = 0;
    test[2] = "gpio"; cost[2] = 580;
    hits[2][0] = 3;
    hits[2][1] = 0;
    hits[2][2] = 1;
    hits[2][3] = 0;
    hits[2][4] = 0;
    hits[2][5] = 0;
    hits[2][6] = 2;
    hits[2][7] = 0;
    for (int b = 0; b < 8; b++) begin merged[b] = 0; first[b] = -1; end
    for (int r = 0; r < 3; r++) begin
      total += cost[r];
      for (int b = 0; b < 8; b++) begin
        merged[b] += hits[r][b];
        if (hits[r][b] > 0 && first[b] < 0) first[b] = r;
      end
    end
    for (int b = 0; b < 8; b++)
      if (merged[b] > 0) $display("%-16s %0d hits, first: %s", bin[b], merged[b], test[first[b]]);
      else begin $display("%-16s hole", bin[b]); holes++; end
    $display("%0d bins hit, %0d holes, %0d cycles in all", 8 - holes, holes, total);
  end
endmodule
ConceptTwo runs come from builds with different fingerprints. What does the merge do?
ConceptWhat does reordering the suite change in the merged ledger?
ConceptWhy do the processor runs fill bins the seat runs never can?
ConceptA hole stays open after many random seeds. What is the next step?

Common Mistakes

Wrong Report the mean of the runs' coverage percentages.

A bin hit in one run is hit, but the mean hides it.

Fix Add counts per bin and count the bins hit.

Wrong Merge a run that failed.

It may have counted the first half of a scenario that never finished.

Fix Merge only passing runs.

Wrong Drop a test from the regression because it adds no new coverage.

Its checks may still catch bugs the others miss.

Fix Drop it from the coverage suite only, if at all.

Remember

  • Merge counts, never percentages, and only from passing runs of one build.
  • Order decides first contributors, not coverage.
  • Both modes add bins the other cannot reach.
  • Close holes by new bins per cycle, with directed tests where random runs keep missing.

Practice

Report a problem with this page