interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

branch main Branches Tags History

omega-gpu-driver / tests / pm_gate.sh

34 lines · 1940 bytes Raw Blame History
1#!/bin/sh
2# pm_gate.sh: runtime-PM planted fault (tests/pm_gate.om) on the real gsp/mmio.om, then two mutants that
3# must go red: the gate removed, and the gate accepting any runtime_status text. Host only: the device
4# file is a temp file, never /sys. Exit 0 PASS, 1 FAIL, 2 setup.
5set -u
6here=$(cd "$(dirname "$0")/.." && pwd)
7OMC=${OMC:-$here/build/omc}
8OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$here/tools/omc.pin")
9run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; }
10[ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$OMC_SHA" ] || { echo "pm_gate: FAIL omc pin"; exit 2; }
11t=$(mktemp -d /tmp/pm_gate.XXXXXX) || exit 2
12trap 'rm -rf "$t"' EXIT
13printf 'suspended\n' > "$t/sus"
14printf 'active\n' > "$t/act"
15printf 'activa\n' > "$t/near"
16# build SRC -> run -> exit code
17try() {
18 cat "$1" "$here/gsp/sim.om" "$here/tests/pm_gate.om" | run "$OMC" > "$t/p" 2>"$t/err" || return 200
19 chmod +x "$t/p"
20 run "$t/p" "$t/sus" "$t/act" "$t/near" >/dev/null 2>&1
21}
22try "$here/gsp/mmio.om"; rc=$?
23[ "$rc" -eq 0 ] || { echo "pm_gate: FAIL baseline exit $rc"; exit 1; }
24# mutant 1: the gate call removed (3 lines: if not gsppm / ret gspfail EPM / end)
25awk '$0=="if not gsppm"{s=3} s>0{s--; next} {print}' "$here/gsp/mmio.om" > "$t/m1.om"
26cmp -s "$here/gsp/mmio.om" "$t/m1.om" && { echo "pm_gate: FAIL mutant 1 did not apply"; exit 2; }
27try "$t/m1.om"; m1=$?
28# mutant 2: the reader stops comparing bytes
29awk '$0=="if ne get gpmb i get pmact i"{print "if false"; next} {print}' "$here/gsp/mmio.om" > "$t/m2.om"
30cmp -s "$here/gsp/mmio.om" "$t/m2.om" && { echo "pm_gate: FAIL mutant 2 did not apply"; exit 2; }
31try "$t/m2.om"; m2=$?
32[ "$m1" -ne 0 ] && [ "$m1" -ne 200 ] || { echo "pm_gate: FAIL mutant 1 (gate removed) exit $m1"; exit 1; }
33[ "$m2" -ne 0 ] && [ "$m2" -ne 200 ] || { echo "pm_gate: FAIL mutant 2 (any text accepted) exit $m2"; exit 1; }
34echo "pm_gate: PASS (5 cases; mutants red: gate removed exit $m1, any text accepted exit $m2)"