#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Rung 3: the register streams of the reference's validation/closed_box.py (55, both of its # input tables, and its status stream), run through both cores (not the model): every frame, # read and channel value identical. scripts/closed_box_streams.py imports the stream # definitions from the reference; the harness is neither built nor run. # BIN, REUSE and OURS as for scripts/rung2.sh. set -euo pipefail source "$(dirname "$0")/env.sh" DIR="$ROOT/external/closed-box" 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 "$PYTHON" "$ROOT/scripts/closed_box_streams.py" "$DIR/scripts" ls "$DIR"/scripts/*.txt | nice xargs -P "$JOBS" -n 2 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 4 "$BIN" --out-dir "$OURS" 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 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}') values=$(cat "$DIR"/ref/*.trace | grep -c '^v ' || true) reads=$(cat "$DIR"/ref/*.trace | grep -c '^r ' || true) echo "rung 3: $same of $total scripts identical ($frames frames, $values channel_values samples, $reads reads)" [ $status = 0 ] && echo "rung 3: PASS" || echo "rung 3: FAIL" exit $status