56 lines
5.2 KiB
Markdown
56 lines
5.2 KiB
Markdown
# Testing
|
|
|
|
Non-normative. How the reference implementation is tested. Policy (what must be tested) is in `AGENTS.md`; this file covers the mechanics.
|
|
|
|
## Test levels
|
|
|
|
| Level | Where | Run | Purpose |
|
|
|---|---|---|---|
|
|
| Unit | `test` blocks in `src/`, `tools/` | `zig build test` | internal data structures, helpers, registry ↔ docs sync |
|
|
| Conformance | `tests/conformance/` | `zig build conformance` | spec behavior: accept/reject, later run output and traps |
|
|
| Reference programs | `tests/programs/` (from P2) | `zig build conformance` | the six programs in `plan/conformance-suite.md` |
|
|
| Litmus | `tests/litmus/` (from P5) | `zig build litmus` | memory-model outcomes allowed/forbidden |
|
|
| Schedule stress | runner flag (P3-12) | `zig build conformance -- --stress N` | every test with `schedules:` runs schedule seeds 0…N-1 under quanta 1, 2, 7 and its own; a failure prints the replay command. Systematic exploration (DPOR) is Phase 5 |
|
|
| Native parity | (from P7) | `zig build parity` | interpreter and native backend agree on the whole corpus |
|
|
|
|
Unit, conformance and hosted smoke tests exist today; conformance covers accept, reject and run tests in the deterministic profile, and `tests/hosted/smoke.py` checks observable effects (files, streams, sockets) of hosted runs.
|
|
|
|
## Conformance tests
|
|
|
|
Format and outcomes: [`tests/conformance/README.md`](../../tests/conformance/README.md).
|
|
|
|
Adding a verifier rule:
|
|
|
|
1. Write the rule in the spec, with its code in `docs/reference/error-codes.md` and `src/diag.zig`.
|
|
2. Add the smallest `reject` test that violates only that rule.
|
|
3. Add an `accept` test that is as close as possible to the reject test but legal. The pair documents exactly where the boundary is.
|
|
4. Implement until both pass.
|
|
|
|
Planned header extensions (added by the phase that needs them):
|
|
|
|
| Key | Phase | Meaning |
|
|
|---|---|---|
|
|
| `expect: run` + `result:` / `trap:` | P0 (implemented) | module must verify; run record must match |
|
|
| `stdout:` | P2 | expected output, `\n`-escaped (needs `io.write`) |
|
|
| `stdin:` / `vfs:` / `seed:` / `stdout:` / `stderr:` / `file:` / `blocked:` | P2 (implemented) | deterministic world inputs and expected observable output |
|
|
| `grant:` / `not_instantiated:` | P2 (implemented) | capability grants for `@main`; expected instantiation failure |
|
|
| `fuel:` | P0 (implemented) | instruction limit; default 1 000 000 (spec 11 §7.1) |
|
|
| `seed:` / `schedules:` / `quantum:` | P3 | scheduler seed / schedule budget / instructions per forced scheduling point (spec 11 §7.2) |
|
|
| `profile:` | P2 | runtime profile (`hosted`, `deterministic`, …) |
|
|
|
|
## Determinism checks
|
|
|
|
No test outcome may depend on wall-clock time. Runs are bounded by fuel; fuzz and stress tooling must always pass a fuel limit.
|
|
|
|
Every run test is executed twice by the runner from P0-12 onward and the outputs (stdout, trap record, trace hash) compared byte-for-byte. Concurrency tests additionally run under the stress modes listed in `plan/conformance-suite.md`.
|
|
|
|
## Diagnostics as API
|
|
|
|
Diagnostic JSON is a stable interface. Snapshot tests on the full JSON (not only the code) belong in unit tests next to the pass that emits them, so field renames are caught.
|
|
|
|
`python3 tests/hosted/source_diagnostic_reasons.py` checks stable E7006 categories, generic/package propagation and serialization. From `tools/eval`, `python3 -m unittest discover tests` checks reporting alongside the harness. `ajieval summary` reports observed `(code, reason)` occurrences and affected runs with log coverage; `profile` and `checkpoint` expose per-run pairs. Existing compact code extraction is preserved. Only whole JSON diagnostic lines classify a reason: unparsed or historical records remain unknown; new reason strings are retained. Missing logs are unavailable. These counts cover the recorded command outputs, not a pre-acceptance cutoff or the true frequency of unobserved errors; future cohort methodology must specify those separately.
|
|
|
|
`python3 tests/hosted/related_locations.py` checks factual E2101/E2104 definitions and E4302 spawns in public AIR/source rejects, exact definition coordinates (including parameters and second split results), independent annotation-map reconstruction, existing source deduplication, generics and explicit packages. Unit tests cover typed JSON/key order, absent related mappings and repeated cancelled-join handle replacement through the lowered-source pipeline. `zig build conformance -- --filter cancel_join --stress 200 --collect-every-step` exercises accepted cancellation counterparts under deterministic schedule seeds and several quanta. These checks add no repair or lifetime inference.
|
|
|
|
The CLI JSON reader rejects duplicate members instead of silently overwriting them; targeted capability-kind and live-guard cases check the stable machine `kind` and separate payload identities. Pipeline unit tests also parse those records with duplicate fields forbidden. `verifier.expectCodes` checks that all its diagnostics have distinct payload names that do not shadow the envelope (`diag.expectUniqueFields`). The conformance runner validates every final source/AIR diagnostic after lowering and mapping, including frontend-added fields, and parses its serialized JSON with duplicate members forbidden. This adds no production/runtime check.
|