#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Rung 3: the reference's conformance kit and validation streams. # 1. the committed kit stimuli and conformance.txt in tests/conformance/ must be what # scripts/export_streams.py writes from the reference at the pin; # 2. `cargo test --test conformance`: validation/conformance.txt reproduced exactly (11 cases); # 3. the reference's validation stream generators (rungs 2, 3, 4, 6 of its scripts/streams.py, # PER streams of each of 7 kinds, default 10) played on both cores, never the closed box; # traces identical byte for byte. # BIN/OURS/REUSE as for rung 2; CRATE: the copy whose cargo test to run (scripts/seeded_faults.py). set -euo pipefail source "$(dirname "$0")/env.sh" require_reference PER=${PER:-10} CRATE=${CRATE:-$ROOT} KIT="$ROOT/external/kit" DIR="$ROOT/external/streams-per$PER" status=0 if [ "${REUSE:-0}" != 1 ] || [ ! -f "$KIT/done" ]; then mkdir -p "$KIT" timeout 600 nice -n 19 "$REFERENCE_PYTHON" "$ROOT/scripts/export_streams.py" kit "$POKEY_PYTHON" "$KIT" >/dev/null for f in "$KIT"/*.txt; do cmp -s "$f" "$ROOT/tests/conformance/$(basename "$f")" || { echo "tests/conformance/$(basename "$f") is not the reference's"; exit 1; } done [ "$(ls "$KIT"/*.txt | wc -l)" = "$(ls "$ROOT"/tests/conformance/*.txt | wc -l)" ] || { echo "tests/conformance has a different number of files"; exit 1; } touch "$KIT/done" fi echo "kit stimuli: $(($(ls "$ROOT"/tests/conformance/*.txt | wc -l) - 1)) cases and conformance.txt, the reference's at the pin" if [ -z "${SKIP_CARGO_TEST:-}" ]; then if out=$(cd "$CRATE" && timeout 900 nice -n 19 cargo test --release -q --test conformance -- --nocapture 2>&1); then echo "$out" | grep -E "cases identical" | sed 's/^\.*//; s/^/conformance kit: /' else echo "$out" | grep -E "cases identical|panicked" | head -3 status=1 fi fi mkdir -p "$DIR/ref" if [ "${REUSE:-0}" != 1 ] || [ ! -f "$DIR/ref.done" ]; then mkdir -p "$DIR/scripts" timeout 600 nice -n 19 "$REFERENCE_PYTHON" "$ROOT/scripts/export_streams.py" streams "$POKEY_PYTHON" "$DIR/scripts" --per "$PER" >/dev/null ls "$DIR"/scripts/*.txt | timeout 3600 nice -n 19 xargs -P "$JOBS" -n 4 \ env PYTHONPATH="$POKEY_PYTHON/src" "$REFERENCE_PYTHON" "$ROOT/scripts/lockstep_ref.py" --out-dir "$DIR/ref" touch "$DIR/ref.done" fi if [ -z "${BIN:-}" ]; then (cd "$ROOT" && nice -n 19 cargo build --release -q --example pokey-trace) BIN="$ROOT/target/release/examples/pokey-trace" fi OURS=${OURS:-"$DIR/ours"} mkdir -p "$OURS" ls "$DIR"/scripts/*.txt | timeout 1800 nice -n 19 xargs -P "$JOBS" -n 8 "$BIN" --out-dir "$OURS" "$ROOT/scripts/compare_traces.sh" "$DIR/ref" "$OURS" "validation streams" | tail -2 || status=1 [ $status = 0 ] && echo "rung 3: PASS" || { echo "rung 3: FAIL"; exit 1; }