#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Rung 3: the reference's validation streams, the 51 of validation/closed_box.py's streams(), # replayed through both cores (never the closed-box model) on each of the four parts. # 1. the committed scripts in tests/closed_box/ must be what scripts/export_closed_box.py # writes from the reference at the pin; # 2. sn76489-python's traces and this core's must be identical byte for byte; # 3. `cargo test --test closed_box` (the committed SHA-256 of the reference's traces). # BIN/OURS as for rung 2 (scripts/seeded_faults.py uses them). set -euo pipefail source "$(dirname "$0")/env.sh" DIR="$ROOT/external/closed_box" mkdir -p "$DIR/ref" if [ "${REUSE:-0}" != 1 ] || [ ! -f "$DIR/ref.done" ]; then mkdir -p "$DIR/scripts" PYTHONPATH="$REF/src" "$PYTHON" "$ROOT/scripts/export_closed_box.py" "$REF" "$DIR/scripts" >/dev/null for f in "$DIR"/scripts/*.txt; do cmp -s "$f" "$ROOT/tests/closed_box/$(basename "$f")" || { echo "tests/closed_box/$(basename "$f") is not the reference's stream"; exit 1; } done [ "$(ls "$DIR"/scripts/*.txt | wc -l)" = "$(ls "$ROOT"/tests/closed_box/*.txt | wc -l)" ] || { echo "tests/closed_box has a different number of streams"; exit 1; } echo "streams: $(ls "$DIR"/scripts/*.txt | wc -l) scripts, the reference's at the pin" ls "$DIR"/scripts/*.txt | nice xargs -P "$JOBS" -n 8 env PYTHONPATH="$REF/src" "$PYTHON" "$ROOT/scripts/lockstep_ref.py" --out-dir "$DIR/ref" touch "$DIR/ref.done" fi if [ -z "${BIN:-}" ]; then (cd "$ROOT" && nice cargo build --release -q --example sn76489-trace) BIN="$ROOT/target/release/examples/sn76489-trace" fi OURS=${OURS:-"$DIR/ours"} mkdir -p "$OURS" ls "$ROOT"/tests/closed_box/*.txt | nice xargs -P "$JOBS" -n 16 "$BIN" --out-dir "$OURS" status=0 "$ROOT/scripts/compare_traces.sh" "$DIR/ref" "$OURS" "rung 3 (traces)" | tail -2 || status=1 if [ -z "${SKIP_CARGO_TEST:-}" ]; then out=$(cd "$ROOT" && nice cargo test --release -q --test closed_box -- --nocapture 2>&1) || status=1 echo "$out" | grep -E "closed-box traces identical|differ" || true fi [ $status = 0 ] && echo "rung 3: PASS" || { echo "rung 3: FAIL"; exit 1; }