omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-gpu-driver / tests / dispatch_diff.sh
| 1 | #!/bin/sh |
| 2 | # tests/dispatch_diff.sh: builds the .om GSP sequencer dispatcher (gsp/dispatch.om) |
| 3 | # and the C referee (tests/dispatch_ref.c against gsp_seq.c and gsp_sim.c), |
| 4 | # runs every case in tests/dispatch_cases.txt through both, and requires |
| 5 | # byte-identical traces (rc, state, dead, why, delays, core calls, save[8], register log, violations). |
| 6 | # Host verification only. Never invokes VFIO, device opens, or kernel module actions. |
| 7 | set -u |
| 8 | here=$(cd "$(dirname "$0")/.." && pwd) |
| 9 | AIENUX=${AIENUX:-/tmp/omega-driver-reference} |
| 10 | [ -d "$AIENUX/native/kernel" ] || AIENUX=/home/drakestapleton/work/OwnDriver/omega-driver-reference |
| 11 | OMC=${OMC:-$here/build/omc} |
| 12 | [ -f "$OMC" ] || OMC=/home/drakestapleton/work/OwnDriver/omega-mv-vfio/seed/out/omc |
| 13 | SEQ_OM=${SEQ_OM:-$here/gsp/seq.om} |
| 14 | RPC_OM=${RPC_OM:-$here/gsp/rpc.om} |
| 15 | BOOT_OM=${BOOT_OM:-$here/gsp/boot.om} |
| 16 | DISPATCH_OM=${DISPATCH_OM:-$here/gsp/dispatch.om} |
| 17 | OMC_PIN=$here/tools/omc.pin |
| 18 | [ -f "$OMC_PIN" ] || OMC_PIN=/home/drakestapleton/work/OwnDriver/omega-mv-vfio/tools/omc.pin |
| 19 | OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$OMC_PIN" 2>/dev/null || echo "bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6") |
| 20 | run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; } |
| 21 | |
| 22 | got=$(sha256sum "$OMC" 2>/dev/null | cut -d' ' -f1) |
| 23 | if [ "$got" != "$OMC_SHA" ]; then |
| 24 | echo "dispatch_diff: FAIL omc sha256 $got, pinned $OMC_SHA"; exit 2 |
| 25 | fi |
| 26 | |
| 27 | # Hard device-safety check: neither dispatch nor test harness may reference device paths or IOCTLs |
| 28 | if grep -n 'put gspmode [0-9]* [1-9]\|gspbar\|vfio\|mapnew\|/dev/\|/sys/' "$here/tests/dispatch_trace.om" "$DISPATCH_OM"; then |
| 29 | echo "dispatch_diff: FAIL dispatch or test driver names a device"; exit 2 |
| 30 | fi |
| 31 | |
| 32 | t=$(mktemp -d /tmp/dispatch_diff.XXXXXX) || exit 2 |
| 33 | trap 'rm -rf "$t"' EXIT |
| 34 | |
| 35 | k=$AIENUX/native/kernel |
| 36 | if ! run cc -std=c11 -O1 -Wall -Werror -I"$k/gpu" -o "$t/ref" "$here/tests/dispatch_ref.c" "$k/gpu/gsp_seq.c" "$k/gpu/gsp_sim.c"; then |
| 37 | echo "dispatch_diff: FAIL C referee build"; exit 2 |
| 38 | fi |
| 39 | |
| 40 | REPLAY_OM="" |
| 41 | if [ -f "$here/gsp/replay.om" ]; then |
| 42 | REPLAY_OM="$here/gsp/replay.om" |
| 43 | fi |
| 44 | |
| 45 | if ! cat "$here/gsp/mmio.om" "$here/gsp/sim.om" "$SEQ_OM" "$RPC_OM" $REPLAY_OM "$here/gsp/sysinfo.om" "$here/chan/params.om" "$BOOT_OM" "$DISPATCH_OM" "$here/tests/dispatch_trace.om" | run "$OMC" > "$t/om"; then |
| 46 | echo "dispatch_diff: FAIL omc build"; exit 3 |
| 47 | fi |
| 48 | chmod +x "$t/om" |
| 49 | |
| 50 | fail=0 |
| 51 | cases=$here/tests/dispatch_cases.txt |
| 52 | |
| 53 | run "$t/ref" < "$cases" > "$t/c.cases"; echo "exit $?" >> "$t/c.cases" |
| 54 | run "$t/om" < "$cases" > "$t/o.cases"; echo "exit $?" >> "$t/o.cases" |
| 55 | |
| 56 | if ! cmp -s "$t/c.cases" "$t/o.cases"; then |
| 57 | echo "dispatch_diff: cases output differs (C left, .om right)"; diff -u "$t/c.cases" "$t/o.cases" | head -20; fail=1 |
| 58 | fi |
| 59 | |
| 60 | want=$(grep -Evc '^(#|[[:space:]]*$)' "$cases") |
| 61 | n=$(grep -c '^== ' "$t/o.cases") |
| 62 | if [ "$n" -ne "$want" ] || [ "$(tail -n 1 "$t/o.cases")" != "exit 0" ]; then |
| 63 | echo "dispatch_diff: ran $n of $want cases"; tail -n 1 "$t/o.cases"; fail=1 |
| 64 | fi |
| 65 | |
| 66 | # Verification of negative controls and behavioral constraints: |
| 67 | # 1. Zero writes on malformed late op (proves full prevalidation prevented any partial effects) |
| 68 | late_unk=$(grep '^== late-unkop ' "$t/o.cases") |
| 69 | case "$late_unk" in |
| 70 | *"rc=-3"*"state=12"*"dead=1"*"nlog=0"*) ;; |
| 71 | *) echo "dispatch_diff: FAIL late-unkop side-effect control: $late_unk"; fail=1 ;; |
| 72 | esac |
| 73 | |
| 74 | late_badstore=$(grep '^== late-badstore ' "$t/o.cases") |
| 75 | case "$late_badstore" in |
| 76 | *"rc=-6"*"state=12"*"dead=1"*"nlog=0"*) ;; |
| 77 | *) echo "dispatch_diff: FAIL late-badstore side-effect control: $late_badstore"; fail=1 ;; |
| 78 | esac |
| 79 | |
| 80 | # 2. Stale token / generation returns -10 without entering quarantine (state remains 11, dead=0) |
| 81 | stale_gen=$(grep '^== stale-gen ' "$t/o.cases") |
| 82 | case "$stale_gen" in |
| 83 | *"rc=-10"*"state=11"*"dead=0"*"nlog=0"*) ;; |
| 84 | *) echo "dispatch_diff: FAIL stale-gen state control: $stale_gen"; fail=1 ;; |
| 85 | esac |
| 86 | |
| 87 | stale_tok=$(grep '^== stale-tok ' "$t/o.cases") |
| 88 | case "$stale_tok" in |
| 89 | *"rc=-10"*"state=11"*"dead=0"*"nlog=0"*) ;; |
| 90 | *) echo "dispatch_diff: FAIL stale-tok state control: $stale_tok"; fail=1 ;; |
| 91 | esac |
| 92 | |
| 93 | # 3. Poll timeout enters quarantine |
| 94 | poll_fail=$(grep '^== poll-fail ' "$t/o.cases") |
| 95 | case "$poll_fail" in |
| 96 | *"rc=-5"*"state=12"*"dead=1"*) ;; |
| 97 | *) echo "dispatch_diff: FAIL poll-fail quarantine control: $poll_fail"; fail=1 ;; |
| 98 | esac |
| 99 | |
| 100 | # 4. Core matrix: all 4 core opcodes refuse without callback or without permission |
| 101 | for op in 5 6 7 8; do |
| 102 | nocall=$(grep "^== core${op}-nocall " "$t/o.cases") |
| 103 | case "$nocall" in |
| 104 | *"rc=-7"*"state=12"*"dead=1"*"core=0"*) ;; |
| 105 | *) echo "dispatch_diff: FAIL core${op}-nocall refusal: $nocall"; fail=1 ;; |
| 106 | esac |
| 107 | noperm=$(grep "^== core${op}-noperm " "$t/o.cases") |
| 108 | case "$noperm" in |
| 109 | *"rc=-7"*"state=12"*"dead=1"*"core=0"*) ;; |
| 110 | *) echo "dispatch_diff: FAIL core${op}-noperm refusal: $noperm"; fail=1 ;; |
| 111 | esac |
| 112 | done |
| 113 | # 5. Non-sim mode: allpermissions+sqcore cannot activate core in non-sim mode (refuses before effect) |
| 114 | core_nonsim=$(grep '^== core-nonsim ' "$t/o.cases") |
| 115 | case "$core_nonsim" in |
| 116 | *"rc=-7"*"state=12"*"dead=1"*"core=0"*"nlog=0"*) ;; |
| 117 | *) echo "dispatch_diff: FAIL core-nonsim side-effect control: $core_nonsim"; fail=1 ;; |
| 118 | esac |
| 119 | |
| 120 | # No typed MMIO span: reject even register-only hardware sequences before the first write. |
| 121 | late_reg=$(grep '^== late-invalidreg ' "$t/o.cases") |
| 122 | case "$late_reg" in |
| 123 | *"rc=-7"*"state=12"*"dead=1"*"delays=0/0"*"core=0"*"nlog=0"*"violations=0"*) ;; |
| 124 | *) echo "dispatch_diff: FAIL late-invalidreg whole-dispatch refusal: $late_reg"; fail=1 ;; |
| 125 | esac |
| 126 | |
| 127 | if [ "$fail" -eq 0 ]; then |
| 128 | echo "dispatch_diff: PASS host-model trace parity, payload prevalidation, hardware-dispatch refusal, and quarantine controls; hardware NOT_RUN" |
| 129 | sha256sum "$here/gsp/dispatch.om" "$cases" "$here/tests/dispatch_ref.c" "$here/tests/dispatch_trace.om" |
| 130 | exit 0 |
| 131 | else |
| 132 | exit 1 |
| 133 | fi |