Testing

Tanny's claim is checker.md's rule: a verdict is Python's meaning of the model, and never a PASS for a check it did not make. Each layer below checks that claim against something Tanny does not share code with.

layer run what it checks Tanny against
conformance make conformance the verdicts Temporal Typing's suite states, and Tanny's own regressions
oracle make oracle Python itself: tests/reference.py runs each model's code in CPython
fuzz make fuzz RUNS=5000 SEED=n the oracle on random specifications, and mutants that must not crash
TLA⁺ models make tla, make tla-oracle models of Tanny's logic, with bugs planted that each must catch
benchmark make bench, make bench-check its own last report, with TLC counting the states
coverage make coverage which of Tanny's code the layers above run at all
WebAssembly make test-javascript Tanny's own binary: javascript/ gives the same verdicts, diagnostics and TLA⁺ for each example and regression

make check runs lint, tests, conformance, oracle and tla: about two minutes. It must pass before a push or a release.

Conformance#

scripts/conformance.py checks each file's Expected: docstring: name: PASS, name: FAIL kind name or name: ERROR code. The suite's files are Temporal Typing's (tests/temporal-typing, a submodule at a release); tests/regress/ are Tanny's, one model a fixed bug. A verdict the suite does not expect is Tanny's bug, unless KNOWN lists it with why.

Oracle#

tests/reference.py FILE MODEL checks a model by running it: it imports the file, reads the model with Temporal Typing's front-end, and explores the states breadth-first in CPython, with TLC's meaning of a .cfg (each rule measured against TLC 1.8.0: a state outside the constraint is checked, not explored; a raise disables the step). What it skips (a property, fairness, refinement, symmetry, more than 20000 states) it says.

tests/fuzz.py compares Tanny with it:

  • diff: random specifications from tests/generate.py, typed, with bodies of every statement Tanny takes and module constants (a dict key twice, True among 1s, a name bound again). Most count their steps in tick, and their random parts hold only after one to three of them: else nearly every one fails in its first state, and no step is compared. Tanny and Python must agree: a PASS on as many states, a FAIL of the kind, name and trace length the reference finds first. Tanny may refuse (an ERROR a user can read), never give an internal error or another verdict.
  • matrix: tests/matrix.py, every operation Tanny translates applied to every kind of value a state holds, and each binary one to each pair that may meet (the same kind, a bool and an int, an item and each collection), in an invariant and in a body; every mutator on each. Random specifications reach a pair when their weights say so; here each is reached, about 5700 cases in 15 seconds. Judged as diff judges.
  • replay FILE...: the same, for each model of saved files: what make oracle does for tests/regress.
  • crash: mutants of the suite's files; Tanny exits 0, 1 or 2 within 60s, with no internal error. A mutant of a file that has no verdict in time itself (alone, duplicate/a is an unbounded counter) is not counted.
  • frontend: Tanny's front-end against Temporal Typing's, the reference of checker.md §1, model by model, as the checker acts: a model the reference refuses, Tanny refuses with one of its errors (line and code) or as unsupported; one it reads, Tanny refuses only as unsupported; the errors Tanny's front-end gives are among the reference's, and the warnings of models Tanny checks are the same. Each file of the suite as it is, in make oracle; then --runs mutants and random ones. scripts/names.py writes the names each module the reference knows has, from the reference: run it when the suite's pin moves.

A case that differs is saved to .obj/fuzz/, with why, for replay.

Coverage#

make coverage builds Tanny for llvm-cov (rustc's LLVM: Homebrew's llvm, or LLVM=dir/), runs conformance, the oracle and the front-end's mutants with it, and reports each file's regions run; .obj/cov/lines.txt marks each line by how often, 0 for never. It fails when fewer than FLOOR percent of the regions run (89: 89.7% ran when it was set); raise it as coverage rises, never lower it to pass. A line no layer runs is Python Tanny translates and nothing compares with Python: there the fuzzer found any((1, 0)), set.update of a tuple and {*xs}. Give the generator the construct, or a model in tests/regress/; a branch nothing can reach is deleted.

TLA⁺ models#

tests/tla/ holds what Tanny's translation rests on, as TLA⁺:

  • Lowering.tla: how body.rs lowers a body (a block threads a record, a loop is a recursive helper, break, continue, return, raise and assert set its o), against a machine running the same statements one at a time, as Python does. MCLowering checks every body of its shapes from every start: 70545 cases.
  • MCPy.tla, written by py_cases.py: Py.tla's 35 operators against the 7122 values CPython gives them.

check.py checks both with Manyan (and TLC, for tla-oracle: the same states), then plants 16 bugs, each a line of a model or of Py.tla, and each must be found. A new rule of the lowering or a new Py.tla operator goes in a model, with a mutant that breaks it.

Benchmark#

bench/*.py are models heavy enough to time, each with its Expected: verdict; bench/run.py times them and the front-end reading limits.py, built to be slow. docs/benchmark.md is the last report. TLC checks each of Tanny's translations and must count the same states.

When a layer fails#

  • A verdict differs from the suite. Find whose meaning is Python's: tests/reference.py on the model, and semantics.md. If Tanny's, fix Tanny; if the suite's, list it in KNOWN with the section that says so.
  • The oracle differs. replay the saved case; shrink it to the construct; fix the translation, or the reference if it is the one wrong (it has been: list defaults, a progress line read as a count). Then add the shrunk case to tests/regress/ with its Expected: verdict.
  • An internal error. Always Tanny's bug: Manyan refused what Tanny wrote. tanny translate FILE MODEL gives the TLA⁺; TLC on it, with Py.tla beside, names the expression Manyan only calls an exception.
  • A mutant is not found. The model no longer covers that rule: widen its shapes or its domains.
  • WebAssembly differs. The same code, built for another machine: what differs is the machine's. Run node target/wasm32-unknown-emscripten/release/tanny.js check FILE beside tanny check FILE; a stack that runs out is the worker's (STACK_MB in javascript/index.js), a crash in Manyan its longjmp, which .cargo/config.toml builds as WebAssembly's.
  • The benchmark is slower. Measure again on an idle machine; then bisect (git stash, make bench-check). A slower release is the user's call.

Known gaps#

  • The front-end is a port of Temporal Typing's. On the suite's files they agree, by model, and on their mutants: fuzz.py frontend --runs 200, seeds 1 to 120, 0 of 28,680 differ against Temporal Typing's main. A refined action's parameter Tanny needs a domain for, the reference does not; Tanny refuses it as unsupported.
  • TLA⁺ compares values of one kind only, tells a bool from an integer, and bounds its integers (to 2³¹); Python does none of these. Comparing values of two kinds (1 and "1", a list and a tuple inside a value), a bool stored where an int is declared, compared with one, or in a set or dict's keys with one, and an integer past Manyan's range, are refused. So is what Python raises a TypeError on, which a type checker would refuse: a list as a key, frozenset.add, len of an int.
  • A while loop is followed for Turns (1000) turns, then reported.
  • Manyan (0.19.1 and 0.20.1) slows by a thousand times on nested loops past 64 calls (docs/upstream/manyan-cliff.md, soasme/manyan#43).