omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-gpu-driver / tests / mutants-window.sh
| 1 | #!/bin/sh |
| 2 | # tests/mutants-window.sh -- each mutant removes one safety step from a copy of window/*.sh; tests/window_sim.sh |
| 3 | # must then fail. Test-only shell; evidence label EXERCISED (host simulator). |
| 4 | set -eu |
| 5 | R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) |
| 6 | W=$(mktemp -d /tmp/owndriver-window-mut.XXXXXX) |
| 7 | killed=0 |
| 8 | total=0 |
| 9 | # file@sed expression@what the mutant removes |
| 10 | MUTANTS='common.sh@s/^need_approval() {$/need_approval() { return 0/@approval check |
| 11 | common.sh@s/^privcheck() {$/privcheck() { return 0/@privilege check |
| 12 | common.sh@/\[ "$s" = active \] || die/d@runtime PM active check |
| 13 | d2-pre.sh@s/^flock -n 9 || die/true || die/@W1 chip lock |
| 14 | d2-pre.sh@s/^trap .abort_w1. EXIT$/:/@W1 abort trap |
| 15 | d2-pre.sh@s/^\tif cmp -s "$SNAP.now" "$SNAP.want"; then$/\tif true; then/@W0 launch record check |
| 16 | d2-pre.sh@s/^\[ "$STAGE" = D2 \] || has_mode exec ||/true ||/@D3 needs ogd |
| 17 | common.sh@s/^\tmodes=$("$BUILD\/ogd" modes 2>\/dev\/null) || return 1$/\tmodes=$("$BUILD\/ogd" modes 2>\/dev\/null) || true/@D3 failed mode query |
| 18 | d2-pre.sh@s/^\[ "$STAGE" = D2 \] || has_mode exec ||/[ "$STAGE" = D2 ] || [ -x "$BUILD\/ogd" ] ||/@D3 model-only executable |
| 19 | d2-pre.sh@s/^\t(cd "$BUILD\/fw" .* sha256sum -c --quiet .*) ||$/\ttrue ||/@W0 build\/fw hash check |
| 20 | d2-run.sh@s/^echo restore > "$STATE"$/:/@W2 state=restore before acting |
| 21 | d2-run.sh@s/^flock -n 9 || die/true || die/@W2 chip lock |
| 22 | d2-run.sh@/^\[ "$m" = root:root:600 \] || die/d@W2 /dev/vfio mode check |
| 23 | d2-run.sh@s/^\tpm_auto$/\t:/@W7 power\/control=auto |
| 24 | d2-restore.sh@s/^fallback() {$/fallback() { die "$*"/@R1 reboot fallback |
| 25 | d2-restore.sh@s/^\tif \[ -e "$FALLBACK" \]; then$/\tif false; then/@R1 fallback only once |
| 26 | d2-restore.sh@s/^\tsudo -n sysctl -q -p "$SAVED" || die/\ttrue || die/@R2 sysctl restore |
| 27 | d2-restore.sh@s/^sudo -n rm -f "$UNIT"$/:/@R4 unit removal |
| 28 | d2-restore.sh@s/^rm -f "$LIVE_MARKER" "$APPROVAL"/rm -f "$LIVE_MARKER"/@R4 approval removal |
| 29 | d2-boot.sh@s/^\tsudo -n rm -f "$UNIT"$/\t:/@stale unit removal' |
| 30 | printf '%s\n' "$MUTANTS" > "$W/list" |
| 31 | while IFS='@' read -r f expr what; do |
| 32 | total=$((total + 1)) |
| 33 | M=$W/m$total |
| 34 | mkdir -p "$M/build" |
| 35 | cp -r "$R/window" "$R/tools" "$R/tests" "$M/" |
| 36 | ln -s "$R/build/omc" "$M/build/omc" |
| 37 | sed -i "$expr" "$M/window/$f" |
| 38 | if cmp -s "$R/window/$f" "$M/window/$f"; then |
| 39 | echo "BROKEN mutant $total ($what): sed did not change window/$f" |
| 40 | rm -rf "$W" |
| 41 | exit 2 |
| 42 | fi |
| 43 | if SIMDIR=$W/sim$total sh "$M/tests/window_sim.sh" > "$W/out$total" 2>&1; then |
| 44 | echo "SURVIVED $total: $what ($f)" |
| 45 | else |
| 46 | killed=$((killed + 1)) |
| 47 | echo "killed $total: $what ($f): $(tail -1 "$W/out$total" | sed 's/.*in://')" |
| 48 | fi |
| 49 | for s in "$W"/sim$total/*/st/35b; do [ -s "$s" ] && kill "$(cat "$s")" 2>/dev/null || true; done |
| 50 | done < "$W/list" |
| 51 | rm -rf "$W" |
| 52 | echo "mutants-window: $killed/$total killed" |
| 53 | [ "$killed" -eq "$total" ] |