Section 19.2.13

Semantic oracle independence and common-mode errors

Definition

A semantic oracle is a test oracle §10.5, the check that decides whether a test result is correct, that derives the expected result from the meaning (the semantics) of the input, for example by running a second implementation of the language. Oracles are independent when no shared cause can make them wrong on the same input. A common-mode error is an error that several components make together from one shared cause, such as shared code or one misreading of a specification; their agreement says nothing about what that cause governs.

Where it fits

Main entry: Differential testing (§10.6).

Differential testing runs two or more engines on the same inputs and compares their results. An engine is a program that executes a language or an instruction set, such as an interpreter §2.13 or a compiler. Each engine is then a semantic oracle for the others. A disagreement shows that at least one engine, or the specification, is wrong. Agreement is evidence only to the extent that the engines would be wrong in different ways.

Example. An instruction set defines 32-bit addition to wrap around: the true sum is reduced modulo 2322^{32}, so adding 1 to 0xFFFFFFFF, which is 4,294,967,2954{,}294{,}967{,}295, gives 0. Three engines written in Python §12.23, whose integers have no size limit, all omit the reduction and report 4,294,967,2964{,}294{,}967{,}296. A fourth engine, written in C with a 32-bit unsigned type, reports 0, because unsigned modular arithmetic §4.16 in C wraps by definition. A majority vote says 3 to 1 that the C engine is wrong; the specification says it alone is right. The Python engines share one decisive dependency, the integer arithmetic of their host language, and so they share the error.

Shared causes defeat the arithmetic of independence. If each of three engines were wrong on an input with probability 0.01, independently, all three would be wrong together with probability 0.013=0.0000010.01^3 = 0.000001. If one shared cause makes all three wrong on 1 input in 100, they are wrong together with probability 0.01, which is 10,00010{,}000 times as often. In Knight and Leveson’s 1986 experiment [440], 27 independently written versions of one program failed together far more often than independence predicts.

A third engine therefore helps only through the dependencies in which it differs from the others: the decoder (the code that splits instruction bytes into fields), the reading of the specification, the host arithmetic and the compiler. An engine used as a reference on a development computer must follow the rules of the target, the machine or instruction set under test, not the rules of its own programming language: in C, unsigned overflow wraps but signed overflow §4.15 is undefined behavior §4.12, while the target’s instruction may define signed addition to wrap.

Questions answered

What does a third engine add?

A third engine, a third program that executes the same language or instruction set in a differential test, adds a chance to expose errors that the first two share and a hint about which engine is wrong when two disagree. It adds no proof. Engines can share a common-mode error, one error from one shared cause, such as the same reading of the specification, the same decoder, the same compiler or the same host integer arithmetic: three engines that compute a 32-bit sum with unlimited integers all report 4,294,967,296 where the specification requires 0.

A third engine adds evidence only where its decisive dependencies differ from those of the other two, and a majority vote is a first guess, never a verdict. Settle every disagreement by reducing the input to a small case and checking the specification’s rules for width, overflow and every other point in question. Different names or authors do not show that two engines differ in the dependency that decides a case.

Related entries: Test oracle (§10.5), Independent review (§10.44), Bit-vector logic (§15.15), Differential semantics (§3.34), Unsigned modular arithmetic (§4.16). Further reading: [440].