interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / tools / runtime_api_negative.sh

115 lines · 9922 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# runtime_api_negative.sh -- negative controls for tools/runtime_api_check.sh (R1, omega-mv#594).
4#
5# tools/runtime_api_negative.sh MANIFEST ROOT WORK_DIR API_MD
6#
7# Copies the headers, API.md, the manifest and its INTERNAL list to WORK_DIR, breaks one copy in one way at a time and
8# runs the check on the copies. Each break must make
9# the check FAIL and say the expected thing; if the check still passes, this script fails (the check cannot see that
10# class of change). Then it breaks copies of the manifest and runs tools/runtime_api_semver.sh against the real one:
11# each too-small bump must FAIL, and one correct bump must PASS. The real headers and manifest are never touched.
12set -u
13[ $# -eq 4 ] || { echo "usage: $0 MANIFEST ROOT WORK_DIR API_MD" >&2; exit 2; }
14MANIFEST=$1; ROOT=$(cd "$2" && pwd) || exit 2; WORK=$3; APIMD=$4
15HERE=$(dirname "$0")
16bad=0
17# control NAME EXPECTED_TEXT FILE SED_EXPR (FILE: a header under src/, API.md, manifest, or internal)
18control() {
19 name=$1; expect=$2; file=$3; expr=$4
20 d=$WORK/neg-$name; rm -rf "$d"; mkdir -p "$d/src"; cp "$ROOT"/src/*.h "$d/src/"; cp "$APIMD" "$d/API.md"
21 # the check reads the INTERNAL list next to the manifest (.manifest -> .internal), so both copies keep that pairing
22 cp "$MANIFEST" "$d/api.manifest"; cp "${MANIFEST%.manifest}.internal" "$d/api.internal"
23 case $file in
24 API.md) target=$d/API.md ;;
25 manifest) target=$d/api.manifest ;;
26 internal) target=$d/api.internal ;;
27 *) target=$d/src/$file ;;
28 esac
29 # POSIX sed has no -i. Generate a private replacement, then verify the mutation
30 # before moving it over the scratch fixture; never edit the real headers/docs.
31 if ! sed -e "$expr" "$target" > "$d/edit.tmp"; then
32 echo "NEGATIVE CONTROL $name: BROKEN (fixture edit failed)"; bad=1; return
33 fi
34 if cmp -s "$target" "$d/edit.tmp"; then
35 echo "NEGATIVE CONTROL $name: BROKEN (the edit changed nothing)"; bad=1; return
36 fi
37 if ! mv "$d/edit.tmp" "$target"; then
38 echo "NEGATIVE CONTROL $name: BROKEN (fixture replacement failed)"; bad=1; return
39 fi
40 out=$("$HERE/runtime_api_check.sh" "$d/api.manifest" "$d" "$d/work" "$d/API.md" 2>&1); rc=$?
41 if [ $rc -ne 0 ] && printf '%s\n' "$out" | grep -qF "$expect"; then echo "NEGATIVE CONTROL $name: FAILED as it must ($expect)"
42 else echo "NEGATIVE CONTROL $name: NOT CAUGHT (rc=$rc, wanted \"$expect\")"; printf '%s\n' "$out" | head -5; bad=1; fi
43}
44control removed-function "header disagrees with manifest: fn omega_gpu_session_alloc_code" omega_gpu_session.h '/^int omega_gpu_session_alloc_code(/d'
45control missing-version "version macro missing: OMEGA_RUNTIME_API_VERSION_MAJOR" omega_runtime_api.h '/define OMEGA_RUNTIME_API_VERSION_MAJOR/d'
46control changed-signature "header disagrees with manifest: fn omega_gpu_session_free" omega_gpu_session.h 's/^void omega_gpu_session_free(OmegaGpuMem \*m);/void omega_gpu_session_free(const OmegaGpuMem *m);/'
47control changed-struct 'manifest says `struct OmegaGpuLaunch ' omega_gpu_session.h 's/uint64_t timeout_ms; \/\*/uint32_t timeout_ms; \/*/'
48control changed-constant 'manifest says `const OMEGA_GPU_SESSION_MAX_ARGS ' omega_gpu_session.h 's/OMEGA_GPU_SESSION_MAX_ARGS 32u/OMEGA_GPU_SESSION_MAX_ARGS 64u/'
49control version-doc-mismatch "must contain the line \"Omega Runtime API version:" API.md 's/^Omega Runtime API version: .*/Omega Runtime API version: 9.9/'
50control stable-without-doc "STABLE entry omega_gpu_session_launch has no" API.md 's/^#### `omega_gpu_session_launch`/#### launch/'
51control wrong-quoted-signature "signature quoted in" API.md 's/^uint32_t omega_gpu_session_open_count(void);/uint64_t omega_gpu_session_open_count(void);/'
52control signature-inside-another "signature quoted in" API.md 's/^uint32_t omega_gpu_session_open_count(void);/int32_t omega_gpu_session_open_count(void);/'
53control missing-patch-version "version macro missing: OMEGA_RUNTIME_API_VERSION_PATCH" omega_runtime_api.h '/define OMEGA_RUNTIME_API_VERSION_PATCH/d'
54control added-undeclared-function "undeclared public entry (in a manifest header, not in the manifest or the INTERNAL list): fn omega_gpu_session_sneaky" \
55 omega_gpu_session.h 's/^void omega_gpu_session_set_error(const char \*stage);/&\nint omega_gpu_session_sneaky(void);/'
56control added-undeclared-constant "undeclared public entry (in a manifest header, not in the manifest or the INTERNAL list): const OMEGA_GPU_SESSION_SNEAKY" \
57 omega_gpu_session.h 's/^#define OMEGA_GPU_SESSION_MAX_ARGS 32u/&\n#define OMEGA_GPU_SESSION_SNEAKY 7u/'
58control added-undeclared-enumerator "undeclared public entry (in a manifest header, not in the manifest or the INTERNAL list): const OMEGA_GPU_CMDLIST_BARRIER_SNEAKY" \
59 omega_gpu_cmdlist.h 's/OMEGA_GPU_CMDLIST_BARRIER_FLUSH_DATA = 4 }/OMEGA_GPU_CMDLIST_BARRIER_FLUSH_DATA = 4, OMEGA_GPU_CMDLIST_BARRIER_SNEAKY = 5 }/'
60control stale-internal-entry "stale INTERNAL entry (no manifest header declares it): fn omega_gpu_session_set_error" \
61 omega_gpu_session.h '/^void omega_gpu_session_set_error(const char \*stage);/d'
62# the controls the omega-mv copy of this gate carried (omega-mv tests/gates/omega-runtime-api.gate, retired there when
63# the runtime API moved here) that the list above did not have yet
64control removed-recover "header disagrees with manifest: fn omega_gpu_session_recover" omega_gpu_session.h '/^int omega_gpu_session_recover(void);/d'
65control removed-padding-field "header disagrees with manifest: field OmegaGpuCmdListOpts first_barrier_none" omega_gpu_cmdlist.h '/int first_barrier_none;/,/\*\/$/d'
66control new-fnptr-function "undeclared public entry (in a manifest header, not in the manifest or the INTERNAL list): fn omega_gpu_session_zzz_fp" \
67 omega_gpu_session.h '$a\
68int (*omega_gpu_session_zzz_fp(void))(int);'
69control manifest-fn-dropped "undeclared public entry (in a manifest header, not in the manifest or the INTERNAL list): fn omega_gpu_serving_seal" \
70 manifest '/^fn omega_gpu_serving_seal /d'
71control internal-unlisted "undeclared public entry (in a manifest header, not in the manifest or the INTERNAL list): fn omega_gpu_session_set_error" \
72 internal '/^fn omega_gpu_session_set_error /d'
73control internal-also-manifest "entry is both in the manifest and INTERNAL: fn omega_gpu_session_launch" \
74 internal '$a\
75fn omega_gpu_session_launch # control: a manifest fn also named INTERNAL'
76control internal-without-reason "INTERNAL entry fn omega_gpu_session_set_error gives no reason" \
77 internal 's/^fn omega_gpu_session_set_error #.*/fn omega_gpu_session_set_error/'
78# a stale API.md: a section for an entry the manifest no longer has
79control stale-doc-section "stale API.md section (no manifest fn or struct): omega_gpu_session_retired" \
80 API.md '$a\
81#### `omega_gpu_session_retired`'
82
83# semver NAME WANT(FAIL|PASS) EXPECTED_TEXT SED_EXPR [BASE_EXPR] -- a manifest copy edited by SED_EXPR, checked against the
84# real manifest (or against a copy edited by BASE_EXPR, e.g. to stand in for a base already past 1.0)
85semver() {
86 name=$1; want=$2; expect=$3; expr=$4; bexpr=${5:-}
87 d=$WORK/neg-semver-$name; rm -rf "$d"; mkdir -p "$d"
88 sed -e "$expr" "$MANIFEST" > "$d/head.manifest" || { echo "NEGATIVE CONTROL semver-$name: BROKEN (fixture edit failed)"; bad=1; return; }
89 if [ -n "$bexpr" ]; then sed -e "$bexpr" "$MANIFEST" > "$d/base.manifest"; else cp "$MANIFEST" "$d/base.manifest"; fi
90 if cmp -s "$d/base.manifest" "$d/head.manifest"; then echo "NEGATIVE CONTROL semver-$name: BROKEN (the edit changed nothing)"; bad=1; return; fi
91 out=$("$HERE/runtime_api_semver.sh" "$d/base.manifest" "$d/head.manifest" 2>&1); rc=$?
92 if [ "$want" = FAIL ]; then
93 if [ $rc -eq 1 ] && printf '%s\n' "$out" | grep -qF "$expect"; then echo "NEGATIVE CONTROL semver-$name: FAILED as it must ($expect)"
94 else echo "NEGATIVE CONTROL semver-$name: NOT CAUGHT (rc=$rc, wanted \"$expect\")"; printf '%s\n' "$out" | head -5; bad=1; fi
95 else
96 if [ $rc -eq 0 ] && printf '%s\n' "$out" | grep -qF "$expect"; then echo "POSITIVE CONTROL semver-$name: PASSED as it must ($expect)"
97 else echo "POSITIVE CONTROL semver-$name: WRONGLY FAILED (rc=$rc)"; printf '%s\n' "$out" | head -5; bad=1; fi
98 fi
99}
100minor_up='s/^\(const OMEGA_RUNTIME_API_VERSION_MINOR \)\([0-9]*\)$/\1999/'
101major_one='s/^const OMEGA_RUNTIME_API_VERSION_MAJOR [0-9]*$/const OMEGA_RUNTIME_API_VERSION_MAJOR 1/'
102# major version zero (API.md section 2, semver 2.0.0 item 4): a STABLE removal passes with a MINOR bump while the base is 0.x,
103# fails with no bump, and fails with a MINOR-only bump once the base is 1.x
104semver removed-stable-minor-under-zero PASS "the entry changes need MINOR (MAJOR-class under major version zero)" "/^fn omega_gpu_session_alloc_code /d; $minor_up"
105semver removed-stable-unbumped-under-zero FAIL "needs at least a MINOR bump" "/^fn omega_gpu_session_alloc_code /d"
106semver removed-stable-minor-only-at-one FAIL "needs a MAJOR bump" "/^fn omega_gpu_session_alloc_code /d; $major_one; $minor_up" "$major_one"
107semver changed-stable-unbumped FAIL "needs at least a MINOR bump" 's/^\(fn omega_gpu_session_free \)fn(\*mut OmegaGpuMem)/\1fn(*const OmegaGpuMem)/'
108semver added-unbumped FAIL "needs at least a MINOR bump" '$a\
109fn omega_gpu_session_sneaky fn() -> i32 # EXPERIMENTAL'
110semver version-down FAIL "version goes down" 's/^const OMEGA_RUNTIME_API_VERSION_MINOR [0-9]*$/const OMEGA_RUNTIME_API_VERSION_MINOR 0/; s/^const OMEGA_RUNTIME_API_VERSION_MAJOR [0-9]*$/const OMEGA_RUNTIME_API_VERSION_MAJOR 0/'
111semver added-with-minor PASS "the entry changes need MINOR" "$minor_up"'
112$a\
113fn omega_gpu_session_sneaky fn() -> i32 # EXPERIMENTAL'
114[ $bad = 0 ] && { echo "RESULT: PASS (every negative control was caught)"; exit 0; }
115echo "RESULT: FAIL (a negative control was not caught)"; exit 1