DESIGN · BENCHMARKS

Benchmarks: repeatable measurements of the safety checks

The short version

If you tell people a smoke alarm works, they want to know how you checked. Pressing the test button once is not enough. You want it tested on a schedule, tested against things that should set it off, and a way to notice if someone quietly disabled it.

We try to measure the safety checks the same way. Some measurements say how fast a check is. Others say whether the tests would notice if the check were broken.

Everything below runs in simulation on free GitHub runners. No benchmark has run on the real RP2350 or the real Pi, because that hardware is not built yet.

What we measure

Speed: instruction counts on every pull request

sawbones-bench holds a case for each hot safety function: module protocol encode and decode, the bus guard's frame check, the policy engine's classify and preflight, and one interlock step. ci/bench.py runs each case under callgrind and counts only the instructions inside the measured function.

We count instructions because wall-clock time moves with the load on a shared runner and instruction counts do not. The job compares against a checked-in baseline and fails if any case runs more than 10% more instructions. Re-blessing the baseline is a protected change that needs a clean-room review. Wall-clock timing on the real chip waits for the hardware.

Fuzzing: weekly

Four cargo-fuzz targets feed random bytes to every decoder that reads outside input: module protocol frames, the Modbus RTU parser (rebuilt byte for byte), approval messages and the fencing of outside text. A crash fails the job and uploads the input. The input then becomes a regression test.

Mutation testing: weekly

cargo-mutants makes small deliberate breakages in the safety crates (interlock, policy, bus guard, approvals, module protocol) and checks that some test fails for each. A change no test notices is a test gap. A follow-up pull request caught 82 of 89 missed mutants; the rest were equivalent changes or hangs, listed in the pull request. See the lab note.

Coverage of attacks: every test run

The red-team catalog is checked on every cargo test, and its summary table cannot go stale. See Research for the current numbers.

What these numbers do not tell you

  • Instruction counts say nothing about real timing on an RP2350.
  • Mutation testing shows the tests notice changes. It does not prove the code is right.
  • Passing fuzzing for a weekly run is not proof of the absence of bugs.
  • A red-team card marked blocked means one named test or CI job proves it. Many cards are still partial or gaps.

Reproduce it

cargo test --locked
python3 ci/bench.py check    # Linux with valgrind
cargo install cargo-mutants --locked
cargo mutants --package sawbones-approvals

The commands and the full workflow are in CONTRIBUTING.md.