# SPDX-License-Identifier: MIT # Sourced by the rung scripts: the reference, its interpreter, the toolchain and the helpers. ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) REF=${AY8910_PYTHON:-"$ROOT/external/ay8910-python"} PYTHON=${PYTHON:-"$ROOT/external/venv/bin/python"} [ -f "$REF/scripts/streams.py" ] && [ -x "$PYTHON" ] || { echo "no reference at $REF (or no $PYTHON): run scripts/fetch_ay8910python.sh" >&2; exit 2; } # ay8910-python's board streams (validation/streams/*.stream: derived from ROMs, local only), # from a checkout beside this repository unless AY8910_BOARD_STREAMS names them. BOARD_STREAMS=${AY8910_BOARD_STREAMS:-"$(dirname "$ROOT")/ay8910-python/validation/streams"} # A cargo whose clippy matches its rustc, when the default one's does not. STABLE="$HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin" [ -x "$STABLE/cargo" ] && PATH="$STABLE:$PATH" JOBS=${JOBS:-6} export PYPY_GC_NURSERY=${PYPY_GC_NURSERY:-1M} # The Rust side's trace binary: BIN if given (scripts/seeded_faults.py builds its own). trace_binary() { if [ -z "${BIN:-}" ]; then (cd "$ROOT" && nice cargo build --release -q --features serde --example ay8910-trace) BIN="$ROOT/target/release/examples/ay8910-trace" fi } # reference_traces DIR: the reference's trace of every DIR/scripts/*.txt into DIR/ref, # unless REUSE=1 and they are already there. reference_traces() { local dir=$1 if [ "${REUSE:-0}" != 1 ] || [ ! -f "$dir/ref.done" ]; then mkdir -p "$dir/ref" ls -S "$dir"/scripts/*.txt | nice xargs -P "$JOBS" -n 1 "$PYTHON" -I "$ROOT/scripts/lockstep_ref.py" --out-dir "$dir/ref" touch "$dir/ref.done" fi } # compare DIR OURS: every reference trace against ours, byte for byte; sets SAME, TOTAL, STATUS. compare() { local dir=$1 ours=$2 ref name STATUS=0; SAME=0; TOTAL=0 for ref in "$dir"/ref/*.trace; do TOTAL=$((TOTAL + 1)) name=$(basename "$ref") if cmp -s "$ref" "$ours/$name"; then SAME=$((SAME + 1)) else STATUS=1 echo "DIFFERENT ${name%.trace}: $(diff <(cut -c1-160 "$ref") <(cut -c1-160 "$ours/$name" 2>/dev/null) | head -4 | tr '\n' ' ' || true)" fi done }