Definition
A mechanism is the part of a system meant to produce a property: a check in the code, a hardware setting, a rule in a protocol. Evidence is what supports the claim that the property actually holds, together with the conditions under which it was obtained: a reading of the code, a test result, a measurement or a proof. The difference that matters: a mechanism says what should happen; evidence says what was shown to happen, for which artifact, inputs and conditions. Each kind of evidence has its own scope.
The idea
A report states: “out-of-bounds reads §4.5 are rejected”. One reviewer reads the source code and finds a bounds check before the read. Another runs a test that asks for an out-of-bounds read and sees it rejected. Both are evidence, but of different things. The reading shows why the read is rejected and on which paths, for every input that reaches those paths. But the program that actually runs is a binary built from some source, by some compiler, with some settings, and the reading does not show that this binary came from that source. The test shows that the binary that was run rejected one particular read. It shows nothing about inputs that nobody tried.
A fire door is a fair picture. The building plan shows a fire door on every floor: that is the mechanism, and reading the plan shows it on all floors at once. A fire drill shows that the doors on the floors tested actually closed: that is evidence about the real building. Neither replaces the other. The picture stops in one respect. A building rarely differs from its plan without anyone noticing, but a program easily differs from the source that was read, through a different source version, a build setting, or a second code path that the reviewer never read.
How it works
Each method of gathering evidence has a scope: the set of situations its result covers.
Code inspection, reading the source by hand, covers every input on the paths that were read, and explains why the result holds. It does not cover the compiled binary, the hardware, costs such as time and memory, or paths the reader did not read, and it depends on the reader making no mistakes.
Static analysis §3.1, a tool that examines code without running it, covers every path in the tool’s model of the program. A sound tool, one that never misses a real violation of the property it checks, may still raise false alarms §1.22.
Testing, running the program on chosen inputs and comparing the results with the expected ones, covers the inputs tried, on the build tested. One failing test refutes a claim about all inputs; passing tests prove such a claim only if they try every possible input.
Benchmarking, running a fixed workload many times under controlled conditions and recording time, memory or other costs, covers the costs of those runs on that build and that hardware. It shows real costs that no reading of the source reveals, but its largest observed value is only a lower bound on the true worst case.
Proof covers every input of a mathematical model of the program, provided the model matches the implementation.
Testing and benchmarking are forms of dynamic analysis §3.2, analysis by running the program.
To connect evidence to a claim:
State the claim exactly, including what it ranges over: one run, all inputs, or all builds.
Name the mechanism that is meant to deliver it.
Choose evidence whose scope matches the claim. A claim about all inputs needs inspection, static analysis or proof; a claim about cost on real hardware needs measurement; a claim about the shipped binary needs tests of that binary.
Tie every piece of evidence to the artifact it concerns: the source version, the build settings, a cryptographic hash §5.1 of the binary (a short fingerprint computed from its bytes; for a collision-resistant §5.5 hash, nobody can find two different binaries with the same fingerprint), the hardware and the configuration. Recording where an artifact came from in this way is artifact provenance §13.1. A reproducible build §13.8, one that produces bit-for-bit the same binary from the same source and settings, lets anyone check that a binary matches a source.
Record what remains assumed.
Worked example
A program reads a 4-byte value from a buffer of bytes, whose valid positions are 0 to 15, starting at a position that the input chooses. The read touches positions to , so it stays inside the buffer exactly when . Positions and lengths are 32-bit unsigned integers, whole numbers from 0 to stored in 32 bits, so every sum is computed modulo : a sum that reaches wraps around to a small number. The check can be written in two ways:
version A: allow the read if ;
version B: allow the read if , where cannot wrap around because .
A test. The input asks for positions 14 to 17, and positions 16 and 17 lie outside the buffer. Version A computes and is false, so it rejects the read. Version B computes and is false, so it also rejects. The test passes under both versions, so it cannot tell them apart.
An inspection. A reviewer who reads version A asks what happens at the largest positions. Take . Then , which wraps around to 2, and is true: version A allows a read far outside the buffer. Version B compares , which is false, and rejects. Exactly 4 values of , from to , wrap around in version A, so a test that picks at random hits one with probability . Reading the code finds the flaw at once and shows that version B is correct for all values of .
A benchmark. Inspection cannot say what the check costs. Suppose 1,000 runs of the read with version B, on a processor that executes 64 million clock cycles per second, take between 25 and 31 cycles each. The slowest observed run took seconds, which is about 0.48 microseconds. That is a real cost of that build on that hardware, which no reading of the source gives. It is not a worst-case bound: a run interrupted by other work, or one that waited for slow memory, could take longer and simply did not occur among these 1,000 runs. A bound on the worst-case execution time §9.33, the longest time the code can take on any input and in any situation, needs an analysis of the code and the hardware, not only observations.
Connecting the two. The inspection covers the source; the test and the benchmark cover a binary. If the binary was built from a different version of the source, or with a setting that removes the check, the inspection says nothing about it. Recording the source version and the hash of the tested binary, and rebuilding to the same hash, connects the two. If the program also has a second execution path, such as a just-in-time compiler §2.14 that turns it into machine code when it is loaded, that path contains its own check, which needs its own inspection and its own tests.
Stated precisely
An evidence statement has four parts:
the claim;
the method: inspection, static analysis, test, measurement or proof;
the scope: the artifact, inputs, configuration and conditions that the method actually covered;
the remaining assumptions: what must hold for the result to apply beyond its scope, such as “the shipped binary is the tested binary”.
For the test above: the claim is that the read at position 14 is rejected; the method is controlled execution with the result observed; the scope is that binary and that input; the remaining assumptions are that the result was recorded faithfully and that the run used the intended configuration.
Let a claim state that a property holds for every element of a set , whose elements may be inputs, runs or builds, and let the evidence cover a subset of . The evidence establishes the claim only if , or if a separate argument extends the result from to all of . One element of on which the property fails refutes the claim. For a measured quantity, the largest observed value is a lower bound on the true maximum, never an upper bound.
Limits and common mistakes
A mechanism that is present is not a mechanism that works. A check can exist and test the wrong variable, sit on one path but not on another, or be removed by a build setting.
Agreement between inspection and tests is not a certificate for everything. It supports the specific claim that both address, within the narrower of their two scopes.
A polished graph, a passing exit code §13.24 or a long checklist is evidence only of what it actually measured or checked.
Missing runs change conclusions. Runs that crashed, were refused or were excluded by a selection rule must be reported, because leaving them out can make accurately reported values misleading.
A reviewer’s approval has a scope too: the files read, the claims checked and the calculations redone.
A claim about the future, such as a maximum running time, cannot rest on observation alone; it needs an analysis whose assumptions are stated.
Planned, attempted, completed and accepted are different states of an experiment. Reporting a planned measurement as a result is a false claim.
Questions answered
What does code inspection establish that a benchmark does not, and vice versa?
Code inspection establishes properties of the source code that hold for every input on the paths that were read, such as which check runs before which action and whether a check is written so that arithmetic wraparound cannot defeat it; a benchmark cannot establish these, because it exercises only the inputs and paths it actually ran. Code inspection is reading the source by hand. A benchmark runs a fixed workload many times under controlled conditions and records costs such as time or memory. For example, for a 16-byte buffer and 32-bit arithmetic, a bounds check written as wrongly allows the 4 largest values of the position , because the sum wraps around to a small number. Inspection finds this; a benchmark or a test with ordinary inputs passes.
A benchmark establishes what the program as actually built does and costs on real hardware: its running time, memory use and behavior, including effects of the compiler, the processor and the memory system that no reading of the source reveals. It also exercises the binary that was really built, which may differ from the source that was inspected. Neither establishes a bound on the worst case: inspection does not measure time, and a benchmark’s largest observed value is only a lower bound on the true maximum. The two connect only through artifact identity: a record of the source version, the build settings and a cryptographic hash of the binary, showing that the code inspected is the code measured.
Related entries: Artifact provenance (§13.1), Security claim scope (§1.45), Static analysis (§3.1), Dynamic analysis (§3.2), Reproducible build (§13.8), Worst-case execution time (WCET) (§9.33), Overflow-safe range check (§4.17), Test oracle (§10.5), Just-in-time compilation (JIT) (§2.14).