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 / dispatch_diff.sh

133 lines · 5759 bytes Raw Blame History
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.
7set -u
8here=$(cd "$(dirname "$0")/.." && pwd)
9AIENUX=${AIENUX:-/tmp/omega-driver-reference}
10[ -d "$AIENUX/native/kernel" ] || AIENUX=/home/drakestapleton/work/OwnDriver/omega-driver-reference
11OMC=${OMC:-$here/build/omc}
12[ -f "$OMC" ] || OMC=/home/drakestapleton/work/OwnDriver/omega-mv-vfio/seed/out/omc
13SEQ_OM=${SEQ_OM:-$here/gsp/seq.om}
14RPC_OM=${RPC_OM:-$here/gsp/rpc.om}
15BOOT_OM=${BOOT_OM:-$here/gsp/boot.om}
16DISPATCH_OM=${DISPATCH_OM:-$here/gsp/dispatch.om}
17OMC_PIN=$here/tools/omc.pin
18[ -f "$OMC_PIN" ] || OMC_PIN=/home/drakestapleton/work/OwnDriver/omega-mv-vfio/tools/omc.pin
19OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$OMC_PIN" 2>/dev/null || echo "bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6")
20run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; }
21
22got=$(sha256sum "$OMC" 2>/dev/null | cut -d' ' -f1)
23if [ "$got" != "$OMC_SHA" ]; then
24 echo "dispatch_diff: FAIL omc sha256 $got, pinned $OMC_SHA"; exit 2
25fi
26
27# Hard device-safety check: neither dispatch nor test harness may reference device paths or IOCTLs
28if 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
30fi
31
32t=$(mktemp -d /tmp/dispatch_diff.XXXXXX) || exit 2
33trap 'rm -rf "$t"' EXIT
34
35k=$AIENUX/native/kernel
36if ! 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
38fi
39
40REPLAY_OM=""
41if [ -f "$here/gsp/replay.om" ]; then
42 REPLAY_OM="$here/gsp/replay.om"
43fi
44
45if ! 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
47fi
48chmod +x "$t/om"
49
50fail=0
51cases=$here/tests/dispatch_cases.txt
52
53run "$t/ref" < "$cases" > "$t/c.cases"; echo "exit $?" >> "$t/c.cases"
54run "$t/om" < "$cases" > "$t/o.cases"; echo "exit $?" >> "$t/o.cases"
55
56if ! 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
58fi
59
60want=$(grep -Evc '^(#|[[:space:]]*$)' "$cases")
61n=$(grep -c '^== ' "$t/o.cases")
62if [ "$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
64fi
65
66# Verification of negative controls and behavioral constraints:
67# 1. Zero writes on malformed late op (proves full prevalidation prevented any partial effects)
68late_unk=$(grep '^== late-unkop ' "$t/o.cases")
69case "$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 ;;
72esac
73
74late_badstore=$(grep '^== late-badstore ' "$t/o.cases")
75case "$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 ;;
78esac
79
80# 2. Stale token / generation returns -10 without entering quarantine (state remains 11, dead=0)
81stale_gen=$(grep '^== stale-gen ' "$t/o.cases")
82case "$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 ;;
85esac
86
87stale_tok=$(grep '^== stale-tok ' "$t/o.cases")
88case "$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 ;;
91esac
92
93# 3. Poll timeout enters quarantine
94poll_fail=$(grep '^== poll-fail ' "$t/o.cases")
95case "$poll_fail" in
96 *"rc=-5"*"state=12"*"dead=1"*) ;;
97 *) echo "dispatch_diff: FAIL poll-fail quarantine control: $poll_fail"; fail=1 ;;
98esac
99
100# 4. Core matrix: all 4 core opcodes refuse without callback or without permission
101for 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
112done
113# 5. Non-sim mode: allpermissions+sqcore cannot activate core in non-sim mode (refuses before effect)
114core_nonsim=$(grep '^== core-nonsim ' "$t/o.cases")
115case "$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 ;;
118esac
119
120# No typed MMIO span: reject even register-only hardware sequences before the first write.
121late_reg=$(grep '^== late-invalidreg ' "$t/o.cases")
122case "$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 ;;
125esac
126
127if [ "$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
131else
132 exit 1
133fi