#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Seeded faults for the host's own code: each one-line fault is applied to a copy of # src/lib.rs, the wasm is built, scripts/check-node.mjs runs on scripts/smoke-short.txt, and # the fault must be caught (the check fails). src/lib.rs is put back from git after each. # Usage: bash -lc 'scripts/seeded-faults.sh' (NO_INTRO_DIR set; takes a few minutes) set -uo pipefail ROOT=$(cd "$(dirname "$0")/.." && pwd) cd "$ROOT" git diff --quiet -- src/lib.rs || { echo "src/lib.rs has uncommitted changes"; exit 2; } faults=( "restore-forgets-screen| *self.screen.borrow_mut() = screen;| let _ = screen;" "state-drops-wheel|out.extend_from_slice(&self.driving_position().to_le_bytes());|out.extend_from_slice(\&0i64.to_le_bytes());" "check-takes-no-samples| crc.update(&sample.to_le_bytes());| let _ = sample;" "frame-cap-not-chunked| for _ in 0..50 {| for _ in 0..1 {" ) caught=0 for f in "${faults[@]}"; do IFS='|' read -r name old new <<<"$f" python3 - "$old" "$new" <<'PY' import sys old, new = sys.argv[1], sys.argv[2].replace('\\&', '&') s = open('src/lib.rs').read() assert s.count(old) == 1, old open('src/lib.rs', 'w').write(s.replace(old, new)) PY touch src/lib.rs if ! timeout 600 scripts/build-wasm.sh >target/seeded-faults.log 2>&1; then echo "BUILD FAILED $name (not counted)" elif FRAMES=120 SMOKE=scripts/smoke-short.txt timeout 600 node scripts/check-node.mjs >target/seeded-faults.log 2>&1; then echo "MISSED $name" else echo "caught $name: $(grep -c FAIL target/seeded-faults.log) failing case(s)"; caught=$((caught+1)) fi git checkout -q -- src/lib.rs done touch src/lib.rs timeout 600 scripts/build-wasm.sh >/dev/null echo "$caught of ${#faults[@]} seeded faults caught"