Section 10.33

Exhaustive enumeration

Definition

Exhaustive enumeration is checking a property on every case in a finite, explicitly defined set of cases, instead of on a sample of them. The set is defined by its dimensions (the inputs, initial states and operation sequences that vary) and by a bound on each, such as the bit width of a value or the length of a sequence. If every case ran and the oracle that judges each case is correct, a pass shows that the property holds on the whole set, and nothing about cases outside it.

The idea

Sampling leaves gaps: a property checked on a million random inputs can still fail on the one input that was never drawn. When the set of cases is small enough, running every case closes the gap. A function of one 8-bit input has 256 cases. A function of one 32-bit input has 232=4,294,967,2962^{32} = 4{,}294{,}967{,}296 cases, which a computer doing 10910^9 checks per second runs in about 4.3 seconds. Inside such a set, checking every case turns testing into proof.

The price is that the claim is exactly as wide as the set. Two 32-bit inputs already give 2642^{64} cases, about 585 years at 10910^9 checks per second. Real enumerations therefore work on scaled-down domains: values of 2 or 3 bits, a few states, sequences of a few steps. The force of the result comes from stating that domain exactly. Its usefulness comes from choosing the small domain so that it still contains the kinds of behavior that matter.

How it works

  1. Define the domain. List every dimension that varies and its bound: the width or range of each input value, the initial states, the operations, the largest sequence length and, for concurrent code, the thread interleavings, the orders in which the steps of different threads can run. List every dimension held fixed, such as the configuration, the memory size and the timing.

  2. Define the oracle. The test oracle §10.5 is the rule that decides whether each case passes. State the property it checks and where its correct answer comes from, for example a simple reference implementation that uses exact arithmetic.

  3. Count before running. The number of cases is the product of the numbers of values of the dimensions. Write it down.

  4. Prune only with a reason. Leave out cases, such as sequences the system can never reach, only with an argument that they are impossible or cannot behave differently from cases kept. Record each rule and how many cases it removed.

  5. Run every case and account for it. Compare the numbers of cases run, passed, failed, skipped and timed out with the count from step 3. A skipped or timed-out case is not a passed case; while any remain, the enumeration is not exhaustive.

Sequences of operations grow fast. With ss initial states and aa possible operations at each step, there are s×aks \times a^k sequences of exactly kk steps. With 3 initial states and 2 operations, that is 3×22=123 \times 2^2 = 12 sequences of 2 steps but 3×220=3,145,7283 \times 2^{20} = 3{,}145{,}728 sequences of 20 steps. This exponential growth, called state explosion §3.26, is why every enumeration of sequences has a length bound.

Model checking §3.30, which explores every reachable state §3.21 of a finite model, and bounded model checking §3.29, which covers every execution up to a fixed number of steps, are exhaustive in the same sense. They do the work by systematic search or with a solver for logical constraints instead of one test run per case.

Worked example

A range check decides whether a read of nn bytes at offset oo fits inside an object of ss bytes. The specification is o+n≤so + n \le s in ordinary arithmetic. Two implementations are compared. The naive check computes o+no + n in the machine’s unsigned arithmetic, which wraps around, and compares the result with ss. The overflow-safe range check §4.17 tests o≤so \le s and then n≤s−on \le s - o.

The real machine uses 32-bit values, which gives 232×3=296≈7.9×10282^{32 \times 3} = 2^{96} \approx 7.9 \times 10^{28} triples (o,n,s)(o, n, s), about 2.5×10122.5 \times 10^{12} years of work at 10910^9 checks per second. The enumeration therefore scales the width down to 2 bits and keeps the same kind of arithmetic: every value lies between 0 and 3, and a sum wraps around modulo 22=42^2 = 4. The domain has 4×4×4=644 \times 4 \times 4 = 64 cases. The oracle evaluates o+n≤so + n \le s with exact integers.

The overflow-safe check agrees with the oracle in all 64 cases. The naive check disagrees in 20 cases, and in all 20 the sum o+no + n is at least 4 and wraps:

That makes 12+6+2=2012 + 6 + 2 = 20. The specification refuses all 20, because o+n≥4>3≥so + n \ge 4 > 3 \ge s.

The run established that the overflow-safe check is correct for every 2-bit triple and that the naive check is wrong for exactly 20 of the 64. It established nothing about 32-bit values. The 2-bit failure points to the same failure at 32 bits, o=1o = 1 and n=232−1n = 2^{32} - 1, whose sum wraps to 0; a direct test confirms it. The 2-bit success of the safe check carries over to 32 bits only with an argument that does not depend on the width, here algebra: when o≤so \le s, the subtraction s−os - o cannot wrap, and n≤s−on \le s - o then says the same as o+n≤so + n \le s.

Stated precisely

Let the dimensions have the finite value sets D1,…,DkD_1, \dots, D_k. Let the domain DD be a set of tuples (d1,…,dk)(d_1, \dots, d_k), with each did_i taken from DiD_i, possibly restricted by a stated condition such as reachability. Let OO be the oracle. Exhaustive enumeration establishes O(d)=passfor every d∈DO(d) = \text{pass} \quad \text{for every } d \in D when four conditions hold, each checked, not assumed.

  1. Completeness: the generator produced every element of DD; the number of cases run equals |D||D|, the number of elements of DD, which is |D1|×…×|Dk||D_1| \times \dots \times |D_k| before any restriction.

  2. Completion: every case ran to a verdict; none was skipped, crashed the test harness or timed out.

  3. A correct oracle: OO passes exactly the cases that satisfy the property.

  4. Correspondence: what ran behaves like the thing the claim is about, such as the real code built the same way, or a model whose agreement with the code has been argued.

The conclusion covers DD and nothing outside it.

Checking every operation sequence of up to kk steps shows that no violation of a safety property §1.11, a property saying that something bad never happens, occurs within kk steps; a longer sequence may still violate it. A liveness property §1.12, which says that something good eventually happens, is never violated by a finite sequence alone, so checking finite sequences one at a time cannot establish it. A model checker establishes liveness for a finite model by searching the graph of reachable states for a cycle in which the good event never happens.

Small scopes and scaled-down domains

Most enumerations use a domain far smaller than the real one, for example version numbers 0 to 3 instead of 32-bit numbers, or two possible values for a nonce §5.18, a number meant to be used only once, instead of 21282^{128}. Two arguments connect such a result to the real system.

The small-scope hypothesis, stated by Daniel Jackson for the Alloy analyzer, a tool that checks a design against every instance up to a size bound called the scope, says that most errors have small counterexamples: cases with few objects or few steps that already show the error. It is an observation from experience, supported by some empirical studies, not a theorem. A clean result in a small scope is good evidence that a design has no shallow errors, not a proof that it has none.

A finite-domain abstraction replaces a large domain with a small one chosen so that the behavior the property depends on survives.

What lies outside a scaled-down domain must be listed as outside: behavior at the real largest value, where a counter wraps or a table is full; the probability of rare events, such as two random 128-bit values being equal, which a model with two possible values makes common or rules out; limits on memory and storage; timing; and every dimension held fixed, such as power failing in the middle of a write.

Limits and common mistakes

A wrong oracle approves wrong behavior in every case. If the oracle shares an error with the implementation, for example because both were written from the same misreading of the specification, the enumeration passes completely and proves nothing.

A generator meant to produce every case can silently produce fewer, for example through a loop bound that stops one value short of the largest value. Comparing the number of cases run with the computed size of the domain catches this; a count of passes alone does not.

Exhaustive over a domain is not exhaustive over the program. Other inputs, configurations, compilers and hardware lie outside the result unless they were dimensions of the domain.

Questions answered

Exactly which dimensions and bounds were enumerated?

A claim of exhaustive enumeration must state every dimension that varied with its exact bound, every dimension held fixed, the oracle, every rule that pruned cases, and the number of cases run compared with the size of the domain. A complete answer has this shape.

The result then holds for exactly that domain. Extending it to the real system, for example from 2-bit to 32-bit values, needs a separate argument: a proof that the property does not depend on the width, or weaker evidence such as the small-scope hypothesis, the observation that most errors already show up in small cases, which supports the extension but does not prove it.

Related entries: Test oracle (§10.5), Model-based testing (§10.34), Signed versus unsigned comparison (§2.12), Bounded model checking (§3.29), Model checking (§3.30), State explosion (§3.26), Overflow-safe range check (§4.17). Further reading: [494].