#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Rung U: this fork against sh2-rust itself, no Python on the judged side. # # The -fast tier's own obligation (charter: every bus cycle identical to x-rust). sh2-rust # at UPSTREAM_REV (default: the fork point, fcb9dae) is built in a clone # (target/upstream-tree, its own target dir) and both builds' sh2-trace run on every # scenario family the ladder uses plus extra fuzz and fresh-chip seeds the reference cache # does not hold (generated by the reference's scenario writer, which is quick: it writes # programs, it does not run them), and both builds' sh2-replay on a longer prefix of each # MAME trace. Every trace file must be byte-identical. # # scripts/upstream.sh # env: UPSTREAM_REV, SEEDS (default "3 4 5 6 7 8"), PREFIX_UP (default 4000000), # SH2_BLOCK_CACHE (passed through: 1 judges the cached interpreter, src/blocks.rs) set -euo pipefail ROOT=$(cd "$(dirname "$0")/.." && pwd) source "$ROOT/scripts/env.sh" UPSTREAM_REV=${UPSTREAM_REV:-fcb9dae} SEEDS=${SEEDS:-"3 4 5 6 7 8"} PREFIX_UP=${PREFIX_UP:-4000000} TREE="$ROOT/target/upstream-tree" UPSTREAM_REPO=$(git -C "$ROOT" remote get-url upstream) rev=$(git -C "$UPSTREAM_REPO" rev-parse --short "$UPSTREAM_REV") # a clone, not a worktree: sh2-rust's own .git is left alone [ -d "$TREE" ] || git clone -q "$UPSTREAM_REPO" "$TREE" git -C "$TREE" fetch -q origin git -C "$TREE" checkout -q -f --detach "$rev" CARGO_TARGET_DIR="$ROOT/target/upstream" nice -n 19 cargo build --release -q -j "$JOBS" \ --manifest-path "$TREE/Cargo.toml" --bin sh2-trace --bin sh2-replay build UP="$ROOT/target/upstream/release" OURS="$ROOT/target/release" S="$ROOT/external/scenarios" dirs=("$S/pipeline" "$S/rung4" "$S/edges" "$S/fuzz-s1-n40" "$S/fuzz-s2-n40" "$S/fresh-s1-n10" "$S/fresh-s2-n10") for seed in $SEEDS; do for family in fuzz fresh; do n=40; [ $family = fresh ] && n=10 d="$S/$family-s$seed-n$n" [ -d "$d" ] || nice -n 19 "$REFERENCE_PYTHON" "$ROOT/scripts/make_scenarios.py" "$SH2_PYTHON" "$d" \ --only $family --fuzz $n --seed "$seed" > /dev/null dirs+=("$d") done done OUT="$ROOT/external/upstream-lockstep" mkdir -p "$OUT/up" "$OUT/ours" total=0; same=0; failed=() for d in "${dirs[@]}"; do files=("$d"/*.json) # in groups, two processes at a time (the machine is shared) printf '%s\0' "${files[@]}" | nice -n 19 xargs -0 -n 40 -P "$JOBS" "$UP/sh2-trace" "$OUT/up" > /dev/null printf '%s\0' "${files[@]}" | nice -n 19 xargs -0 -n 40 -P "$JOBS" "$OURS/sh2-trace" "$OUT/ours" > /dev/null for f in "${files[@]}"; do name=$(basename "$f" .json) total=$((total + 1)) if cmp -s "$OUT/up/$name.trace" "$OUT/ours/$name.trace"; then same=$((same + 1)); else failed+=("$name"); fi done done echo "rung U scenarios: $same of $total identical to sh2-rust $rev" status=0 [ ${#failed[@]} -eq 0 ] || { printf 'DIFFERENT %s\n' "${failed[@]:0:10}"; status=1; } logs=$(ls "$SH2_MAME_TRACES"/bus-*/master.log 2>/dev/null || true) for log in $logs; do cart=$(basename "$(dirname "$log")"); cart=${cart#bus-} nice -n 19 "$UP/sh2-replay" "$log" --limit "$PREFIX_UP" --slices 100000 --out "$OUT/up/replay-$cart.txt" > /dev/null || true nice -n 19 "$OURS/sh2-replay" "$log" --limit "$PREFIX_UP" --slices 100000 --out "$OUT/ours/replay-$cart.txt" > /dev/null || true if cmp -s "$OUT/up/replay-$cart.txt" "$OUT/ours/replay-$cart.txt"; then echo "rung U $cart: $PREFIX_UP instructions, $(tail -1 "$OUT/up/replay-$cart.txt" | cut -d' ' -f2) bus callbacks identical" else echo "rung U $cart: DIFFERENT"; status=1 fi done exit $status