#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Rung 2: real code. Every MAME 0.285 trace of a 32X cartridge in SH2_MAME_TRACES # (bus-/master.log, the reference's scripts/mame_trace.py) replayed by sh2-replay, # the transcription of the reference's validation/rung2/replay.py: register-exact to the # end, with the reference's counts (sh2-python docs/validation.md, rung 2: instructions, # interrupts injected, MAME-attributed differences, first difference none). Then the # lockstep: the first PREFIX (default 2,000,000: the 32X boot ROM's first 300,000 are the # same in every cart) instructions of each on both cores, a CRC # of every bus cycle per 100,000 callbacks identical (scripts/replay_trace.py, cached). # FULL=0 skips the full replays (the seeded faults use the prefix only). set -euo pipefail source "$(dirname "$0")/env.sh" require_reference CACHE="$ROOT/external/reference-cache/${SH2_PYTHON_PIN:0:12}" mkdir -p "$CACHE" if [ -z "${BIN:-}" ]; then build; BIN="$ROOT/target/release"; fi OUT=${OUT:-"$ROOT/external/ours/main"} mkdir -p "$OUT" PREFIX=${PREFIX:-2000000} status=0 logs=$(ls "$SH2_MAME_TRACES"/bus-*/master.log 2>/dev/null || true) if [ -z "$logs" ]; then echo "rung 2: no MAME traces in $SH2_MAME_TRACES (skipped)"; exit 0; fi # The reference's results (its docs/validation.md, rung 2, at 12aed9b and since). declare -A WANT=( [BCRacersUSA]="30164032 25200 mame-interrupt-after-ldc=58" [DoomJapanUSAEn]="34555701 80 -" [KnucklesChaotixJapanUSAEn]="32543515 61 dma-writes=1387" [VirtuaRacingDeluxeUSA]="31791810 0 -" ) for log in $logs; do cart=$(basename "$(dirname "$log")"); cart=${cart#bus-} if [ "${FULL:-1}" = 1 ]; then nice -n 19 "$BIN/sh2-replay" "$log" > "$OUT/replay-$cart.json" || true got=$(python3 -c " import json, sys r = json.load(open(sys.argv[1])) a = ','.join(f'{k}={v}' for k, v in sorted(r['attributed'].items())) or '-' print(r['replayed'], r['interrupts_injected'], a, 'stopped' if r['stopped_at'] else 'clean', r['instructions_per_second']) " "$OUT/replay-$cart.json") set -- $got if [ "$1 $2 $3" = "${WANT[$cart]:-none}" ] && [ "$4" = clean ]; then echo "rung 2 $cart: $1 instructions, $2 interrupts injected, attributed $3, no other difference ($5 instructions/s)" else echo "rung 2 $cart: DIFFERENT: $got (want ${WANT[$cart]:-?} clean)"; status=1 fi fi ref="$CACHE/replay-$cart-$PREFIX.txt" if [ ! -f "$ref" ]; then nice -n 19 "$REFERENCE_PYTHON" "$ROOT/scripts/replay_trace.py" "$SH2_PYTHON" "$log" "$ref.partial" --limit "$PREFIX" --slices 100000 > "$ref.json" mv "$ref.partial" "$ref" fi nice -n 19 "$BIN/sh2-replay" "$log" --limit "$PREFIX" --slices 100000 --out "$OUT/replay-$cart-$PREFIX.txt" > /dev/null || true if cmp -s "$ref" "$OUT/replay-$cart-$PREFIX.txt"; then echo "rung 2 $cart lockstep: $PREFIX instructions, $(tail -1 "$ref" | cut -d' ' -f2) bus callbacks identical" else echo "rung 2 $cart lockstep: DIFFERENT"; status=1 fi done exit $status