R455 · AI-built software and its verification › Test oracles for agent-written code

The oracle that weakens as you port it: checkasm per-architecture detection matrix

Read the original

test-oraclesverificationbenchmarksopen-sourcedeveloper-infrastructureclaim-checking

Filed 2026-12-01. Sources: the VideoLAN project page for checkasm, the project's own documentation site (checkasm.videolan.me, version 1.3.0), and FFmpeg's in-tree tests/checkasm README.

What it is

checkasm is a differential test harness for hand-written assembly. In the project's words it is "a tool for verifying the correctness of assembly code, as well as performance benchmarking." A test calls checkasm_call_ref() for the C reference and checkasm_call_new() for the optimised implementation on identical inputs, then compares the outputs with checkasm_check1d() / checkasm_check2d() or a padded-rectangle variant. The reference is the oracle: there is no expected-output table to maintain, only the slow obvious implementation and the fast suspicious one.

It has existed inside codecs for years. It was "[o]riginally developed for the x264 encoder project" and grew "while in use by FFmpeg and dav1d". What is new is that it has been extracted: the standalone project was "forked from dav1d's internal copy", chosen because dav1d's was "the closest to being feature complete, while also being permissively licensed and using a modern CI and build system", with FFmpeg's improvements merged in "with permission to relicense". It is now, in the documentation's phrase, "a fully fledged cross-platform standalone library and benchmarking framework", under the 2-clause BSD licence, maintained by Niklas Haas (FFmpeg's copy of the README also names Martin Storsjö), with original authorship credited to Henrik Gramner, Loren Merritt, Fiona Glaser and others.

Why this matters beyond codecs

The interesting property is not that it diffs two implementations. It is what else it checks while doing so. The project claims "[d]etection of ABI violations such as register misuse, illegal opcodes, or missing state cleanup" and "[c]rash resilience including signal handling and stack smashing detection." The observable evidence is in its failure labels: sigill for an illegal instruction, corrupt_stack, clobber_r9 through clobber_r14 ("failed to preserve register: r9"), and underwrite_64 accompanied by a hex dump of the destination buffer showing aa aa aa aa guard bytes. Out-of-bounds writes are caught structurally, by comparing a padded rectangle: the harness "[d]etect[s] when functions write beyond their intended boundaries."

That is a much stronger oracle than output equality. A function can return the right pixels and still have trashed a callee-saved register, left the FPU in the wrong state, or written four bytes past the buffer — three failures that output comparison alone cannot see, and that will surface later as an unrelated bug in unrelated code. checkasm turns all three into a named failure at the point of origin, with the PRNG seed printed so the case replays.

The finding: the oracle's strength is a function of target architecture

FFmpeg's README publishes the detection matrix, and it is not uniform:

ArchitectureWhat is checked
x86, x86-64registers, stack, AVX2, MMX/FPU state
ARM, ARM64 (aarch64)registers, stack, VFP state
RISC-Vregisters, stack, vector state
LoongArch (32, 64)registers
PowerPC (64le)none

Read that bottom row carefully. On PowerPC 64le the harness still runs, still compares outputs, and still reports a pass — but none of the ABI-violation machinery is active. On LoongArch only register preservation is checked; stack corruption is not. The same test, the same source, the same green result, and three materially different guarantees.

No page in the documentation warns about this. The matrix is presented as a platform-support table, which is how a reader will take it — as a statement about whether the tool works, not about how much the tool proves. The honest reading is the opposite: the tool works everywhere and proves progressively less as you move down the table. A team that ships a PowerPC asm path on the strength of a green checkasm run has a weaker assurance than the identical green run on x86-64 gave them, and nothing in the output says so.

This is a general hazard for any differential harness with optional checks. The check set is a property of the runner, not of the test, so it is invisible in the test source and invisible in the pass/fail line. The cheap mitigation is to make the active check set part of the report — print what was verified, not just what passed — so that a reviewer comparing CI logs across targets can see the asymmetry without going to look up a table.

Architecture: what the consuming project has to own

The integration boundary is drawn unusually tightly, and deliberately so: "checkasm does not provide CPU detection or runtime dispatch functionality on its own. It is a pure testing framework... should not be used as a runtime dependency." The consumer supplies:

CPU feature levels are cumulative and ordered by that array: "[f]lags are tested in the order defined in the array. Each test inherits flags from all previous entries." A test receives its level rather than choosing it, which is the right default — it makes "run every implementation at every level the machine supports" the path of least resistance instead of something each test opts into.

Integration is Meson-shaped. The recommended route is a wrap file pointing at code.videolan.org/videolan/checkasm.git with revision = release, consumed via dependency('checkasm', fallback: ['checkasm', 'checkasm_dep'], required: false); a git submodule on the same branch is offered for environments "where the build system cannot access the internet during configuration time"; a manual meson install plus pkg-config works but is "discouraged in favor of using Meson subprojects or distribution packages". CMake is not mentioned. One compile-time wrinkle: "[c]heckasm uses optional C11 features inside public header files", so -std=c99 builds must define the relevant options before including the header.

Benchmarking: a measurement model, not a stopwatch

The benchmarking half is more statistically careful than most microbenchmark harnesses. It "models execution time as a log-normal distribution", tracking log-mean μ and log-variance σ², and publishes its own formulas — mode exp(μ − σ²), median exp(μ), mean exp(μ + σ²/2), standard deviation sqrt(exp(2μ + σ²) × (exp(σ²) − 1)), and 95% intervals at exp(μ ± 1.96σ). Per-call cost is recovered by "linear regression in log-space on the relationship between iteration count and total execution time", which also gives "robust outlier rejection through regression residuals". Harness overhead is handled by measuring a no-op and subtracting it, re-estimated periodically. Repeated measurements are combined as a geometric mean.

Timing sources degrade along the same axis as the correctness checks: rdtsc on x86 ("very high resolution"), pmccntr on ARM and rdtime on LoongArch ("high resolution"), mfspr on PowerPC 64le ("medium resolution"), and OS timers as a "lower resolution" fallback. The documentation is candid about validity: disable frequency scaling and turbo, avoid loaded systems, nice -n -20, watch for thermal throttling — with the useful clarification that frequency scaling "affects only the conversion to nanoseconds, not cycle counts." Cross-CPU comparison is explicitly discouraged in favour of "relative speedup (optimized vs C) rather than absolute cycle counts", and the page lists dead-code elimination, constant folding, branch prediction and memory hierarchy as the pitfalls it cannot solve for you.

Failure modes

Review checklist

  1. For each target architecture you ship assembly for, write down which checks were actually active. If any target shows fewer than registers + stack, say so in the review, not just "checkasm passes".

  2. Make the active check set appear in CI output, so the asymmetry is visible without consulting a table.

  3. Assert the number of tests and functions that ran, so a silently skipped implementation fails the build rather than passing it.

  4. Confirm the CPU-flag array is ordered from baseline upward, since each level inherits the previous ones.

  5. Run with --repeat across successive seeds before trusting a new kernel; a single seed is one sample of the input space, and the seed is printed precisely so a failure replays.

  6. Pin the dependency to something reproducible rather than a moving release branch, and record the version string your build used — the documentation site currently reads 1.3.0 and no changelog is published.

  7. For benchmarks: pin the CPU, disable turbo and scaling, and report speedup ratios rather than cycle counts.

Connections

See R455 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.