#!/usr/bin/env bash # The gate for every commit that touches src/: # rung 1 cargo test: the examples against the reference's committed traces, the # EEPROM vectors, the frontend's conversions, frame_rgb_into; with SDL2 # installed, the window itself, headless; # rung 2 scripts/lockstep.py on all 37 cases at full length, against upstream # megadrive-rust's md-trace at UPSTREAM (built into external/upstream). Upstream # is identical to megadrive-python on every case, so identical here is # identical to the reference. # rung 3 scripts/state_rung.py on all cases: this board straight through and through # save states (saved part way down a frame and loaded into a fresh system, # saved at a frame's start, a snapshot taken back after three frames), identical # line for line (src/state.rs). # megadrive-python itself (scripts/fetch_megadrivepython.sh, then lockstep.py without # --reference) is the check before a tag. # env: UPSTREAM (default 8a36258, megadrive-rust with the SVP ROM DMA fix), JOBS # (default 14), UPSTREAM_DIR (where upstream's worktree goes; default beside this # repository, because upstream's Cargo.toml finds its cores as ../ym2612-rust, # ../sn76489-rust and ../ssp1601-rust: inside external/ there are none) set -euo pipefail ROOT=$(cd "$(dirname "$0")/.." && pwd) UPSTREAM=${UPSTREAM:-8a36258} JOBS=${JOBS:-14} REF=${UPSTREAM_DIR:-"$(dirname "$ROOT")/megadrive-rust-fast-upstream"} cargo() { nice rustup run stable cargo "$@"; } if [ ! -d "$REF" ]; then git -C "$ROOT" fetch -q upstream git -C "$ROOT" worktree add -q --detach "$REF" "$UPSTREAM" fi [ "$(git -C "$REF" rev-parse --short=7 HEAD)" = "${UPSTREAM:0:7}" ] || git -C "$REF" checkout -q --detach "$UPSTREAM" echo "commit $(git -C "$ROOT" rev-parse --short HEAD)$(git -C "$ROOT" diff --quiet -- src || echo ' + working tree'), upstream $UPSTREAM" start=$(date +%s) CARGO_TARGET_DIR="$REF/target" cargo build --release -q --manifest-path "$REF/Cargo.toml" --bin md-trace CARGO_TARGET_DIR="$ROOT/target" cargo build --release -q --manifest-path "$ROOT/Cargo.toml" --bin md-trace if out=$(CARGO_TARGET_DIR="$ROOT/target" cargo test --release -q --manifest-path "$ROOT/Cargo.toml" 2>&1); then echo "rung 1: cargo test, $(grep -oE '[0-9]+ passed' <<<"$out" | awk '{s += $1} END {print s}') passed" else echo "rung 1 FAILED:"; tail -n 20 <<<"$out"; exit 1 fi # The window's tests too, headless, where SDL2 is installed (CI builds without it). if pkg-config --exists sdl2 2>/dev/null; then if out=$(CARGO_TARGET_DIR="$ROOT/target/frontend" cargo test --release -q --features frontend \ --manifest-path "$ROOT/Cargo.toml" --test frontend 2>&1); then echo "rung 1: the window headless, $(grep -oE '[0-9]+ passed' <<<"$out" | tail -n 1)" else echo "rung 1 FAILED (the window):"; tail -n 20 <<<"$out"; exit 1 fi fi if out=$(python3 "$ROOT/scripts/lockstep.py" --jobs "$JOBS" --reference "$REF/target/release/md-trace" 2>&1); then echo "rung 2: $(tail -n 1 <<<"$out")" else echo "rung 2 FAILED:"; grep -v " identical " <<<"$out" | tail -n 12; exit 1 fi if out=$(python3 "$ROOT/scripts/state_rung.py" --jobs "$JOBS" --rust "$ROOT/target/release/md-trace" 2>&1); then echo "rung 3: $(tail -n 1 <<<"$out")" else echo "rung 3 FAILED:"; grep -v " identical " <<<"$out" | tail -n 12; exit 1 fi echo "ladder clean in $(( $(date +%s) - start )) s"