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

95 lines · 5149 bytes Raw Blame History
1#!/bin/sh
2# seq_diff.sh: builds the .om GSP CPU sequencer (gsp/seq.om, run by tests/seq_trace.om on gsp/sim.om in mode 0) and
3# the C reference (aienux PR #441 native/kernel/gpu/gsp_seq.c + gsp_sim.c, driven by tests/seq_ref.c, compiled fresh
4# into a temp dir as a test-only referee), runs every case of tests/seq_cases.txt through both and requires
5# byte-identical traces (rc, why, delays, core calls, save[8], register log, violations) and the same exit code.
6# Also: malformed case input stops both the same way; a corrupted buffer is refused; the .om-only refusals
7# (nwords cap, poll budget cap) match fixed expected lines. Host only: no device is opened.
8# Env: AIENUX (aienux checkout), OMC (pinned omc), SEQ_OM (library file to test; mutants use this).
9set -u
10here=$(cd "$(dirname "$0")/.." && pwd)
11AIENUX=${AIENUX:-/home/drakestapleton/work/OwnDriver/aienux}
12OMC=${OMC:-$here/build/omc}
13SEQ_OM=${SEQ_OM:-$here/gsp/seq.om}
14OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$here/tools/omc.pin")
15run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; }
16
17got=$(sha256sum "$OMC" | cut -d' ' -f1)
18if [ "$got" != "$OMC_SHA" ]; then
19 echo "seq_diff: FAIL omc sha256 $got, pinned $OMC_SHA"; exit 2
20fi
21if grep -n 'put gspmode [0-9]* [1-9]\|gspbar\|vfio\|mapnew\|/dev/\|/sys/' "$here/tests/seq_trace.om" "$SEQ_OM"; then
22 echo "seq_diff: FAIL sequencer or test driver names a device"; exit 2
23fi
24
25t=$(mktemp -d /tmp/seq_diff.XXXXXX) || exit 2
26trap 'rm -rf "$t"' EXIT
27k=$AIENUX/native/kernel
28if ! run cc -std=c11 -O1 -Wall -Werror -I"$k/gpu" -o "$t/ref" "$here/tests/seq_ref.c" "$k/gpu/gsp_seq.c" "$k/gpu/gsp_sim.c"; then
29 echo "seq_diff: FAIL C reference build"; exit 2
30fi
31if ! cat "$here/gsp/mmio.om" "$here/gsp/sim.om" "$SEQ_OM" "$here/tests/seq_trace.om" | run "$OMC" > "$t/om"; then
32 echo "seq_diff: FAIL omc build"; exit 3
33fi
34chmod +x "$t/om"
35
36fail=0
37# both tools on one input: stdout then the exit code
38both() { # infile tag
39 run "$t/ref" < "$1" > "$t/c.$2"; echo "exit $?" >> "$t/c.$2"
40 run "$t/om" < "$1" > "$t/o.$2"; echo "exit $?" >> "$t/o.$2"
41 if ! cmp -s "$t/c.$2" "$t/o.$2"; then
42 echo "seq_diff: $2 differs (C left, .om right)"; diff "$t/c.$2" "$t/o.$2" | head -12; fail=1
43 fi
44}
45cases=$here/tests/seq_cases.txt
46both "$cases" cases
47want=$(grep -vc '^#' "$cases")
48n=$(grep -c '^== ' "$t/o.cases")
49if [ "$n" -ne "$want" ] || [ "$(tail -n 1 "$t/o.cases")" != "exit 0" ]; then
50 echo "seq_diff: ran $n of $want cases"; tail -n 1 "$t/o.cases"; fail=1
51fi
52# every refusal the C has must be among the cases
53for w in 'empty buffer' 'cmdIndex not inside the buffer' 'unknown opcode' 'opcode overruns cmdIndex' 'poll timed out' \
54 'save index out of range' 'core opcode with no core callback' 'core opcode failed'; do
55 if ! grep -q " rc=-1 why=$w " "$t/o.cases"; then echo "seq_diff: no case refuses with '$w'"; fail=1; fi
56done
57# malformed case input: both stop with exit 2 after the same output
58printf 'write 0 4 0 0 4 3 3 0 8653504 2748\nbad 0 4 x\n' > "$t/bad1"
59printf 'write 0 4 0 0 4 3 3 0 8653504 2748\nshort 0 4 0 0 4 3 3 0 8653504\n' > "$t/bad2"
60printf 'big 0 4 0 0 4 3 3 0 8653504 4294967296\n' > "$t/bad3"
61for b in bad1 bad2 bad3; do
62 both "$t/$b" "$b"
63 if [ "$(tail -n 1 "$t/o.$b")" != "exit 2" ]; then echo "seq_diff: $b not refused"; fail=1; fi
64done
65# negative control: the modify case with its opcode corrupted (1 -> 9) is refused by both, nothing written after it
66grep '^modify ' "$cases" | sed 's/ 255 1 8653504 / 255 9 8653504 /' > "$t/corrupt"
67both "$t/corrupt" corrupt
68if ! grep -qx '== modify rc=-1 why=unknown opcode delays=0/0 core=0 ops= save=0,0,0,0,0,0,0,0, nlog=1 violations=0' "$t/o.corrupt"; then
69 echo "seq_diff: negative control not refused"; cat "$t/o.corrupt"; fail=1
70fi
71# the comparison itself can go red: a changed modify mask (10 -> 255) on the C side must not match the .om trace
72grep '^modify ' "$cases" > "$t/m.ok"
73sed 's/ 8653504 10 5$/ 8653504 255 5/' "$t/m.ok" > "$t/m.bad"
74run "$t/ref" < "$t/m.bad" > "$t/c.mbad"
75run "$t/om" < "$t/m.ok" > "$t/o.mok"
76if ! grep -q '^modify .* 255 5$' "$t/m.bad" || cmp -s "$t/c.mbad" "$t/o.mok"; then echo "seq_diff: changed mask not detected"; fail=1; fi
77# .om-only refusals (the C has no such limits); cmdIndex is still checked first, as in the C
78cat > "$t/only" <<'EOF'
79cap 0 4 0 0 16385 0 0
80capidx 0 4 0 0 16385 16385 0
81bigbud 0 999999 0 0 2 1 1 3
82EOF
83run "$t/om" < "$t/only" > "$t/only.got"
84cat > "$t/only.want" <<'EOF'
85== cap rc=-1 why=nwords over 16384 delays=0/0 core=0 ops= save=0,0,0,0,0,0,0,0, nlog=0 violations=0
86== capidx rc=-1 why=cmdIndex not inside the buffer delays=0/0 core=0 ops= save=0,0,0,0,0,0,0,0, nlog=0 violations=0
87== bigbud rc=-1 why=poll budget over 999998 delays=0/0 core=0 ops= save=0,0,0,0,0,0,0,0, nlog=0 violations=0
88EOF
89if ! cmp -s "$t/only.want" "$t/only.got"; then
90 echo "seq_diff: .om-only refusals differ"; diff "$t/only.want" "$t/only.got"; fail=1
91fi
92if [ "$fail" -ne 0 ]; then
93 echo "seq_diff: FAIL"; exit 1
94fi
95echo "seq_diff: PASS ($n cases identical trace+exit, 8 C refusals covered, 3 malformed inputs stop alike, negative control refused, changed mask detected, 3 .om-only refusals; .om vs C reference)"