#!/usr/bin/env bash # SPDX-License-Identifier: MIT # The gate (charter: x-python -> x-rust): every rung, in order, stopping at the first failure. # # scripts/ladder.sh # rungs 0-6 # scripts/ladder.sh --faults # and rung 7, the seeded faults # # 0. the pins: the siblings at their commits with clean trees, the reference clone at f70eeb2, # the reference venv holding a7800-python's three pins # 1. build, fmt, clippy (rustup's stable toolchain when there is one), cargo test (the # reference's unit tests, transcribed) # 2. per-slice lockstep against the reference over scripts/cases.tsv: every bus cycle, every # finished line, the audio mix, board time and CPU state per slice (reference traces cached # in external/refcache) # 3. the same with --save-at-half: saved half way, loaded into a fresh console, identical # 4. a2600-rust's gates through the 7800's own TIA construction and 2600 mode: die traces, # timer ROMs on both 7800 rows, the smoke group, the PAL 7800 #699 tables; and the # reference's --bios digests (both BIOS rows) equal to this board's # 5. the window, headless: palettes and composite equal to the reference's, the judge, a # screenshot # 6. speed, in multiples of real time (not a judge) # # Needs: ../a2600-rust ../6502-rust ../pokey-rust ../a2600-python (its references fetched) # beside this repository; ../a7800-python/.venv-pypy; external/a7800-python (git clone of # a7800-python, checked out at f70eeb2); scripts/inputs.py run once (cc65 2.19); NO_INTRO_DIR # and MAME_ROMPATH (run under a login shell). At most three processes, niced; every run timed. set -euo pipefail cd "$(dirname "$0")/.." export PYPY_GC_NURSERY="${PYPY_GC_NURSERY:-1M}" export MAME_HASHPATH="${MAME_HASHPATH:-$(cd .. && pwd)/a2600-python/reference/src/mame/hash}" export A2600_PYTHON_ROOT="${A2600_PYTHON_ROOT:-$(cd .. && pwd)/a2600-python}" REF_PY="$(cd .. && pwd)/a7800-python/.venv-pypy/bin/python" NICE="nice -n 19" step() { printf '\n== %s\n' "$*"; } step "0. pins" check() { # repo commit local head dirty head=$(git -C "$1" rev-parse --short=7 HEAD) dirty=$(git -C "$1" status --porcelain --untracked-files=no) if [[ "$head" != "$2" || -n "$dirty" ]]; then echo "$1 is at $head${dirty:+ (dirty)}, not $2"; exit 1; fi echo "$1 $head" } check ../a2600-rust c40bcf6 check ../6502-rust 1a7e134 check ../pokey-rust b37263d check external/a7800-python f70eeb2 for pin in "6502-python.*828b619" "a2600-python.*4ad24f2" "pokey-python.*ea20096"; do $REF_PY -m pip freeze 2>/dev/null | grep -Eq "$pin" || { echo "the reference venv lacks $pin"; exit 1; } done echo "reference venv: 6502-python 828b619, a2600-python 4ad24f2, pokey-python ea20096" if [ -f external/refcache/PIN ] && [ "$(cat external/refcache/PIN)" != f70eeb2 ]; then mv external/refcache "external/refcache-$(cat external/refcache/PIN)" # moved aside, never deleted fi mkdir -p external/refcache && echo f70eeb2 > external/refcache/PIN step "1. build, format, lint, tests" timeout 1800 $NICE cargo build --release -j 3 --bins timeout 1800 $NICE cargo build --release -j 3 --features frontend --bin a7800-play STABLE=$(ls -d "$HOME"/.rustup/toolchains/stable-*/bin 2>/dev/null | head -1 || true) LINT_CARGO=cargo [ -n "$STABLE" ] && LINT_CARGO="env PATH=$STABLE:$PATH $STABLE/cargo" timeout 600 $LINT_CARGO fmt --check timeout 1800 $NICE $LINT_CARGO clippy --release -j 3 --all-targets --features frontend --target-dir external/stable-target -- -D warnings timeout 3600 $NICE cargo test --release -j 3 -- --test-threads 3 2>&1 | grep -E "^test result|FAILED|panicked" || true timeout 3600 $NICE cargo test --release -j 3 -q -- --test-threads 3 >/dev/null 2>&1 step "2. per-slice lockstep against the reference (scripts/cases.tsv)" timeout 14400 python3 scripts/lockstep.py --reference-cache external/refcache --jobs 3 | tail -1 step "3. save states: half way, into a fresh console, identical" timeout 14400 python3 scripts/lockstep.py --reference-cache external/refcache --jobs 3 --save-at-half | tail -1 step "4. a2600-rust's gates through the 7800's TIA and 2600 mode" timeout 1800 $NICE target/release/a7800-gates die | tail -1 timeout 1800 $NICE target/release/a7800-gates timers | tail -2 timeout 7200 $NICE target/release/a7800-gates smoke | tail -1 timeout 7200 $NICE target/release/a7800-gates serial | tail -1 if [ ! -s external/refcache/bios-digests.txt ]; then (cd / && timeout 7200 $NICE "$REF_PY" "$OLDPWD/external/a7800-python/scripts/gates_2600.py" \ --root "$A2600_PYTHON_ROOT" --bios) | sed -E 's/ \([0-9]+ s\)$//' > external/refcache/bios-digests.part mv external/refcache/bios-digests.part external/refcache/bios-digests.txt fi timeout 3600 $NICE target/release/a7800-gates bios | sed -E 's/ \([0-9]+ s\)$//' > external/bios-digests.rust if diff -q external/refcache/bios-digests.txt external/bios-digests.rust >/dev/null; then echo "--bios digests: $(wc -l < external/bios-digests.rust) of $(wc -l < external/refcache/bios-digests.txt) lines identical to the reference's" else diff external/refcache/bios-digests.txt external/bios-digests.rust | head; exit 1 fi step "5. the window, headless (no human has looked at it)" (cd / && $REF_PY "$OLDPWD/scripts/palettes_ref.py") > external/palettes.ref target/release/a7800-play --dump-palettes > external/palettes.rust cmp external/palettes.ref external/palettes.rust && echo "palettes and composite: identical to the reference's" SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy timeout 1800 $NICE target/release/a7800-play --judge | tail -1 rom="$NO_INTRO_DIR/Atari - Atari 7800 (BIN)/Joust (USA).zip" SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy timeout 600 target/release/a7800-play "$rom" --frames 400 --scale 1 --screenshot external/window-shot.png echo "window: $(stat -c %s external/window-shot.png) bytes of PNG after 400 frames (external/window-shot.png)" step "6. speed (multiples of real time; not a judge)" timeout 600 target/release/a7800-speed "$NO_INTRO_DIR/Atari - Atari 7800 (BIN)/Commando (USA).zip" 3600 if [ "${1:-}" = "--faults" ]; then step "7. seeded faults (each must be caught)" timeout 36000 python3 scripts/seeded_faults.py | tail -1 fi step "ladder passed"