#!/usr/bin/env bash # The per-commit gate, run on a committed revision in its own worktree so the # working tree can move on while it runs (~10 min on a loaded machine): # lint and format, generated-code drift, lockstep on the 13 shipped manifests # and 300 random programs (through step(), then through run(1)), then the whole suite on PyPy (SingleStepTests, # z80test, FUSE, interrupt cross-check). # # scripts/gate.sh [REV] default HEAD; log in .gate-logs/REV.log # # Rung 3 (ZEXDOC/ZEXALL lockstep) is scripts/rung3.py, run separately. set -euo pipefail repo=$(cd "$(dirname "$0")/.." && pwd) rev=$(git -C "$repo" rev-parse --short "${1:-HEAD}") wt="$repo-gate" [ -d "$wt" ] || git -C "$repo" worktree add -q --detach "$wt" "$rev" git -C "$wt" checkout -q --detach "$rev" for p in tests/z80_test_vectors tests/zex validation/z80test_data validation/fuse_data validation/interrupt_oracle_src; do [ -e "$wt/$p" ] || ln -s "$(readlink -f "$repo/$p")" "$wt/$p" done mkdir -p "$repo/.gate-logs" cd "$wt" py="$repo/.venv/bin/python" pypy="$repo/.venv-pypy/bin/python" { echo "gate $rev $(date -Is)" "$repo/.venv/bin/ruff" check -q . && "$repo/.venv/bin/ruff" format --check -q . "$py" tools/gen_ops.py --check out=$(PYTHONPATH=src "$pypy" validation/lockstep.py examples/conformance/*.json examples/conformance/interrupts/*.json) \ || { echo "$out" | grep -v '^identical'; exit 1; } echo "lockstep: $(echo "$out" | grep -c '^identical') manifests identical" out=$(PYTHONPATH=src "$pypy" validation/lockstep.py --random 1 300 20000) \ || { echo "$out" | grep -v '^identical'; exit 1; } echo "lockstep: $(echo "$out" | grep -c '^identical') random programs identical" out=$(PYTHONPATH=src "$pypy" validation/lockstep.py --run --random 1 300 20000) \ || { echo "$out" | grep -v '^identical'; exit 1; } echo "lockstep --run: $(echo "$out" | grep -c '^identical') random programs identical" "$pypy" -m pytest -q -p no:cacheprovider 2>&1 | tail -1 echo "gate $rev PASSED" } 2>&1 | tee "$repo/.gate-logs/$rev.log"