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?
- Test
- Measure
- Result
- Analysis
- One run
The GPIO test fills 45 bins.
- Add a second
The DMA test fills 59, but only 25 are new: the others were already hit.
- Add a third
The wake test adds 25 new bins, mostly in power and interrupts.
- 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.
| Question | |
|---|---|
| 1 | How are two runs' coverage merged? |
| 2 | Which runs must never be merged? |
| 3 | What does the first contributor of a bin tell you? |
| 4 | What do the processor and the seat each add? |
| 5 | How 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
| Word | Meaning |
|---|---|
| Merge | Adding the counts of several runs into one ledger. |
| First contributor | The earliest run, in the declared suite order, that hit a bin. |
| Build fingerprint | A hash of the chip, the bench and the coverage model a run used. Runs merge only when it matches. |
| Closure | Writing tests until every bin is hit or waived. |
| Cost of a test | The 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.
| Bin | gpio | dma | wake | Merged |
|---|---|---|---|---|
| visit.gpio | 3 | 0 | 0 | 3 |
| dma.write.sram | 0 | 2 | 0 | 2 |
| window.sysctl | 1 | 1 | 0 | 2 |
| irq.claimed.9 | 0 | 0 | 1 | 1 |
| gate.uart.shut | 0 | 0 | 0 | hole |
| power.state.off | 0 | 0 | 1 | 1 |
| pin.io9.sel1 | 2 | 0 | 0 | 2 |
| debug.step | 0 | 0 | 0 | hole |
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
Rule 1: Merge counts, never percentages.
A bin hit in one run of eight is hit. The mean of the runs' percentages hides it.
Rule 2: Merge only runs of one build.
The chip's merge refuses runs whose build fingerprints differ.
Rule 3: Merge only passing runs.
A failing run may have stopped half way, so its counts describe a scenario that never finished.
Rule 4: The order decides first contributors, not hits.
Declare the suite order; reorder it and only the credit moves.
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.
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:
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 allRule 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:
| Bin | gpio cpu | gpio bfm | dma cpu | dma bfm | timer cpu | timer bfm | wake cpu | wake bfm | Merged |
|---|---|---|---|---|---|---|---|---|---|
| visit.core.gpio | 7 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7 |
| irq.claimed.9 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 2 |
| dma.write.sram | 0 | 0 | 6 | 6 | 0 | 0 | 0 | 0 | 12 |
| window.bfm.sysctl | 0 | 3 | 0 | 3 | 0 | 2 | 0 | 4 | 12 |
| gate.timer.shut | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 2 |
| debug.step | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
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.
| Mode | Runs | Bins hit | Hit in this mode only | System cycles |
|---|---|---|---|---|
| processor (cpu) | 4 | 106 | 43 | 2019 |
| seat (bfm) | 4 | 100 | 37 | 468 |
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:
| Pick | Run | Cycles | New bins | New per 100 cycles | Bins hit so far | Cycles so far |
|---|---|---|---|---|---|---|
| 1 | timer bfm | 62 | 41 | 66.1 | 41 | 62 |
| 2 | wake bfm | 137 | 24 | 17.5 | 65 | 199 |
| 3 | dma bfm | 195 | 27 | 13.8 | 92 | 394 |
| 4 | gpio bfm | 74 | 8 | 10.8 | 100 | 468 |
| 5 | timer cpu | 332 | 21 | 6.3 | 121 | 800 |
| 6 | wake cpu | 356 | 7 | 2.0 | 128 | 1156 |
| 7 | dma cpu | 751 | 10 | 1.3 | 138 | 1907 |
| 8 | gpio cpu | 580 | 5 | 0.9 | 143 | 2487 |
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
This section looks ahead. Eight runs merge in a moment; a chip's nightly thousands do not.
Ranked suites
Tools rank tests by their unique contribution and build a short suite that keeps the same coverage for quick checks.
Coverage-driven generation
Some flows steer random stimulus toward open bins automatically, run after run.
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?
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 allCheck Yourself
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.