CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / tests / tools-om / doctor.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # doctor acceptance: cudapp-doctor (seeded Omega om/tools/fmt.om + om/tools/doctor.om) against its C oracle |
| 4 | # (-DCUDAPP_MIGRATION_PENDING_C_TOOLS_DOCTOR) on fake machines under CUDAPP_DOCTOR_ROOT: stdout, stderr and |
| 5 | # exit code byte for byte, a flipped-record negative control, the documented refusal of a build text |
| 6 | # holding %, and recompiled mutants of the composed unit. TOOLS_OM_COVERAGE=DIR also writes gcov branch |
| 7 | # data of the oracle. Run as a normal user (chmod 000 must deny access) under: |
| 8 | # bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 |
| 9 | set -eu |
| 10 | ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) |
| 11 | cd "$ROOT" |
| 12 | tmp=$(mktemp -d) |
| 13 | trap 'chmod -R u+rwx "$tmp" 2>/dev/null; rm -rf "$tmp"' EXIT |
| 14 | . tests/tools-om/lib.sh |
| 15 | tom_pin |
| 16 | [ "$(id -u)" != 0 ] || { echo "NOT_RUN: root ignores chmod 000; run as a normal user"; exit 3; } |
| 17 | SRC=tools/doctor/cudapp_doctor.c |
| 18 | OFF=-DCUDAPP_MIGRATION_PENDING_C_TOOLS_DOCTOR |
| 19 | ABI='-DCUDAPP_NVIDIA_OPEN_ABI="580.173.02"' |
| 20 | # src/omega_gpu_chip.c calls the HelloC2 #296 chip-admission unit (omega_chip_admit) and the chip enumeration unit. |
| 21 | CHIP="src/omega_gpu_chip.c src/cudapp_om_chip_admit.c src/cudapp_om_chip_enum.c" |
| 22 | |
| 23 | $CC $TOM_CFLAGS "$ABI" $OFF -o "$tmp/doc_c" $SRC $CHIP |
| 24 | $CC $TOM_CFLAGS "$ABI" -o "$tmp/doc_om" $SRC src/cudapp_om_doctor.c $CHIP |
| 25 | |
| 26 | # ---- fake machines (partition: docs in tests/tools-om/README.md) ---- |
| 27 | R=$tmp/m |
| 28 | OPEN='NVIDIA UNIX Open Kernel Module for aarch64 580.173.02 Release Build (test) Tue Jun 23 08:34:19 UTC 2026' |
| 29 | CLOSED='NVIDIA UNIX aarch64 Kernel Module 580.173.02 Release Build (test) Tue Jun 23 08:34:19 UTC 2026' |
| 30 | ver() { mkdir -p "$1/proc/driver/nvidia"; printf 'NVRM version: %s\nGCC version: gcc version 13.3.0\n' "$2" > "$1/proc/driver/nvidia/version"; } |
| 31 | nodes() { d=$1; shift; mkdir -p "$d/dev"; for n in "$@"; do : > "$d/dev/$n"; chmod 666 "$d/dev/$n"; done; } |
| 32 | pci() { # ROOT NAME VENDOR DEVICE CLASS |
| 33 | g="$1/sys/bus/pci/devices/$2"; mkdir -p "$g" |
| 34 | echo "$3" > "$g/vendor"; echo "$4" > "$g/device"; echo "$5" > "$g/class" |
| 35 | } |
| 36 | mem() { mkdir -p "$1/proc"; printf 'MemTotal: %s kB\nMemFree: 1 kB\nMemAvailable: %s kB\n' "$2" "$3" > "$1/proc/meminfo"; } |
| 37 | nvcc() { mkdir -p "$1/$(dirname "$2")"; : > "$1/$2"; chmod "$3" "$1/$2"; } |
| 38 | std() { # ROOT: ready GB10 machine |
| 39 | ver "$1" "$OPEN"; nodes "$1" nvidiactl nvidia0 nvidia-uvm |
| 40 | pci "$1" 000f:01:00.0 0x10de 0x2e12 0x030000; pci "$1" 0000:00:00.0 0x8086 0x1234 0x060000 |
| 41 | mem "$1" 127535484 42000000 |
| 42 | } |
| 43 | CASES="" |
| 44 | case_() { CASES="$CASES $1"; mkdir -p "$R/$1"; } |
| 45 | |
| 46 | case_ empty |
| 47 | case_ ready; std "$R/ready"; nvcc "$R/ready" usr/local/cuda/bin/nvcc 755 |
| 48 | case_ closed; std "$R/closed"; ver "$R/closed" "$CLOSED" |
| 49 | case_ wrong; std "$R/wrong"; ver "$R/wrong" 'NVIDIA UNIX Open Kernel Module for aarch64 575.51.03 Release Build' |
| 50 | case_ wrong_closed; std "$R/wrong_closed"; ver "$R/wrong_closed" 'NVIDIA UNIX Kernel Module 999.1 x' |
| 51 | case_ prefix_ver; std "$R/prefix_ver"; ver "$R/prefix_ver" 'v 9.9.9 Module 580.173.02 Open Kernel Module' |
| 52 | case_ no_module_word; std "$R/no_module_word"; ver "$R/no_module_word" 'build 580.173.02 open' |
| 53 | case_ short_runs; std "$R/short_runs"; ver "$R/short_runs" 'Module 12 1. .5 2.. x' |
| 54 | case_ dotless; std "$R/dotless"; ver "$R/dotless" 'Module 12345 then 580.173.02' |
| 55 | case_ run64; std "$R/run64"; ver "$R/run64" "Module $(printf '1.%.0s' $(seq 32)) 580.173.02" |
| 56 | case_ run63; std "$R/run63"; ver "$R/run63" "Module $(printf '1.%.0s' $(seq 31))1 Open Kernel Module" |
| 57 | case_ unparsable; std "$R/unparsable"; ver "$R/unparsable" 'garbage without any version at all' |
| 58 | case_ long_line; std "$R/long_line"; ver "$R/long_line" "Module $(printf 'x%.0s' $(seq 1100)) 580.173.02" |
| 59 | case_ exact120; std "$R/exact120"; ver "$R/exact120" "$(printf 'y%.0s' $(seq 105))" |
| 60 | case_ empty_version; std "$R/empty_version"; : > "$R/empty_version/proc/driver/nvidia/version" |
| 61 | case_ open_split; std "$R/open_split"; ver "$R/open_split" 'Open Kernel Modul 580.173.02 Open Kernel' |
| 62 | case_ trail_alpha; std "$R/trail_alpha"; ver "$R/trail_alpha" 'Module 1a 580.173.02a Open Kernel Module' |
| 63 | case_ node_missing; std "$R/node_missing"; rm "$R/node_missing/dev/nvidia0" |
| 64 | case_ node_perm; std "$R/node_perm"; chmod 000 "$R/node_perm/dev/nvidiactl"; chmod 444 "$R/node_perm/dev/nvidia-uvm" |
| 65 | case_ node_all; std "$R/node_all"; rm "$R/node_all/dev/nvidiactl" "$R/node_all/dev/nvidia0" "$R/node_all/dev/nvidia-uvm" |
| 66 | case_ no_pci_dir; std "$R/no_pci_dir"; rm -rf "$R/no_pci_dir/sys" |
| 67 | case_ no_gpu; std "$R/no_gpu"; rm -rf "$R/no_gpu/sys/bus/pci/devices/000f:01:00.0" |
| 68 | case_ audio_only; std "$R/audio_only"; rm -rf "$R/audio_only/sys/bus/pci/devices/000f:01:00.0"; pci "$R/audio_only" 000f:01:00.1 0x10de 0x22e8 0x040300 |
| 69 | case_ unknown; std "$R/unknown"; rm -rf "$R/unknown/sys/bus/pci/devices/000f:01:00.0"; pci "$R/unknown" 0001:01:00.0 0x10de 0x2684 0x030000 |
| 70 | case_ two_gpus; std "$R/two_gpus"; pci "$R/two_gpus" 0002:01:00.0 0x10de 0x2684 0x030200 |
| 71 | case_ nl_bdf; std "$R/nl_bdf"; pci "$R/nl_bdf" "$(printf '00:01\nX')" 0x10de 0x1db4 0x030000 |
| 72 | case_ long_bdf; std "$R/long_bdf"; pci "$R/long_bdf" "$(printf 'b%.0s' $(seq 70))" 0x10de 0x2e12 0x030000 |
| 73 | case_ many; std "$R/many"; for i in $(seq 10 26); do pci "$R/many" "00$i:01:00.0" 0x10de 0x20b0 0x030000; done |
| 74 | case_ pct_bdf; std "$R/pct_bdf"; pci "$R/pct_bdf" '00%s:01%d.0' 0x10de 0x2e12 0x030000 |
| 75 | case_ no_meminfo; std "$R/no_meminfo"; rm "$R/no_meminfo/proc/meminfo" |
| 76 | case_ mem_nounified; std "$R/mem_nounified"; rm -rf "$R/mem_nounified/sys/bus/pci/devices/000f:01:00.0"; pci "$R/mem_nounified" 0001:01:00.0 0x10de 0x2684 0x030000 |
| 77 | case_ mem_ties; std "$R/mem_ties"; mem "$R/mem_ties" 262144 786432 |
| 78 | case_ mem_zero; std "$R/mem_zero"; printf 'MemFree: 5 kB\n' > "$R/mem_zero/proc/meminfo" |
| 79 | case_ mem_huge; std "$R/mem_huge"; mem "$R/mem_huge" 18446744073709551615 9007199254740993 |
| 80 | case_ mem_odd; std "$R/mem_odd"; mem "$R/mem_odd" 1153433 104857 |
| 81 | case_ nvcc_usr; std "$R/nvcc_usr"; nvcc "$R/nvcc_usr" usr/local/cuda/bin/nvcc 644; nvcc "$R/nvcc_usr" usr/bin/nvcc 755 |
| 82 | case_ nvcc_noexec; std "$R/nvcc_noexec"; nvcc "$R/nvcc_noexec" usr/bin/nvcc 644 |
| 83 | case_ one_fail; std "$R/one_fail"; rm "$R/one_fail/dev/nvidia-uvm" |
| 84 | |
| 85 | LONG=$tmp/$(printf 'L%.0s' $(seq 4300)) |
| 86 | run_all() { # BIN PREFIX |
| 87 | for c in $CASES; do |
| 88 | rc=0; CUDAPP_DOCTOR_ROOT="$R/$c" "$1" > "$2.$c.out" 2> "$2.$c.err" || rc=$?; echo "$rc" > "$2.$c.rc" |
| 89 | done |
| 90 | rc=0; CUDAPP_DOCTOR_ROOT="$LONG" "$1" > "$2.long.out" 2> "$2.long.err" || rc=$?; echo "$rc" > "$2.long.rc" |
| 91 | # The real machine (CUDAPP_DOCTOR_ROOT unset): its MemAvailable changes between two runs, so the |
| 92 | # memory line is dropped before the comparison. |
| 93 | { rc=0; env -u CUDAPP_DOCTOR_ROOT "$1" 2> "$2.real.err" || rc=$?; echo "$rc" > "$2.real.rc"; } \ |
| 94 | | { grep -v '^ [a-z]* *memory: ' || true; } > "$2.real.out" |
| 95 | } |
| 96 | ALL="$CASES long real" |
| 97 | same() { # PREFIX_A PREFIX_B CASE |
| 98 | cmp -s "$1.$3.out" "$2.$3.out" && cmp -s "$1.$3.err" "$2.$3.err" && cmp -s "$1.$3.rc" "$2.$3.rc" |
| 99 | } |
| 100 | run_all "$tmp/doc_c" "$tmp/c" |
| 101 | run_all "$tmp/doc_om" "$tmp/om" |
| 102 | machines=0 |
| 103 | for c in $ALL; do |
| 104 | same "$tmp/c" "$tmp/om" "$c" || { echo "FAIL differential $c"; diff "$tmp/c.$c.out" "$tmp/om.$c.out" | head -20; exit 1; } |
| 105 | machines=$((machines + 1)) |
| 106 | done |
| 107 | rcs=$(for c in $ALL; do cat "$tmp/c.$c.rc"; done | sort | uniq -c | tr -s ' \n' ' ') |
| 108 | echo "differential: $machines fake machines identical (stdout, stderr, exit; exit histogram:$rcs)" |
| 109 | tom_flip "$tmp/c.mem_odd.out" "$tmp/om.mem_odd.out" |
| 110 | |
| 111 | # Documented deviation: the C printed the ABI and compiler texts as part of a printf format; the unit |
| 112 | # refuses a % or newline in them with exit 2 instead of printing what printf would make of it. |
| 113 | $CC $TOM_CFLAGS '-DCUDAPP_NVIDIA_OPEN_ABI="580%d"' -o "$tmp/doc_pct" $SRC src/cudapp_om_doctor.c $CHIP |
| 114 | rc=0; CUDAPP_DOCTOR_ROOT="$R/ready" "$tmp/doc_pct" > "$tmp/pct.out" 2> "$tmp/pct.err" || rc=$? |
| 115 | [ "$rc" = 2 ] && [ ! -s "$tmp/pct.out" ] && grep -qF 'omega_doctor refused (status 0, code 1)' "$tmp/pct.err" \ |
| 116 | || { echo "FAIL build-text refusal: exit $rc"; exit 1; } |
| 117 | echo "build-text refusal: ABI holding % exits 2 with no stdout" |
| 118 | |
| 119 | # ---- mutants of the composed unit (fmt.om then doctor.om, as om/units.sh composes it) ---- |
| 120 | UNIT=$tmp/doctor_unit.om |
| 121 | { cat om/tools/fmt.om; echo; cat om/tools/doctor.om; } > "$UNIT" |
| 122 | killed=0 |
| 123 | mut() { # NAME SITE REPLACEMENT |
| 124 | tom_mutant "$1" "$UNIT" "$2" "$3" |
| 125 | $CC $TOM_CFLAGS "$ABI" -o "$tmp/$1.bin" $SRC "$tmp/$1.c" $CHIP |
| 126 | run_all "$tmp/$1.bin" "$tmp/$1" |
| 127 | for c in $ALL; do |
| 128 | if ! same "$tmp/c" "$tmp/$1" "$c"; then echo "mutant $1: killed ($c)"; killed=$((killed + 1)); return 0; fi |
| 129 | done |
| 130 | echo "FAIL mutant $1 survived"; exit 1 |
| 131 | } |
| 132 | mut trunc120 'k = ulong 120' 'k = ulong 119' |
| 133 | mut runmin 'if gt k 2' 'if gt k 3' |
| 134 | mut runmax 'if lt k 64' 'if lt k 63' |
| 135 | mut unified 'put st 1 1' 'put st 1 0' |
| 136 | mut clamp16 'n = ulong 16' 'n = ulong 15' |
| 137 | mut prefix 'fi = add add at 6 get f add g 1' 'fi = add add at 5 get f add g 1' |
| 138 | mut gib_prec 'n = fm_f div f64 v DCMB 1 t' 'n = fm_f div f64 v DCMB 2 t' |
| 139 | mut plural 'if ne nf 1' 'if gt nf 2' |
| 140 | mut closed 'if eq dc_open b at add at n 0' 'if ne dc_open b at add at n 0' |
| 141 | mut moreskip 's = add k 1' 's = add k 2' |
| 142 | echo "doctor mutants: $killed killed" |
| 143 | |
| 144 | if [ -n "${TOOLS_OM_COVERAGE:-}" ]; then |
| 145 | mkdir -p "$TOOLS_OM_COVERAGE" "$tmp/cov" |
| 146 | cp $SRC "$tmp/cov/cudapp_doctor.c" |
| 147 | (cd "$tmp/cov" && $CC -std=gnu11 -D_GNU_SOURCE -O0 --coverage -I"$ROOT/src" "$ABI" $OFF -o doc_cov cudapp_doctor.c "$ROOT/src/omega_gpu_chip.c" "$ROOT/src/cudapp_om_chip_admit.c" "$ROOT/src/cudapp_om_chip_enum.c") |
| 148 | run_all "$tmp/cov/doc_cov" "$tmp/cov/r" |
| 149 | (cd "$tmp/cov" && gcov -b -c doc_cov-cudapp_doctor.c > "$TOOLS_OM_COVERAGE/doctor.gcov.txt" 2>&1) |
| 150 | cp "$tmp/cov/cudapp_doctor.c.gcov" "$TOOLS_OM_COVERAGE/cudapp_doctor.c.gcov" |
| 151 | echo "coverage: $TOOLS_OM_COVERAGE/doctor.gcov.txt" |
| 152 | fi |
| 153 | echo "tools-om doctor: PASS (differential $machines machines, negative control, build-text refusal, $killed mutants killed)" |