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 / share / run-share-native.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # Host verification of native/share/share_native.om, the OM-2 function-mode zero-copy unit for |
| 4 | # the one hosted native library. External harness; not a runtime dependency. It builds a |
| 5 | # single-input hosted library with omega-bridge tools/native --host into $OUT/lib as a test |
| 6 | # artifact (never linked into the product; Integration generates the combined library), runs |
| 7 | # tests/share/native-share-test.c against the seccomp fake RM, then rebuilds the library from |
| 8 | # each mutant in tests/share/native-mutants.txt and requires the test to fail. |
| 9 | # Usage: run-share-native.sh [--no-mutants] |
| 10 | # Env (all required): OMEGA_NATIVE_OMC (pinned program-mode omc for tools/native), |
| 11 | # OMEGA_NATIVE_OMC2 (pinned OM-2 omc), ZERO_COPY_NATIVE_BRIDGE (omega-bridge checkout with the |
| 12 | # shared explicit native context). Optional: CC, ZERO_COPY_OUT (build/zero-copy). |
| 13 | # Exit 2 = NOT_RUN (missing toolchain); 1 = FAIL; 0 = PASS. |
| 14 | set -eu |
| 15 | MODE=${1:-} |
| 16 | OUT=${ZERO_COPY_OUT:-build/zero-copy}/native |
| 17 | SRC=native/share/share_native.om |
| 18 | for v in OMEGA_NATIVE_OMC OMEGA_NATIVE_OMC2 ZERO_COPY_NATIVE_BRIDGE; do |
| 19 | eval "x=\${$v:-}" |
| 20 | if test -z "$x"; then |
| 21 | echo "zero-copy native: NOT_RUN ($v unset)" |
| 22 | exit 2 |
| 23 | fi |
| 24 | done |
| 25 | pin() { |
| 26 | got=$(sha256sum < "$2" | cut -c1-64) |
| 27 | if test "$got" != "$3"; then |
| 28 | echo "zero-copy native: FAIL $1 sha256 $got, want $3" >&2 |
| 29 | exit 1 |
| 30 | fi |
| 31 | } |
| 32 | # omega-mv dbedb2ca (OM-2 explicit native context, omega-bridge#69 248a1984 / A64 #1047 b8f8f137). |
| 33 | pin OMEGA_NATIVE_OMC2 "$OMEGA_NATIVE_OMC2" b8f8f1371bc0303f8da02db8b754e085d5dd852620c8d8d676c5769c233d9195 |
| 34 | pin OMEGA_NATIVE_OMC "$OMEGA_NATIVE_OMC" 734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61 |
| 35 | T=third_party/nvidia-open-580.173.02 |
| 36 | TOP=$(pwd) |
| 37 | rm -rf "$OUT" |
| 38 | mkdir -p "$OUT" |
| 39 | OUT=$(cd "$OUT" && pwd) |
| 40 | |
| 41 | # Build the library from one unit into $1 and the test against it; quiet unless it fails. |
| 42 | build() { |
| 43 | (cd "$ZERO_COPY_NATIVE_BRIDGE" && tools/native --host "$1" "$2") > "$1.log" 2>&1 || return 1 |
| 44 | ${CC:-cc} -std=gnu11 -O2 -Wall -Wextra -Werror -pthread \ |
| 45 | -I$T/src/common/sdk/nvidia/inc -I$T/kernel-open/common/inc \ |
| 46 | -I$T/kernel-open/nvidia-uvm -I$T/src/nvidia/arch/nvalloc/unix/include -I"$1" \ |
| 47 | tests/share/native-share-test.c -L"$1" -Wl,-rpath,"$1" -lomega_native -o "$1/native-share-test" |
| 48 | } |
| 49 | |
| 50 | if ! build "$OUT/lib" "$TOP/$SRC"; then |
| 51 | cat "$OUT/lib.log" >&2 |
| 52 | echo "zero-copy native: FAIL build of $SRC" >&2 |
| 53 | exit 1 |
| 54 | fi |
| 55 | "$OUT/lib/native-share-test" |
| 56 | test "$MODE" = --no-mutants && exit 0 |
| 57 | |
| 58 | # Mutants: "search|replace" lines; the search text must occur exactly once in the unit. |
| 59 | n=0 |
| 60 | while IFS='|' read -r from to; do |
| 61 | case "$from" in '' | '#'*) continue ;; esac |
| 62 | n=$((n + 1)) |
| 63 | count=$(grep -cF -- "$from" "$SRC" || true) |
| 64 | if test "$count" != 1; then |
| 65 | echo "zero-copy native: FAIL mutant $n site found $count times: $from" >&2 |
| 66 | exit 1 |
| 67 | fi |
| 68 | dir="$OUT/m$n" |
| 69 | mkdir -p "$dir" |
| 70 | awk -v f="$from" -v t="$to" '{ i = index($0, f); if (i) $0 = substr($0, 1, i - 1) t substr($0, i + length(f)); print }' \ |
| 71 | "$SRC" > "$dir/share_native.om" |
| 72 | if ! build "$dir/lib" "$dir/share_native.om"; then |
| 73 | echo "zero-copy native: FAIL mutant $n does not build (a vacuous mutant): $from -> $to" >&2 |
| 74 | exit 1 |
| 75 | fi |
| 76 | if "$dir/lib/native-share-test" > "$dir/run.log" 2>&1; then |
| 77 | echo "zero-copy native: FAIL mutant $n survived: $from -> $to" >&2 |
| 78 | exit 1 |
| 79 | fi |
| 80 | echo "zero-copy native: mutant $n caught ($(tail -n 1 "$dir/run.log")): $from -> $to" |
| 81 | done < tests/share/native-mutants.txt |
| 82 | echo "ZERO-COPY SHARE NATIVE MUTANTS PASS ($n/$n caught)" |