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

63 lines · 3026 bytes Raw Blame History
1#!/bin/sh
2# params_diff.sh: builds the .om params dump (chan/params.om + tests/params_dump.om) and the C referee
3# tests/params_ref.c (TEST-ONLY, compiled fresh into a temp dir against the NVIDIA open-gpu-kernel-modules
4# 580.173.02 headers) and requires byte-identical stdout: every record's bytes, every record size
5# against NVIDIA's sizeof, the refused cases and the exported constants. Host only.
6# Env: OMC (pinned omc), PARAMS_OM (unit to test; mutants use it), OGKM_SRC (NVIDIA src/ tree),
7# PARAMS_REF (referee output already produced by this script, so a mutant run skips the rebuild).
8# Exit: 0 PASS, 1 outputs differ, 2 setup, 3 omc failure.
9set -u
10here=$(cd "$(dirname "$0")/.." && pwd)
11OMC=${OMC:-$here/build/omc}
12PARAMS_OM=${PARAMS_OM:-$here/chan/params.om}
13OGKM_SRC=${OGKM_SRC:-/home/drakestapleton/workspace/_ext/open-gpu-kernel-modules-580.173.02/src}
14PARAMS_REF=${PARAMS_REF:-}
15OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$here/tools/omc.pin")
16run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; }
17
18got=$(sha256sum "$OMC" | cut -d' ' -f1)
19if [ "$got" != "$OMC_SHA" ]; then
20 echo "params_diff: FAIL omc sha256 $got, pinned $OMC_SHA"; exit 2
21fi
22if grep -n 'vfio\|mapnew\|/dev/\|/sys/' "$PARAMS_OM" "$here/tests/params_dump.om"; then
23 echo "params_diff: FAIL params unit or dump names a device"; exit 2
24fi
25
26t=$(mktemp -d /tmp/params_diff.XXXXXX) || exit 2
27trap 'rm -rf "$t"' EXIT
28if [ -n "$PARAMS_REF" ]; then
29 [ -s "$PARAMS_REF" ] || { echo "params_diff: FAIL PARAMS_REF $PARAMS_REF missing or empty"; exit 2; }
30 cp "$PARAMS_REF" "$t/c.txt" || exit 2
31else
32 S=$OGKM_SRC
33 if ! run cc -std=c11 -O1 -Wall -Werror \
34 -I"$S/common/sdk/nvidia/inc" -I"$S/nvidia/arch/nvalloc/common/inc" -I"$S/common/uproc/os/common/include" \
35 -I"$S/nvidia/inc/kernel" -I"$S/nvidia/inc" -I"$S/nvidia/generated" -I"$S/common/shared/msgq/inc" \
36 -I"$S/nvidia/interface" -I"$S/common/inc" -o "$t/pref" "$here/tests/params_ref.c"; then
37 echo "params_diff: FAIL C referee build"; exit 2
38 fi
39 run "$t/pref" > "$t/c.txt" || { echo "params_diff: FAIL C referee run"; exit 2; }
40fi
41if ! cat "$PARAMS_OM" "$here/tests/params_dump.om" | run "$OMC" > "$t/pd"; then
42 echo "params_diff: FAIL omc build"; exit 3
43fi
44chmod +x "$t/pd"
45run "$t/pd" > "$t/om.txt"
46rc=$?
47if [ "$rc" -ne 0 ]; then
48 echo "params_diff: FAIL om dump exit $rc"; exit 1
49fi
50n=$(wc -l < "$t/c.txt")
51if [ "$n" -eq 0 ]; then
52 echo "params_diff: FAIL empty C output"; exit 2
53fi
54if ! cmp -s "$t/c.txt" "$t/om.txt"; then
55 echo "params_diff: FAIL outputs differ ($(diff "$t/c.txt" "$t/om.txt" | grep -c '^[<>]') differing lines; C $n lines, om $(wc -l < "$t/om.txt"))"
56 exit 1
57fi
58# negative control: the comparison must see a single corrupted byte (first record byte 01 -> 00)
59sed '2s/^01/00/' "$t/om.txt" > "$t/bad.txt"
60if cmp -s "$t/c.txt" "$t/bad.txt"; then
61 echo "params_diff: FAIL negative control: a corrupted byte was not detected"; exit 2
62fi
63echo "params_diff: PASS ($n lines identical, .om vs C referee; corrupted-byte control refused)"