Testing

How tests are written, what the harness checks and what scripts/check.sh and CI run. The grammar of a test file and every rule of the harness are in tests/README.md; this page is the map.

A test file

A test is a source file whose first lines are // comments. The expect: and mode: lines among them are the expectations; the rest explain the test. An expect:, mode: or twin: line after the first line of code is an error, so an expectation cannot be silently ignored. Here is the header of a test that must verify (tests/scalar/abs_value.c):

// expect: verified
// expect: native-ok
// mode: c23, c++20
// Pins: 0010 item 3 and 0012 item 5: the conditional operator checks its branch only when taken
#include <cerastes.h>

and of its must-fail twin (tests/scalar/negative/abs_value_over.c), which names it and the one error it must produce:

// expect: error overflow @ L11
// mode: c23, c++20
// twin: tests/scalar/abs_value.c
// Pins: 0010 item 3: -a is checked on the branch where a < 0
// Without the requires, a = INT_MIN takes the negating branch.
#include <cerastes.h>

@ L11 is a line of the test file itself. The test passes only if the reported errors are exactly the expected ones: the harness says whether a miss was the wrong line, the wrong category, a missing error or an unexpected one.

Outcome kinds

expect: What it checks

verified

cerastes verify succeeds with no errors.

error <category> @ L<n>

Verification fails with exactly these errors, each with that category at that line.

rejected <diag> @ L<n>

cerastes verify does not accept the program and prints exactly these diagnostics (an EDG tag, or cerastes- and the tag of a back-end diagnostic).

golden

The IL walker’s listing (--cerastes_walk) equals the committed golden file, byte for byte.

native-ok

Also: clang, and GCC when installed, accept the file with -Wall -Wextra -Werror and without __CERASTES__, so the annotations are inert in an ordinary build.

frontend-ok, frontend-error, frontend-warning

What the EDG front end alone says about the file.

.c tests run in both languages where the directory says so (mode: c23, c++20). Files with the suffix .vpr are hand-written Viper programs that go straight to Silicon (tests/viper-smoke/). tests/README.md has the whole grammar, including verify-options: and the rules for tests whose errors are in a header.

Must-fail twins

Every encoding rule has at least one test that must verify and one that must fail for the right reason at the right line (invariant 2). In tests/annotations/, tests/scalar/ and tests/memory/ the harness enforces it: a test under that area’s negative/ directory names its positive test with twin:, and a positive test that no negative test names is a header error unless it says why with twin-exempt:. See "Twins" in tests/README.md.

Golden files are expectations

A golden file is the committed output of the IL walker for a golden test. It is an expectation, so invariant 1 applies: never edit an expect: line, and never regenerate a golden file to make a test pass. When a change intentionally alters a golden, regenerate it only for that change, read the diff line by line and state the reason in the commit message:

python3 scripts/run_tests.py --update-golden path/to/test.cpp

check.sh never uses --update-golden, and the harness self-test fails if a script does.

Running tests

python3 scripts/run_tests.py                    # tests/ and the documentation examples
python3 scripts/run_tests.py tests/scalar       # a directory
python3 scripts/run_tests.py -v path/to/test.c  # full diffs and tool output for failures
python3 scripts/run_tests.py --long             # also the long-running tests of tests/long/
python3 scripts/test_run_tests.py               # the harness's own self-test

With no paths the harness runs tests/ and doc/modules/ROOT/examples/. The exit status is 0 when every selected test passes, 1 when one fails and 2 on a usage or environment error. -j sets the parallelism (default: CERASTES_JOBS, else half the CPUs). Solver timeouts, crashes and messages the harness cannot classify always fail a test.

Long-running tests

A verify test that needs more than the driver’s 300 seconds lives under tests/long/<area>/ and starts with // timeout: <seconds> (301 to 3600; decision 0057). A default run skips the tier and says how many tests it skipped (N long skipped in the summary, a SKIP line each); --long, or naming a path inside tests/long/, runs them, each with --timeout=<seconds> on its cerastes verify command. Their headers and twins are checked in every run, and a positive outside tests/long/ needs a must-fail twin outside it. The limit is at least twice the test’s time on the quiet x86-64 box. tests/README.md, "Long-running tests", has every rule.

Mutation testing

python3 scripts/mutate.py [paths …​] changes each verified test one place at a time (a relational operator, a literal, a dropped conjunct, a deleted statement and so on) and verifies the mutant. A mutant that still verifies means the test would not notice the change: strengthen the test, or list the mutant with a reason in tests/mutants-equivalent.txt. A full run over tests/scalar takes a long time, so it is an acceptance step rather than part of check.sh, which only runs scripts/mutate.py --validate. The classes of mutation and the rules for survivors are in tests/README.md.

The Viper lint

python3 scripts/lint_viper.py reads the Viper that the verify tests left in build/vpr and enforces the rules about what the emitted program may contain: every inhale and assume carries a cerastes:inhale-ok reason, the only domain and axioms are the tagged ones, every checked line has a position-map entry and so on (Soundness). The docstring at the top of the script lists every rule, and scripts/test_lint_viper.py tests the lint.

The full check

scripts/check.sh must be green before a change is done. It requires a prior scripts/bootstrap.sh. In order, it:

  1. checks the EDG and vlibc trees (scripts/edg_tree.py, scripts/vlibc_tree.py);

  2. rebuilds with bootstrap.sh --build-only;

  3. lints: the shell scripts (bash -n, ShellCheck), the code style of src/ (scripts/format.sh --check), the Python scripts, the test headers and the documentation examples, the list of vlibc’s trusted contracts and the mutants;

  4. checks the EDG configuration;

  5. runs the self-tests of the harness, the lint, the mutation tool, the contract checker and the object-identity tool;

  6. runs every test, then lints the Viper they produced;

  7. runs the VIR self-test through Silicon and the lint;

  8. runs the walker oracle;

  9. builds the documentation and checks the rendered pages.

It ends with check.sh: all green, then a line that says whether the long-running tests ran: they run only with CERASTES_LONG=1 scripts/check.sh (the session’s check on the x86-64 box sets it; CI does not). The script is the authority; read it for the current list.

Refactors that change nothing

A change that should not change behaviour (a restyle, a rename, a function moved between files) is checked by scripts/object_identity.py before the full check:

python3 scripts/object_identity.py --before <base> [--after <rev>] [--tokens none|braces]

It exports src/, include/, cmake/ and the CMake files of both sides, compiles every translation unit of the compile database from each export with the build’s own command, and requires the object files and the LLVM IR to be identical; a second IR, with -femit-all-decls, adds the inline functions no translation unit calls, where a libc++ instantiation present on one side only is named and counted rather than failed (a literal’s new type can instantiate a library trait for another argument). It compiles only what the running platform compiles, so a refactor that touches platform code is checked on both. --tokens also compares the token streams of every source file, which covers code that no build compiles (an inactive #if branch, include/cerastes.h) and code that leaves no trace in the IR (a static_assert, = delete); --tokens braces accepts inserted brace pairs without checking where they close, so it is evidence only beside the compile passes. The tool refuses ("proof invalid") when a translation unit could read a header from outside its own side, when a file it does not compile has changed, when the sides pin different submodules, or when a source file is missing from the compile database. EDG’s internal assertions in encode.cpp receive __LINE__, so a change of layout changes two immediates in that object: the tool zeroes exactly those in the IR, compares the IR, and reports that the objects were not compared. S7’s restyle was proved this way, then by the full check’s .vpr and .map files, byte for byte (decision 0051). Its self-test, scripts/test_object_identity.py, runs in the full check.

Did any program’s Viper change?

A change to the encoder that should leave every existing program’s Viper as it was (a re-keying before a feature, a feature that only adds cases) is checked against a baseline of the Viper itself, long before the full check:

python3 scripts/regen_vpr.py --out <dir> [-j N] [--cerastes <path>] [--only <paths> ...]
python3 scripts/vprdiff.py <base_dir> <new_dir> [--allow <file>] [--show <test>] [--strict-new]

regen_vpr.py writes every .vpr and .map that run_tests.py would keep (the same tests, modes and // verify-options:, taken from the enumeration and command builder of run_tests.py itself) into a directory of its own, without running Silicon: it uses the driver’s silicon_timeout self-test hook, so the driver writes the Viper, starts Silicon, stops it at once and exits 3 with a fixed message, which the script requires. The output is byte for byte what a run_tests.py run keeps; the whole suite takes about a minute on the Mac, where the suite with Silicon takes hours. Take the baseline with the starting commit’s build, before any change. vprdiff.py compares two such trees: an entry (<test>.<mode>, its .vpr with its .map) that is only in the base or that differs fails the comparison unless the allow-list (test paths or globs, one per line) names it. Entries only in the new tree are new tests: they are counted, and compared only with --strict-new. So a neutral change shows as "0 allowed, 0 unexpected", and an intended one as exactly its tests.

Continuous integration

.github/workflows/ci.yml runs one job per toolchain profile (decision 0053). The profiles are listed in scripts/ci_toolchains.toml. Each job runs a setup script for its profile, then scripts/check.sh:

  • scripts/ci.sh <profile> on macOS;

  • scripts/ci-linux.sh <profile> on x86-64 Linux (decision 0031).

The setup script checks that the runner has the profile’s toolchain, installs the compilers it names, and bootstraps.

Two profiles are the references, the toolchains the expectations were made on:

  • macos-27: GitHub’s xcode-27 image, the Command Line Tools 27, Apple clang 21, SDK 27, Homebrew GCC 16;

  • ubuntu-26.04: clang 21 with libc++ 21, GCC 16, glibc 2.43.

The setup scripts check each version by its major and write the exact builds to the job log and to build/ci-toolchain.txt. An image update within those majors does not stop a job; a test whose result changes still does. Every test must give the same outcome on every profile, unless the profile records an exclusion for it (below).

Which profiles run depends on the trigger. A profile’s cadence field is every, nightly or dispatch:

  • Pull requests and pushes to main run the every profiles, the two references, in the PR tier (decision 0016, item 14). Tests that reach Silicon run only if they changed relative to the base, are documentation examples, or fall in a fixed one-in-eight sample; everything else runs. You can rehearse it with CERASTES_CHECK_BASE=main scripts/check.sh, which ends with check.sh: green in the PR tier (not the full check).

  • The nightly run (07:00 UTC) runs the full check on the every and nightly profiles.

  • A manual dispatch runs the full check. With an empty profiles input it runs the same profiles as the nightly run; all runs every profile; a list of names (separated by commas or spaces) runs exactly those.

Adding a toolchain

A toolchain is one table in scripts/ci_toolchains.toml. The comment at the top of that file lists the fields. Here is a Linux profile:

[[profile]]
name = "ubuntu-26.04-clang20-gcc15"
platform = "linux"
runner = "ubuntu-26.04"
cadence = "dispatch"
jobs = 4
ubuntu_version = "26.04"
glibc = "2.43"
clang_major = 20
gcc_major = 15
build = "clang"

python3 -I scripts/ci_profile.py check validates the file, and the harness self-test runs the same check. The script rejects runners it does not know, a runner whose OS version differs from the profile’s, GCC older than 14 (GCC 13 has no -std=c23), clang older than 18 on Linux, and a GCC build on macOS. build = "gcc" compiles EDG and cerastes with g++-<gcc_major>. EDG still emulates clang, so the scrape and the native-ok clang stay clang-<clang_major>.

A new profile starts as dispatch. Run a full check on it, either as a dispatch naming it or, for Linux, in an ubuntu container on an x86-64 machine (scripts/ci-linux.sh <profile>, then scripts/check.sh). Move it to nightly once that check is green.

To run the same setup locally, use scripts/bootstrap.sh. It takes the profile’s compilers from CERASTES_CLANG_MAJOR, CERASTES_GCC_MAJOR and CERASTES_BUILD_COMPILER and records them in build/toolchain.env. check.sh builds with the recorded values (bootstrap.sh --build-only). It stops if one of those variables names a different compiler.

A test whose outcome on a profile differs from its expect: lines fails that job. Fix it in cerastes if you can. Otherwise add an exclusion to the profile:

[[profile.exclusions]]
test = "tests/scalar/assert_basic.c"
mode = "c23"
reason = "glibc 2.39's assert expands to a shape the encoder does not match"

The mode field is optional. In that profile’s jobs (CERASTES_CI_PROFILE), the excluded test still runs, and at least one of its runs must fail. Those runs are reported as DIVERGES, with the reason. If none of them fails, the job fails with "remove the exclusion", so an exclusion cannot outlive its cause. The references carry no exclusions, and no test has an expect: line for a particular toolchain.

The documentation has its own workflow, .github/workflows/docs.yml, which builds and lints the pages on pull requests and deploys them from main (Writing documentation).