Techniqueresearch
Coverage-directed test generation
Also called CDG, Fine-Ziv coverage-directed generation.
Closes the loop between coverage and stimulus, for example by a Bayesian network that learns which generator settings hit which coverage holes, as in Fine and Ziv.
Coverage-directed test generation (CDG) closes the loop between the coverage report of a simulation regression and the settings of the random stimulus generator that drives it. Here a test means a simulation stimulus, a program or sequence of transactions for a design under verification; it is not a manufacturing test of a chip. A constrained random generator takes parameters, called directives by Fine and Ziv (weights, ranges, modes), and produces many stimuli from each setting. CDG learns from past runs which settings tend to hit which coverage events, and chooses settings that should hit the events no run has hit yet, the coverage holes. Fine and Ziv (2003) learn this relation with a Bayesian network; others use genetic algorithms, bandits or other learned models. The method is a heuristic: what can be proved is the arithmetic of one step, and how much it shortens closure is only measured.
In plain words
A random generator makes test inputs for a chip design, and it has knobs: how long the bursts are, how often an interrupt comes, which instructions appear most. The team watches a list of situations that the tests should produce. Some situations are rare, and plain random runs almost never reach them.
Instead of turning the knobs by hand, the team records, for many past runs, the knob settings and the situations each run reached. A model learns from these records which settings make which situations likely. To reach a situation that no run has reached, the team asks the model for the most promising settings, runs with them, adds the new records, and asks again.
The model is only a guess. It cannot reach a situation that the design never allows, and it only chases the situations that someone listed.
When it applies
- A parametrized generator. The stimulus comes from a random generator with a finite set of directives , each with a finite domain, and each setting gives a distribution over stimuli. Constrained random stimulus generation is the usual source.
- A coverage model. A finite set of events , such as bins of a functional coverage model, and a monitor that reports which of them a run hit.
- Many cheap runs. The model learns from data, so it needs a few hundred or thousand runs over varied settings, and simulation must be cheap enough to give them.
- Holes that the generator can reach. Some setting must give the hole a probability that is not tiny. If the hole needs a sequence that no setting makes likely, a directed test or a formal witness from a bounded model checker fits better. If the hole is unreachable in the design, no generator hits it, and the hole should be proved unreachable and removed.
The template
1. Collect data. Run the generator with settings , chosen at random over the directive domains, one or more runs per setting. For each run record the setting and the vector of events that it hit.
2. Fix the structure. Write a network whose root nodes are the directives, whose leaf nodes are the coverage events, and whose inner nodes stand for intermediate quantities, such as the instruction mix or "the queue was full". The edges come from what the engineers know about the generator and the design; this is the part that needs expertise. The joint law factors as
over all nodes , where are the parents of and are the inner nodes.
3. Learn the tables. Estimate each conditional table from the data. For observed nodes, count: with runs in which the parents of take the values , and of them with , a smoothed estimate is . For inner nodes that the monitor does not record, use expectation maximization.
4. Query. For a hole , compute for candidate settings by exact inference in the network (for example variable elimination) and pick
For a set of holes, pick the that maximizes the expected number of new hits per run, . The two objectives can choose different settings.
5. Run and repeat. Simulate with , add the runs to the data, update the tables, and query again. Stop when the holes are hit, or when the model gives every remaining hole a very small probability under every setting; such holes go to a directed test or to a formal tool.
What can be proved about one step.
- Expected new hits. If a run with setting hits with probability , the expected number of holes of that the run hits is , by linearity of expectation over the indicators of the events; no independence between events is needed.
- Waiting time. Runs with a fixed setting are independent, so the number of runs until is first hit has a geometric distribution with mean .
- Two forms of the query. The query can also ask for the setting that is most probable given that the hole is hit, . By Bayes' theorem, . So the two forms choose the same setting when the prior is uniform over the candidates, and they can differ when it is not.
These facts are about the true probabilities . The network gives estimates of them, and how close the estimates are depends on the data and on the structure. That the loop closes coverage faster than plain random runs is a measured result of the papers, not a theorem.
Classic examples
A FIFO with two knobs. A generator has the directives = burst length in and = read rate in . The event is "the FIFO became full in the run". Forty runs per setting, 160 in all, gave these counts.
| setting | runs | runs with | smoothed estimate |
|---|---|---|---|
| short, slow | 40 | 2 | 3/42 |
| short, fast | 40 | 0 | 1/42 |
| long, slow | 40 | 14 | 15/42 |
| long, fast | 40 | 3 | 4/42 |
The query picks (long, slow). With settings drawn uniformly, the observed hit rate per run is , so the expected wait for a hit is about runs. With (long, slow) the observed rate is , a wait of about runs. The training prior was uniform, so the posterior form gives the same choice: is proportional to the counts .
A hole, reached through structure. Add a third directive = flush rate in , drawn at random in each run, and the event = "the run issued a flush". The coverage task = "the run filled the FIFO and issued a flush" was never hit. In the network, has parents ; has parent ; and is the AND of and . The structure says that and are independent given the directives, so
If the runs gave , the model predicts for (long, slow, high), the best setting, although has no hit in the data. This is how a network can rank settings for a hole: the hole shares parents with events that were hit. The prediction rests on the independence that the structure assumes; if a flush empties the FIFO, the assumption is wrong and the runs will show it.
Fine and Ziv (2003). The first network-based CDG, for the generator of stimuli of a processor design. The directives are the inputs of the network, the coverage events its outputs, and the inner nodes encode knowledge of the design. The network is trained on simulation runs and queried for directives that hit uncovered events. Braun, Fine and Ziv (2004) improved its efficiency.
Variations
- Genetic algorithms. Treat a setting of the directives as a genome, its fitness as the coverage that its runs add, and evolve a population with a genetic algorithm. No structure needs to be written, and many more runs are needed. The review of Ioannides and Eder surveys this family, with genetic programming and other learned models.
- Bandits. With a fixed list of candidate settings and the reward "new events hit by the run", the choice of setting is a multi-armed bandit; Thompson sampling keeps a posterior per setting and balances trying new settings against using the best one. The reward changes as holes are filled, which the basic bandit model does not allow.
- Formal help. For a hole that random settings miss, a bounded model checker given the event as a cover goal returns a trace, or a proof that the event cannot happen within the bound. The trace can be replayed as a directed test, or used to tune the constraints.
- Software analogues. Coverage-guided fuzzing closes the same loop for programs, but changes the inputs themselves, not the parameters of a generator.
Pitfalls
- Settings that never vary. If a directive kept one value in all training runs, the data say nothing about its other values, and the network cannot rank them. Draw the training settings at random over the domains; because the directives are set by the engineer and not observed, the learned dependence of events on directives is causal.
- A non-uniform prior. The query favors settings that were tried often. If in the FIFO example the setting (long, fast) had run 400 times with 30 hits, a rate of , the posterior would prefer it ( of the hits) over (long, slow) with a rate of . Ask for , or divide by the prior.
- Zero counts. A table with estimates the probability as 0 and the setting is never tried again. Smooth the estimates.
- One setting for everything. Running only hits the target hole and stops exploring the rest of the stimulus space, where bugs that no event describes may be. Keep a share of runs at random settings.
- The model is the limit. CDG fills holes of the coverage model. A situation that no event describes is never a target, and a hit is still not a check: the response must be judged by checkers or assertions.
- Unreachable holes. An event that the design cannot produce stays at probability near 0 under every setting, and the loop runs forever unless it stops on a threshold and sends the hole to a formal tool.
Exercises
- In the FIFO example, a second event has the hit counts for the four settings in the order of the table. Which single setting maximizes the expected number of hits of per run, using the observed rates?
- Prove that the expected number of runs with a fixed setting until is first hit is , and that the probability that runs miss it is .
- Show that and agree for every event when is uniform, and give a two-setting example where they differ otherwise.
- In the hole example, suppose a flush always empties the FIFO before it can be full in the same run. Which edge is missing from the network, and what does the model predict for after it is added?
- A setting has 0 hits in 50 runs. Compare the raw estimate, the smoothed estimate , and the upper end of a one-sided 95 percent bound .
References
- Shai Fine and Avi Ziv, Coverage directed test generation for functional verification using Bayesian networks, Proceedings of the 40th Design Automation Conference, 286 to 291, 2003, the Bayesian network whose inputs are the directives of the test generator and whose outputs are coverage events, its training on simulation runs, and its use to choose directives for uncovered events
- M. Braun, S. Fine and A. Ziv, Enhancing the efficiency of Bayesian network based coverage directed test generation, Proceedings of the Ninth IEEE International High-Level Design Validation and Test Workshop, 75 to 80, 2004, the improvements of the Bayesian network method of Fine and Ziv (general locator)
- Charalambos Ioannides and Kerstin I. Eder, Coverage-directed test generation automated by machine learning, a review, ACM Transactions on Design Automation of Electronic Systems 17(1), 2012, the survey of coverage-directed generation by Bayesian networks, genetic algorithms, genetic programming, Markov models and inductive logic programming (general locator)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag BA1EWQ Edit this page History Report an error Markdown