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

168 lines · 9390 bytes Raw Blame History
1#!/bin/sh
2# sysinfo_diff.sh: builds the .om GspSystemInfo encoder (gsp/sysinfo.om + tests/sysinfo_cli.om) and the C reference
3# (aienux PR #441 native/kernel/tools/ck_gsp_sysinfo_encode.c, compiled fresh into a temp dir as a test-only referee)
4# and requires, for every case text, byte-identical stdout, the same exit code and the same 936 output bytes.
5# Also: `fields` output identical; every field set by index (byidx) encodes like the C tool encodes the same values
6# as text; the .om-only API refusals match fixed expected lines. Host only: no device is opened.
7# Env: AIENUX (aienux checkout), OMC (pinned omc), SYSINFO_OM (library file to test; mutants use this).
8set -u
9here=$(cd "$(dirname "$0")/.." && pwd)
10AIENUX=${AIENUX:-/home/drakestapleton/work/OwnDriver/aienux}
11OMC=${OMC:-$here/build/omc}
12SYSINFO_OM=${SYSINFO_OM:-$here/gsp/sysinfo.om}
13OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$here/tools/omc.pin")
14run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; }
15
16got=$(sha256sum "$OMC" | cut -d' ' -f1)
17if [ "$got" != "$OMC_SHA" ]; then
18 echo "sysinfo_diff: FAIL omc sha256 $got, pinned $OMC_SHA"; exit 2
19fi
20if grep -n 'gspmode [0-9]* [1-9]\|gspbar\|vfio\|mapnew\|/dev/\|/sys/' "$here/tests/sysinfo_cli.om" "$SYSINFO_OM"; then
21 echo "sysinfo_diff: FAIL encoder or test driver names a device"; exit 2
22fi
23
24t=$(mktemp -d /tmp/sysinfo_diff.XXXXXX) || exit 2
25trap 'rm -rf "$t"' EXIT
26k=$AIENUX/native/kernel
27if ! run cc -std=c11 -O1 -Wall -Werror -o "$t/ck" "$k/tools/ck_gsp_sysinfo_encode.c"; then
28 echo "sysinfo_diff: FAIL C reference build"; exit 2
29fi
30if ! cat "$SYSINFO_OM" "$here/tests/sysinfo_cli.om" | run "$OMC" > "$t/om"; then
31 echo "sysinfo_diff: FAIL omc build"; exit 3
32fi
33chmod +x "$t/om"
34
35# ---- case texts (the C tool's selftest texts first, then the parser's edge cases) ----
36c=$t/cases
37mkdir "$c"
38rep() { printf "%$2s" '' | tr ' ' "$1"; }
39printf 'gpuPhysAddr 0x24000000\nPCIDeviceID 0x2e1210de # GB10\n\nFHBBusInfo.deviceID 0x22d1\nhostPageSize 4096\nbWindowChannelAlwaysMapped 1\n' > "$c/01valid"
40printf 'gpuPhysAdr 1\n' > "$c/02unknown"
41printf 'Chipset 1\nChipset 2\n' > "$c/03repeat"
42printf 'oorArch 256\n' > "$c/04fit1"
43printf 'FHBBusInfo.deviceID 0x10000\n' > "$c/05fit2"
44printf 'PCIRevisionID 0x100000000\n' > "$c/06fit4"
45printf 'maxUserVa 0x10000000000000000\n' > "$c/07ovf16"
46printf 'bIsPrimary -1\n' > "$c/08minus"
47printf 'bIsPrimary 1x\n' > "$c/09trail"
48printf 'bIsPrimary\n' > "$c/10want1"
49printf 'bIsPrimary 1 2\n' > "$c/11want3"
50printf 'acpiMethodData.dodMethodData 1\n' > "$c/12unkpart"
51printf 'acpiMethodData.dodMethodData.status 0xffff\nacpiMethodData.jtMethodData.status 0x56\nacpiMethodData.capsMethodData.status 0x56\n' > "$c/13acpi"
52printf 'Chipset 0777\nbIsPrimary 00\noorArch 0377\nconsoleMemSize 01777777777777777777777\n' > "$c/14octal"
53printf 'maxUserVa 02000000000000000000000\n' > "$c/15octovf"
54printf 'Chipset 08\n' > "$c/16octbad"
55printf 'Chipset +0x10\nhypervisorType +7\nbIsPassthru +0\n' > "$c/17plus"
56printf 'Chipset +-1\n' > "$c/18plusminus"
57printf 'Chipset +\n' > "$c/19plusonly"
58printf 'Chipset -0\n' > "$c/20minuszero"
59printf '\tChipset\t0x10\r\n oorArch 3 \r\n\013\014\n \t \n' > "$c/21ws"
60{ printf 'Chipset 1'; rep ' ' 502; printf '\n'; } > "$c/22len511"
61{ printf 'Chipset 1'; rep ' ' 503; printf '\n'; } > "$c/23len512"
62{ printf 'oorArch 1\n#'; rep x 600; printf '\n'; } > "$c/24longcomment"
63{ rep a 200; printf ' 1\n'; } > "$c/25longname3"
64{ rep a 130; printf '\n'; } > "$c/26longname2"
65{ printf 'Chipset '; rep 1 130; printf '\n'; } > "$c/27longval"
66{ printf 'Chipset 0x'; rep 0 124; printf '1\n'; } > "$c/28zeros127"
67{ printf 'Chipset 0x'; rep 0 125; printf '1\n'; } > "$c/29zeros128"
68printf '# full comment\nChipset 5 # trailing\n#\noorArch 2#x\n # indented\n' > "$c/30comments"
69printf 'Chipset 5\noorArch 3' > "$c/31noeol"
70printf 'Chipset 5\n\000oorArch 999\n' > "$c/32nul"
71: > "$c/33empty"
72printf 'maxUserVa 0xffffffffffffffff\nconsoleMemSize 18446744073709551615\n' > "$c/34max64"
73printf 'maxUserVa 18446744073709551616\n' > "$c/35dec2p64"
74{ printf 'oorArch 0x'; rep 0 50; printf '100\n'; } > "$c/36trunc40"
75printf 'Chipset 0x\n' > "$c/37zerox"
76printf 'Chipset 0xg\n' > "$c/38zeroxg"
77printf 'Chipset 0X1F\nPCIDeviceID 0xABCDEF\nPCISubDeviceID 0xAbCd\n' > "$c/39hexcase"
78printf 'FHBBusInfo.deviceID 0xffff\nPCIRevisionID 0xffffffff\noorArch 255\nvirtualConfigBits 65535\n' > "$c/40fitedge"
79printf 'virtualConfigBits 65536\n' > "$c/41fit2dec"
80printf 'Chipset \n' > "$c/42nameonly"
81printf 'Chipset 1\noorArch 1\n\n# c\nChipset 2\n' > "$c/43replate"
82printf 'gpuPhysAddrX 1\n' > "$c/44longer"
83printf 'gpuPhysAdd 1\n' > "$c/45prefix"
84printf 'gpuphysaddr 1\n' > "$c/46case"
85{ i=0; while [ $i -lt 3000 ]; do printf '\n'; i=$((i + 1)); done; printf 'bogus 1\n'; } > "$c/47line3001"
86printf 'Chipset 0x1 0x2\n' > "$c/48want3b"
87printf 'gpuPhysAddr 0x24000000\ngpuPhysInstAddr 0x24700000\nnvDomainBusDeviceFunc 0x0000000f00000100\nPCIDeviceID 0x2e1210de\nPCISubDeviceID 0x000010de\nPCIRevisionID 0xa1\nmaxUserVa 0x1000000000000\nhostPageSize 4096\npcieConfigReg.linkCap 0x00457901\noorArch 3\nChipset 0x106d\nFHBBusInfo.deviceID 0x22d1\nFHBBusInfo.vendorID 0x10de\nchipsetIDInfo.deviceID 0x22d1\nchipsetIDInfo.vendorID 0x10de\nclPdbProperties 0x1088020c1\nbFlrSupported 1\nb64bBar0Supported 1\npciConfigMirrorBase 0x92000\npciConfigMirrorSize 0x1000\npcieAtomicsOpMask 0x7\nhypervisorType 4\nacpiMethodData.bValid 1\nacpiMethodData.dodMethodData.status 0xffff\nacpiMethodData.dodMethodData.acpiIdListLen 64\nacpiMethodData.jtMethodData.status 0x56\nacpiMethodData.capsMethodData.status 0x56\nupstreamAddressValid 1\nbWindowChannelAlwaysMapped 1\nbIsUnixHdmiFrlComplianceEnabled 1\n' > "$c/49window1"
88printf 'gspVFInfo.b64bitBar2 1\ngspVFInfo.FirstVFBar2Address 0x0102030405060708\nsysTimerOffsetNs 0x8000000000000000\nbS0ixSupport 0x0\n' > "$c/50tail"
89
90# one run: stdout, then the exit code, then the output bytes (or "no output file")
91one() { # tool infile outfile -> stdout of the record
92 rm -f "$t/out.bin"
93 run "$1" encode "$2" "$3" > "$t/r.txt" 2> /dev/null
94 echo "rc=$?" >> "$t/r.txt"
95 cat "$t/r.txt"
96 if [ -f "$t/out.bin" ]; then od -An -tx1 -v "$t/out.bin"; else echo "no output file"; fi
97}
98fail=0; n=0
99for f in "$c"/*; do
100 n=$((n + 1))
101 one "$t/ck" "$f" "$t/out.bin" > "$t/c.rec"
102 one "$t/om" "$f" "$t/out.bin" > "$t/o.rec"
103 if ! cmp -s "$t/c.rec" "$t/o.rec"; then
104 echo "sysinfo_diff: case $(basename "$f") differs:"; diff "$t/c.rec" "$t/o.rec" | head -8; fail=1
105 fi
106done
107# missing input, unwritable output (negative controls on the file paths)
108for args in "$t/no-such-file $t/out.bin" "$c/01valid $t/no-dir/out.bin"; do
109 n=$((n + 1))
110 # shellcheck disable=SC2086
111 { run "$t/ck" encode $args; echo "rc=$?"; } > "$t/c.rec" 2>&1
112 # shellcheck disable=SC2086
113 { run "$t/om" encode $args; echo "rc=$?"; } > "$t/o.rec" 2>&1
114 if ! cmp -s "$t/c.rec" "$t/o.rec"; then
115 echo "sysinfo_diff: path case '$args' differs:"; diff "$t/c.rec" "$t/o.rec"; fail=1
116 fi
117done
118# usage: stdout empty, exit 1 on both
119for args in "" "fields x" "encode a" "selftestx" "encode a b c"; do
120 n=$((n + 1))
121 # shellcheck disable=SC2086
122 { run "$t/ck" $args; echo "rc=$?"; } > "$t/c.rec" 2> /dev/null
123 # shellcheck disable=SC2086
124 { run "$t/om" $args; echo "rc=$?"; } > "$t/o.rec" 2> /dev/null
125 if ! cmp -s "$t/c.rec" "$t/o.rec"; then
126 echo "sysinfo_diff: usage case '$args' differs:"; diff "$t/c.rec" "$t/o.rec"; fail=1
127 fi
128done
129# the field table
130run "$t/ck" fields > "$t/c.f"; run "$t/om" fields > "$t/o.f"
131if ! cmp -s "$t/c.f" "$t/o.f" || [ "$(wc -l < "$t/c.f")" -ne 72 ]; then
132 echo "sysinfo_diff: fields differ"; diff "$t/c.f" "$t/o.f" | head -8; fail=1
133fi
134# every field by index: the .om bytes must equal the C tool's bytes for the same values as text
135if ! run "$t/om" byidx "$t/idx.bin" > "$t/idx.txt" || [ "$(wc -l < "$t/idx.txt")" -ne 72 ]; then
136 echo "sysinfo_diff: byidx run failed"; cat "$t/idx.txt"; fail=1
137elif ! run "$t/ck" encode "$t/idx.txt" "$t/idxc.bin" > "$t/idxc.log" || ! cmp -s "$t/idx.bin" "$t/idxc.bin"; then
138 echo "sysinfo_diff: byidx bytes differ from the C encoding of the same values"; cat "$t/idxc.log"; fail=1
139fi
140# negative control: a corrupted copy of the window-1 text is refused with nothing written
141sed 's/^oorArch 3$/oorArch 0x103/' "$c/49window1" > "$t/bad.txt"
142rm -f "$t/out.bin"
143run "$t/om" encode "$t/bad.txt" "$t/out.bin" > "$t/bad.log"
144brc=$?
145if [ "$brc" -ne 2 ] || [ -f "$t/out.bin" ] || ! grep -qx 'REFUSED: line 10: 0x103 does not fit oorArch (1 bytes)' "$t/bad.log"; then
146 echo "sysinfo_diff: negative control not refused (rc $brc)"; cat "$t/bad.log"; fail=1
147fi
148# .om-only API refusals
149run "$t/om" api > "$t/api.txt"
150cat > "$t/api.want" <<'EOF'
151api nit rc=-9 why=sireset not called
152api idx rc=-1 why=field index out of range
153api fit rc=-3 why=0x100 does not fit oorArch (1 bytes)
154api ok rc=0 why=
155api rep rc=-2 why=field oorArch repeated
156api name rc=0 why=
157api unk rc=-4 why=unknown field chipset
158api big rc=-8 why=text over 65536 bytes
159api ok rc=0 why=
160api bytes 2 0xff 0x6d 0x10 0 0
161EOF
162if ! cmp -s "$t/api.want" "$t/api.txt"; then
163 echo "sysinfo_diff: api refusals differ"; diff "$t/api.want" "$t/api.txt"; fail=1
164fi
165if [ "$fail" -ne 0 ]; then
166 echo "sysinfo_diff: FAIL"; exit 1
167fi
168echo "sysinfo_diff: PASS ($n encode/usage cases identical stdout+exit+bytes, 72 fields, 72 by-index sets, negative control refused, 10 API lines; .om vs C reference)"