#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Rung 2: bus-stream lockstep. Seeded random and scripted scripts for every part # (scripts/lockstep_gen.py) run on both cores; every clock's three codes (hashed per take or # poll), every read, every port change, every mix() and take_samples() float (as bits), the # whole state at checkpoints and the tables must be identical. # Usage: scripts/rung2.sh [count per part, default 48] [seed, default 1] [steps, default 3000] # BIN: another build of examples/ay8910-trace to judge (scripts/seeded_faults.py uses it); # OURS: where its traces go; REUSE=1 keeps the reference traces already written; # ROUNDTRIP=1 runs ours through a save state at every save, state and take (rung 4). set -euo pipefail source "$(dirname "$0")/env.sh" COUNT=${1:-48}; SEED=${2:-1}; STEPS=${3:-3000} DIR="$ROOT/external/lockstep/seed$SEED-n$COUNT-s$STEPS" mkdir -p "$DIR/scripts" trace_binary 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 fi reference_traces "$DIR" OURS=${OURS:-"$DIR/ours"} mkdir -p "$OURS" flag=(); [ "${ROUNDTRIP:-0}" = 1 ] && flag=(--roundtrip) ls "$DIR"/scripts/*.txt | nice xargs -P "$JOBS" -n 8 "$BIN" "${flag[@]}" --out-dir "$OURS" compare "$DIR" "$OURS" clocks=$(cat "$DIR"/ref/*.trace | awk '$1=="take"||$1=="tick"||$1=="samples"{n+=$2} END{print n+0}') writes=$(cat "$DIR"/scripts/*.txt | grep -cE '^(w|d) ' || true) reads=$(cat "$DIR"/ref/*.trace | grep -cE '^(r|rr) ' || true) ports=$(cat "$DIR"/ref/*.trace | grep -c '^P ' || true) states=$(cat "$DIR"/ref/*.trace | grep -c '^state ' || true) saves=$(cat "$DIR"/scripts/*.txt | grep -cE '^(save|state|take)$' || true) what="rung 2"; [ "${ROUNDTRIP:-0}" = 1 ] && what="rung 4 (rung 2's scripts, $saves save-state round trips)" echo "$what: $SAME of $TOTAL scripts identical ($writes data writes, $reads reads, $ports port changes, $clocks clocks' codes, $states state checkpoints)" [ $STATUS = 0 ] && echo "$what: PASS" || echo "$what: FAIL" exit $STATUS