Section 10.42

Incremental validation

Definition

Incremental validation is the practice of rechecking a system after a change by repeating only the checks whose results the change could alter, and reusing the earlier results of all other checks. Every reused result needs a stated reason: each condition the result depended on, such as the code, the build settings, the tools and the test environment, is unchanged, or is changed in a way shown not to alter the result. The output is a list of checks to repeat and a justified list of results to keep.

The idea

A program has passed a long list of checks: unit tests §10.1, a fuzzing §10.9 campaign that ran for two days, a timing measurement on the device and a code review. Then one line changes. Repeating every check after every change costs days; repeating none is unsafe, because the change may have broken something a check once established. Incremental validation repeats what the change can affect and keeps the rest.

A build system, the tool that turns source files into a program, applies this idea to files: it rebuilds a file only when a file it was made from has changed. Incremental validation applies the same rule to evidence. A test result, a measurement or a proof is made from inputs, and it stays valid while those inputs stay the same. The comparison stops at the list of inputs. A build system is told the inputs of every file, while the inputs of a piece of evidence, such as a compiler option §12.3, every function the tested code calls, or the timing of other code on the same processor, must be worked out.

How it works

  1. Record the premises of each result. A premise is a condition that the result depended on: the source code of the tested part and of everything it calls, the build configuration (compiler version and options), generated files, test inputs, the test oracle §10.5 (the check that decides pass or fail), tools, hardware, environment, and the assumptions of the argument that uses the result.

  2. Describe the change. List every artifact that changed: source files, build options, tool versions, configuration, data and hardware.

  3. Follow the change to every part that depends on a changed artifact, directly or through other parts. The transitive dependency §10.43 entry explains this step: a change to a shared parser reaches every caller of the parser, and every caller of those callers.

  4. Classify each result. A result is unaffected when none of its premises is among the parts the change reaches. It is preserved when a premise changed but an argument shows that the change cannot alter what the result relies on. Otherwise it is affected.

  5. Repeat the affected checks, and add integration tests §10.2 at every interface whose behavior changed, because the old tests on either side were written for the old behavior.

  6. Decide unknowns conservatively: a result whose premises cannot be shown unaffected counts as affected.

  7. Record the decision: which results were kept, with the reason for each, and which were repeated.

Steps 1 to 4 are called change impact analysis. Choosing which existing tests to rerun after a change is called regression test §10.4 selection; a selection is called safe when it includes every test whose outcome the change could alter.

The strongest reason to keep a result is identity: the checked artifact is the same, byte for byte, as before. Equal cryptographic hashes §5.1, short fingerprints that change when any byte changes, of the old and new program files show identity directly. A reproducible build §13.8, which produces the same output bytes every time it runs on the same inputs, makes the comparison meaningful: a difference in the output then comes from a difference in the inputs.

Worked example

A shared parser reads messages whose payload may be at most 16 bytes long. Four earlier results exist.

The change raises the parser’s limit from 16 to 32 bytes by editing one constant. R1 is affected directly, because the parser itself changed. R2 is affected through a dependency: A’s code did not change, but A now receives payloads of 17 to 32 bytes. Copying a 32-byte payload into the 16-byte buffer writes 32−16=1632 - 16 = 16 bytes past its end, a buffer overflow §4.4. The old review and fuzzing campaign said nothing about such payloads, because the old parser never let them through. R3 is reached in the same way, but a short argument preserves it: B reads the length from the message and processes exactly that many bytes, with no fixed-size storage, so a longer payload changes only how many bytes enter the checksum. New tests at lengths 17 and 32 confirm the argument cheaply. R4 is unaffected: no chain of dependencies leads from the parser to the date function, so its tests are kept without being rerun. Three of the four results are examined again, after an edit to one number.

Stated precisely

Let RR be an earlier result and P(R)P(R) its premise set: the artifacts and conditions that RR depended on. Let Δ\Delta be the set of changed artifacts, and let Reach(Δ)\mathrm{Reach}(\Delta) be the set made of Δ\Delta and every artifact that depends on a member of Δ\Delta, directly or through a chain of dependencies. Then RR may be kept without repetition if P(R)∩Reach(Δ)=∅,P(R) \cap \mathrm{Reach}(\Delta) = \emptyset, where ∩\cap is set intersection and ∅\emptyset is the empty set, or if, for every premise in that intersection, an argument shows that the change leaves unaltered the property of that premise on which RR relies.

The rule is correct only when two assumptions hold, which the analysis must check, not presume.

  1. P(R)P(R) is complete: it names every condition the result depended on, including build options, tools and environment.

  2. The dependency relation is complete: it contains every way in which one artifact can influence another, including data formats, configuration, shared memory and timing, not only calls and imports.

Putting too much into Reach(Δ)\mathrm{Reach}(\Delta) only wastes work; leaving out one real dependency can keep a result that is no longer true.

Limits and common mistakes

The size of a change does not measure its effect. A one-character edit to a shared constant can affect every consumer; a large rewrite of an isolated tool may affect nothing that was claimed.

Passing the old tests again does not show that a result is unaffected. The old tests were chosen for the old behavior and may never exercise the new one.

Results about timing and memory layout depend on almost everything that runs on the same processor or is linked into the same program. Adding code anywhere can move other code in memory and change its timing, so such results are rarely preserved by a local argument.

Hidden premises are the main risk: a generated file, a compiler option, a default value in a configuration file, a different tool version or a different test machine. Even an added comment line can change the program file: in C, with assertions enabled, each assert check stores its source line number to report on failure, and the inserted line shifts those numbers. Comparing the hashes of the old and new program files catches such cases.

Reusing results across many small changes lets mistakes in the dependency analysis accumulate unseen. A full revalidation at intervals catches such mistakes. A kept result also keeps its original scope: it remains a statement about the version and conditions under which it was obtained, carried forward by the stated argument.

Questions answered

What analysis proves a previous result remains applicable after this change?

A change impact analysis of the result’s premises proves it: list every condition the earlier result depended on, follow the change through every direct and indirect dependency, and show that each premise is either untouched or changed in a way that cannot alter the property the result relies on. The premises include the tested code and everything it calls, the build configuration, the tools, the test data, the test oracle that decided pass or fail, the hardware and environment, and the assumptions of the argument that used the result.

The strongest form of the argument is identity: the checked program file is byte for byte the same, shown by equal cryptographic hashes, and it runs with the same tools in the same environment. Weaker forms argue that the change cannot matter to the property, for example that a consumer handles inputs of any length, so a raised length limit cannot break it. If any premise cannot be shown unaffected, the check must be repeated. Passing the old tests again is no proof, because they may never exercise the changed behavior.

Related entries: Transitive dependency (§10.43), Compiler correctness (§3.40), Firmware build profile (§6.44), Reproducibility versus repeatability (§11.43), Regression test (§10.4), Reproducible build (§13.8), What makes an incremental validation boundary sound (§17.19).