Skip to content
suit Artifact [7434a8e912]
Login

Artifact [7434a8e912]

Artifact 7434a8e9124cde2a91a4fa3e0ad78ca114e7990806a74d593eba666a108a7a10:


# Quality gates

The bar for this project: built and tested under Fil-C, released in a fast
build, zero untested branches, zero known flaws, best performance possible.
Every gate below is a make target, and `make all` runs them in order and
stops at the first failure. The forge's Linux runner runs `make all`
(`ci/test.yml`).

## The gates

| Target | What it runs | What passing proves |
|---|---|---|
| `make` | Dev build in `build/dev/`: `-O1 -g`, ASan, UBSan, `-DSUIT_TEST` | It compiles with every warning on and `-Werror`: `-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wcast-align -Wformat=2 -Wundef -Wvla -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough`. |
| `make release` | `-O2 -flto`, stripped, no sanitizers, no `SUIT_TEST`, to `build/release/suit`, then `test/release_clean.sh` | The binary that ships has no fault-injection code: `strings` finds neither `SUIT_FAULT` nor the wrapper-name table in it, and does find them in the dev build (so the check is not blind). |
| `make check` | `test/unit.c`, `test/run.sh` and a replay of every fuzz seed and saved corpus file, on the dev build | Behaviour is right, and no test trips ASan or UBSan. |
| `make cover` | The same tests on a `-O0` build with `-fprofile-instr-generate -fcoverage-mapping`, then `tools/cover_gate.py` | Every function, line, region and branch of every file in `src/` ran, as a count per file. On failure it prints each uncovered line and branch. |
| `make analyze` | The clang static analyzer over `src/`, test and coverage configurations | No analyzer report. |
| `make check-budget` | `suit bench` on the release binary, quiet and then under `loadgen 30 8` | The no-change run costs at most 1 ms and 1 MiB more than an empty program built the same way ([decisions](decisions.md)). |
| `make fuzz` | libFuzzer on the config parser and the stamp reader, 30 seconds each; without libFuzzer, a fixed-seed mutation loop | No crash, sanitizer report or failed invariant on generated input. Findings are kept in `build/fuzz/corpus-*` and replayed by `check` and `cover`. |
| `make filc` | `tools/filc.sh`: unit tests, shell suite and fuzz replay built with Fil-C 0.687 | Every out-of-bounds access, use after free and bad cast in those runs would have been a crash, and none was. Linux only; `tools/filc-docker.sh` runs it in an ubuntu:24.04 container elsewhere. |

## The 100% rule

All of `src/` is held to 100% of functions, lines, regions and branches, as
`llvm-cov` counts them. There are no exclusions: no file, line or marker is
skipped. A branch that cannot be reached is not left uncovered. It becomes an
`ensure` or is removed.

Branches counted by `llvm-cov` include each side of every `&&`, `||` and `?:`,
so each condition in a compound test needs a test that decides it. The
coverage build adds `-D_FORTIFY_SOURCE=0`, because the macOS SDK's checked
`snprintf` macro contains a branch that is never taken by construction.

### ensure

`ensure(cond)` is for invariants that cannot fail: it reports `cond`, file and
line on stderr and aborts. It is on in the release, sanitizer and Fil-C builds.
In the coverage build alone it compiles to nothing, so the impossible side is
not counted as a branch. `cond` must have no side effects.

Anything that can happen is not an `ensure`: bad input and a failed call are
error paths, each with a test.

## Fault injection

Every libc or system call that can fail goes through a wrapper in
`src/platform.c`: `sys_open`, `sys_read`, `sys_write`, `sys_close`,
`sys_fsync`, `sys_stat`, `sys_fstatat`, `sys_rename`, `sys_mkdir`,
`sys_unlink`, `sys_getenv`, `sys_spawn`, `sys_wait4`, `sys_now_ns` and
`platform_self_path`. A wrapper returns what the libc call returns and sets
`errno` the same way. Output goes through `say` and `Out`, which are built
on `sys_write`.

In a build with `-DSUIT_TEST`, the environment variable

    SUIT_FAULT=NAME:N[:ERRNO|short]

makes the Nth call to the wrapper NAME fail. The names are `open`, `read`,
`write`, `close`, `fsync`, `stat`, `fstatat`, `rename`, `mkdir`, `unlink`,
`getenv`, `spawn`, `wait4`, `clock_gettime` and `self_path`. N counts from 1,
and only that one call fails. ERRNO is a name (`EIO ENOSPC EACCES ENOENT
ENOTDIR EEXIST EINTR EPERM ENOMEM EMFILE`) or a positive number; the default
is `EIO`. `short` applies to `read` and `write` only: the call transfers
between 1 and 4 bytes instead of failing. `getenv` returns null, `spawn`
returns the error number, and the others return -1 or false. A malformed
`SUIT_FAULT` exits with status 99 and says why.

The release build contains none of this. The variable name and the name table
are compiled out, and `test/release_clean.sh` checks the binary.

Two things are deliberately not reported: a failed write to stderr (there is
nowhere left to say so) and a failed `close` of a descriptor that was only
read.

## Tests

- `test/unit.c`: the parser through its API, the limits, and each wrapper
  failing, run in a child process with `SUIT_FAULT` set.
- `test/run.sh`: the command line, every strict error with its line number,
  the stamp format and exit codes, the no-write assertion, the bench, and a
  fault case for each failure branch.
- `test/replay.c`: replays fuzz seeds and saved corpus files through either
  fuzz target without libFuzzer, so `check`, `cover` and Fil-C can use them.
  `--mutate N` runs N fixed-seed mutations.
- Fuzz targets: `test/fuzz_conf.c` (config parser) and `test/fuzz_stamp.c`
  (stamp reader). Seeds are in `test/corpus/`.

## Vendored code

SQLite, libfossil, zlib and TLS arrive in phase 2. They are outside the 100%
rule and the warning set. They are built and run under ASan, UBSan and Fil-C
along with everything else, and suit's own code that calls them stays inside
the rule.

## What "no known flaws" means

Passing every gate is what "no known flaws" means here, and nothing more. The
gates cannot show that an untested input is handled, that the fuzzers would
find a bug given more time, or that the Linux build behaves like the macOS
one when only macOS ran. A flaw found later is a missing test: add the test
that fails, fix it, and the gates keep it fixed.