Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-gpu-driver/blob/main/tests/sysinfo_diff.sh # omega-gpu-driver aien-dev/omega-gpu-driver Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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). 8 set -u 9 here=$(cd "$(dirname "$0")/.." && pwd) 10 AIENUX=${AIENUX:-/home/drakestapleton/work/OwnDriver/aienux} 11 OMC=${OMC:-$here/build/omc} 12 SYSINFO_OM=${SYSINFO_OM:-$here/gsp/sysinfo.om} 13 OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$here/tools/omc.pin") 14 run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; } 15 16 got=$(sha256sum "$OMC" | cut -d' ' -f1) 17 if [ "$got" != "$OMC_SHA" ]; then 18 echo "sysinfo_diff: FAIL omc sha256 $got, pinned $OMC_SHA"; exit 2 19 fi 20 if 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 22 fi 23 24 t=$(mktemp -d /tmp/sysinfo_diff.XXXXXX) || exit 2 25 trap 'rm -rf "$t"' EXIT 26 k=$AIENUX/native/kernel 27 if ! 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 29 fi 30 if ! cat "$SYSINFO_OM" "$here/tests/sysinfo_cli.om" | run "$OMC" > "$t/om"; then 31 echo "sysinfo_diff: FAIL omc build"; exit 3 32 fi 33 chmod +x "$t/om" 34 35 # ---- case texts (the C tool's selftest texts first, then the parser's edge cases) ---- 36 c=$t/cases 37 mkdir "$c" 38 rep() { printf "%$2s" '' | tr ' ' "$1"; } 39 printf 'gpuPhysAddr 0x24000000\nPCIDeviceID 0x2e1210de # GB10\n\nFHBBusInfo.deviceID 0x22d1\nhostPageSize 4096\nbWindowChannelAlwaysMapped 1\n' > "$c/01valid" 40 printf 'gpuPhysAdr 1\n' > "$c/02unknown" 41 printf 'Chipset 1\nChipset 2\n' > "$c/03repeat" 42 printf 'oorArch 256\n' > "$c/04fit1" 43 printf 'FHBBusInfo.deviceID 0x10000\n' > "$c/05fit2" 44 printf 'PCIRevisionID 0x100000000\n' > "$c/06fit4" 45 printf 'maxUserVa 0x10000000000000000\n' > "$c/07ovf16" 46 printf 'bIsPrimary -1\n' > "$c/08minus" 47 printf 'bIsPrimary 1x\n' > "$c/09trail" 48 printf 'bIsPrimary\n' > "$c/10want1" 49 printf 'bIsPrimary 1 2\n' > "$c/11want3" 50 printf 'acpiMethodData.dodMethodData 1\n' > "$c/12unkpart" 51 printf 'acpiMethodData.dodMethodData.status 0xffff\nacpiMethodData.jtMethodData.status 0x56\nacpiMethodData.capsMethodData.status 0x56\n' > "$c/13acpi" 52 printf 'Chipset 0777\nbIsPrimary 00\noorArch 0377\nconsoleMemSize `01777777777777777777777`\n' > "$c/14octal" 53 printf 'maxUserVa `02000000000000000000000`\n' > "$c/15octovf" 54 printf 'Chipset 08\n' > "$c/16octbad" 55 printf 'Chipset +0x10\nhypervisorType +7\nbIsPassthru +0\n' > "$c/17plus" 56 printf 'Chipset +-1\n' > "$c/18plusminus" 57 printf 'Chipset +\n' > "$c/19plusonly" 58 printf 'Chipset -0\n' > "$c/20minuszero" 59 printf '\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" 68 printf '# full comment\nChipset 5 # trailing\n#\noorArch 2#x\n # indented\n' > "$c/30comments" 69 printf 'Chipset 5\noorArch 3' > "$c/31noeol" 70 printf 'Chipset 5\n\000oorArch 999\n' > "$c/32nul" 71 : > "$c/33empty" 72 printf 'maxUserVa 0xffffffffffffffff\nconsoleMemSize `18446744073709551615`\n' > "$c/34max64" 73 printf 'maxUserVa `18446744073709551616`\n' > "$c/35dec2p64" 74 { printf 'oorArch 0x'; rep 0 50; printf '100\n'; } > "$c/36trunc40" 75 printf 'Chipset 0x\n' > "$c/37zerox" 76 printf 'Chipset 0xg\n' > "$c/38zeroxg" 77 printf 'Chipset 0X1F\nPCIDeviceID 0xABCDEF\nPCISubDeviceID 0xAbCd\n' > "$c/39hexcase" 78 printf 'FHBBusInfo.deviceID 0xffff\nPCIRevisionID 0xffffffff\noorArch 255\nvirtualConfigBits 65535\n' > "$c/40fitedge" 79 printf 'virtualConfigBits 65536\n' > "$c/41fit2dec" 80 printf 'Chipset \n' > "$c/42nameonly" 81 printf 'Chipset 1\noorArch 1\n\n# c\nChipset 2\n' > "$c/43replate" 82 printf 'gpuPhysAddrX 1\n' > "$c/44longer" 83 printf 'gpuPhysAdd 1\n' > "$c/45prefix" 84 printf '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" 86 printf 'Chipset 0x1 0x2\n' > "$c/48want3b" 87 printf '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" 88 printf '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") 91 one() { # 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 } 98 fail=0; n=0 99 for 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 106 done 107 # missing input, unwritable output (negative controls on the file paths) 108 for 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 117 done 118 # usage: stdout empty, exit 1 on both 119 for 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 128 done 129 # the field table 130 run "$t/ck" fields > "$t/c.f"; run "$t/om" fields > "$t/o.f" 131 if ! 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 133 fi 134 # every field by index: the .om bytes must equal the C tool's bytes for the same values as text 135 if ! 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 137 elif ! 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 139 fi 140 # negative control: a corrupted copy of the window-1 text is refused with nothing written 141 sed 's/^oorArch 3$/oorArch 0x103/' "$c/49window1" > "$t/bad.txt" 142 rm -f "$t/out.bin" 143 run "$t/om" encode "$t/bad.txt" "$t/out.bin" > "$t/bad.log" 144 brc=$? 145 if [ "$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 147 fi 148 # .om-only API refusals 149 run "$t/om" api > "$t/api.txt" 150 cat > "$t/api.want" <<'EOF' 151 api nit rc=-9 why=sireset not called 152 api idx rc=-1 why=field index out of range 153 api fit rc=-3 why=0x100 does not fit oorArch (1 bytes) 154 api ok rc=0 why= 155 api rep rc=-2 why=field oorArch repeated 156 api name rc=0 why= 157 api unk rc=-4 why=unknown field chipset 158 api big rc=-8 why=text over 65536 bytes 159 api ok rc=0 why= 160 api bytes 2 0xff 0x6d 0x10 0 0 161 EOF 162 if ! 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 164 fi 165 if [ "$fail" -ne 0 ]; then 166 echo "sysinfo_diff: FAIL"; exit 1 167 fi 168 echo "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)"