#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Rung 2: register-stream lockstep. Seeded random and scripted streams for both variants # (scripts/lockstep_gen.py) run on both cores; every read, irq, frame, channel_values() and # state dump, and every table, must be identical byte for byte. # Usage: scripts/rung2.sh [count per variant, default 96] [seed, default 1] [steps, default 2000] # BIN: another build of examples/ym2612-trace to judge (scripts/seeded_faults.py uses it); # REUSE=1 keeps the reference traces already written; OURS: where this core's traces go. set -euo pipefail source "$(dirname "$0")/env.sh" COUNT=${1:-96}; SEED=${2:-1}; STEPS=${3:-2000} DIR="$ROOT/external/lockstep/seed$SEED-n$COUNT-s$STEPS" mkdir -p "$DIR/scripts" "$DIR/ref" if [ -z "${BIN:-}" ]; then (cd "$ROOT" && nice cargo build --release -q --example ym2612-trace) BIN="$ROOT/target/release/examples/ym2612-trace" fi if [ "${REUSE:-0}" != 1 ] || [ ! -f "$DIR/ref.done" ]; then python3 "$ROOT/scripts/lockstep_gen.py" "$DIR/scripts" --count "$COUNT" --seed "$SEED" --steps "$STEPS" >/dev/null "$PYTHON" -c "import ym2612_python, sys; assert ym2612_python.__file__.startswith('$REF/'), ym2612_python.__file__" ls "$DIR"/scripts/*.txt | nice xargs -P "$JOBS" -n 4 env PYPY_GC_NURSERY=1M "$PYTHON" "$ROOT/scripts/lockstep_ref.py" --out-dir "$DIR/ref" touch "$DIR/ref.done" fi OURS=${OURS:-"$DIR/ours"} mkdir -p "$OURS" ls "$DIR"/scripts/*.txt | nice xargs -P "$JOBS" -n 8 "$BIN" --out-dir "$OURS" status=0; same=0; total=0; lines=0 for ref in "$DIR"/ref/*.trace; do total=$((total + 1)) name=$(basename "$ref") if cmp -s "$ref" "$OURS/$name"; then same=$((same + 1)); lines=$((lines + $(wc -l < "$ref"))) else status=1 first=$(diff <(cut -c1-160 "$ref") <(cut -c1-160 "$OURS/$name") | head -4 | tr '\n' ' ' || true) echo "DIFFERENT ${name%.trace}: $first" fi done frames=$(cat "$DIR"/ref/*.trace | awk '$1=="take"{n+=$2} END{print n+0}') reads=$(cat "$DIR"/ref/*.trace | grep -c '^r ' || true) states=$(cat "$DIR"/ref/*.trace | grep -c '^state ' || true) values=$(cat "$DIR"/ref/*.trace | grep -cE '^(v|cv) ' || true) echo "rung 2: $same of $total scripts identical ($frames frames, $reads reads, $values channel_values, $states state dumps, $lines trace lines)" [ $status = 0 ] && echo "rung 2: PASS" || echo "rung 2: FAIL" exit $status