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/CUDApp/blob/main/tools/extract/test-drift.sh # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tools / extract / test-drift.sh` 170 lines · 8736 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 # Host-only regressions for drift.sh. Uses local git repositories, no remote or device. 4 set -euo pipefail 5 export LC_ALL=C 6 here=$(cd "$(dirname "$0")" && pwd) 7 scratch=$(mktemp -d); trap 'rm -rf "$scratch"' EXIT 8 export GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null 9 export GIT_AUTHOR_NAME=drift-test GIT_AUTHOR_EMAIL=drift@test.invalid 10 export GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL 11 fail=0 12 13 fixture() { 14 local name=$1 15 c=$scratch/$name/cudapp; o=$scratch/$name/omega 16 mkdir -p "$c/tools/extract" "$c/src" "$o/src" 17 git init -q "$c"; git init -q "$o" 18 cp "$here/drift.sh" "$here/map.sh" "$c/tools/extract/" 19 for file in filemap.tsv shared.txt extra-paths.txt physics-paths.txt; do 20 printf '# fixture\n' > "$c/tools/extract/$file" 21 done 22 } 23 commit_pair() { 24 git -C "$c" add .; git -C "$c" commit -qm fixture 25 git -C "$o" add .; git -C "$o" commit -qm fixture 26 base=$scratch/baseline 27 git -C "$o" ls-tree -r HEAD src | awk '{print $4 "\t" $3}' > "$base" 28 } 29 run() { 30 local name=$1 want_rc=$2 want_summary=$3; shift 3 31 local rc=0 out=$scratch/output 32 "$@" > "$out" 2>&1 || rc=$? 33 echo "=== $name (exit $rc, expected $want_rc) ===" 34 cat "$out" 35 if [[ $rc -ne $want_rc ]] || ! grep -qxF "$want_summary" "$out"; then 36 echo "FAIL: $name"; fail=1 37 elif [[ $want_rc -eq 2 ]] && grep -qE '^(DIVERGENCE:|DRIFT-GATE: PASS|SELF-TEST: PASS)' "$out"; then 38 echo "FAIL: $name printed a success summary after a setup error"; fail=1 39 else echo "PASS: $name"; fi 40 } 41 42 # Each case has one shared path, with literal expected counts. Header-like words 43 # retain the existing diagnostic heuristic; they do not bypass the blob gate. 44 for kind in code header mixed identical large binary; do 45 fixture "$kind" 46 case $kind in 47 code) 48 printf 'int value = 1;\n' > "$o/src/omega_gpu_case.c" 49 printf 'int value = 2;\n' > "$c/src/omega_gpu_case.c" ;; 50 header) 51 printf '// SPDX-License-Identifier: MIT\nint value = 1;\n' > "$o/src/omega_gpu_case.c" 52 printf '// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\nint value = 1;\n' > "$c/src/omega_gpu_case.c" ;; 53 mixed) 54 printf '// SPDX-License-Identifier: MIT\nint value = 1;\n' > "$o/src/omega_gpu_case.c" 55 printf '// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\nint value = 2;\n' > "$c/src/omega_gpu_case.c" ;; 56 identical) 57 printf 'int value = 1;\n' > "$o/src/omega_gpu_case.c" 58 cp "$o/src/omega_gpu_case.c" "$c/src/omega_gpu_case.c" ;; 59 large) 60 awk 'BEGIN {for(i=0;i<20000;i++) print "int value_" i " = 1;"}' > "$o/src/omega_gpu_case.c" 61 awk 'BEGIN {for(i=0;i<20000;i++) print "int value_" i " = 2;"}' > "$c/src/omega_gpu_case.c" ;; 62 binary) 63 printf 'value\0one\n' > "$o/src/omega_gpu_case.c" 64 printf 'value\0two\n' > "$c/src/omega_gpu_case.c" ;; 65 esac 66 commit_pair 67 case $kind in 68 identical) summary='DIVERGENCE: 1 shared, 1 same, 0 differ (0 licence-header only, 0 code); 0 cudapp-only, 0 omega-only' ;; 69 header) summary='DIVERGENCE: 1 shared, 0 same, 1 differ (1 licence-header only, 0 code); 0 cudapp-only, 0 omega-only' ;; 70 *) summary='DIVERGENCE: 1 shared, 0 same, 1 differ (0 licence-header only, 1 code); 0 cudapp-only, 0 omega-only' ;; 71 esac 72 run "$kind classification at baseline" 0 "$summary" bash "$c/tools/extract/drift.sh" "$o" HEAD "$base" 73 # A changed baseline must still reject a header-only blob difference. 74 printf 'src/omega_gpu_case.c\t0000000000000000000000000000000000000000\n' > "$base" 75 rc=1; [[ $kind != identical ]] || rc=0 76 run "$kind blob gate" "$rc" "$summary" bash "$c/tools/extract/drift.sh" "$o" HEAD "$base" 77 done 78 79 fixture controls 80 printf 'int value = 1;\n' > "$o/src/omega_gpu_case.c" 81 printf 'int value = 2;\n' > "$c/src/omega_gpu_case.c" 82 printf 'int same = 1;\n' > "$o/src/omega_gpu_same.c" 83 cp "$o/src/omega_gpu_same.c" "$c/src/omega_gpu_same.c" 84 commit_pair 85 run 'built-in negative controls' 0 'SELF-TEST: PASS (all controls red, real check green)' \ 86 bash "$c/tools/extract/drift.sh" --self-test "$o" HEAD "$base" 87 run 'invalid ref in direct mode' 2 'DRIFT-GATE: NOT_RUN (map failed)' \ 88 bash "$c/tools/extract/drift.sh" "$o" invalid-ref "$base" 89 run 'invalid ref in self-test mode' 2 'DRIFT-GATE: NOT_RUN (map failed)' \ 90 bash "$c/tools/extract/drift.sh" --self-test "$o" invalid-ref "$base" 91 92 # A directory can satisfy -s. It is not a readable baseline file; awk failure 93 # must never be interpreted as no drift. Reject unreadable files as well. 94 mkdir "$scratch/baseline-directory" 95 printf 'not a baseline\n' > "$scratch/baseline-directory/entry" 96 run 'baseline is a directory' 2 "DRIFT-GATE: NOT_RUN (baseline $scratch/baseline-directory is not a readable nonempty file)" \ 97 bash "$c/tools/extract/drift.sh" "$o" HEAD "$scratch/baseline-directory" 98 chmod 000 "$base" 99 if cat "$base" > /dev/null 2>&1; then 100 # Root/CAP_DAC_OVERRIDE may still read mode 000. That is a usable baseline, 101 # not an unreadable-file fixture. Check real readability independently. 102 run 'mode-000 baseline remains readable' 0 'DIVERGENCE: 2 shared, 1 same, 1 differ (0 licence-header only, 1 code); 0 cudapp-only, 0 omega-only' \ 103 bash "$c/tools/extract/drift.sh" "$o" HEAD "$base" 104 else 105 run 'baseline is unreadable' 2 "DRIFT-GATE: NOT_RUN (baseline $base is not a readable nonempty file)" \ 106 bash "$c/tools/extract/drift.sh" "$o" HEAD "$base" 107 fi 108 chmod 600 "$base" 109 110 # Also propagate a read failure after the baseline's initial validation. 111 mkdir "$scratch/awk-bin" 112 cat > "$scratch/awk-bin/awk" <<'EOF' 113 #!/usr/bin/env bash 114 for arg in "$@"; do 115 if [[ $arg == "$DRIFT_TEST_BASELINE" ]]; then echo 'injected awk read error' >&2; exit 2; fi 116 done 117 exec "$DRIFT_TEST_REAL_AWK" "$@" 118 EOF 119 chmod +x "$scratch/awk-bin/awk" 120 run 'baseline comparison read error' 2 'DRIFT-GATE: NOT_RUN (baseline comparison failed)' \ 121 env PATH="$scratch/awk-bin:$PATH" DRIFT_TEST_BASELINE="$base" DRIFT_TEST_REAL_AWK="$(command -v awk)" \ 122 bash "$c/tools/extract/drift.sh" "$o" HEAD "$base" 123 124 # ls-tree can still map a missing blob. Reading its content must fail closed, 125 # not masquerade as a licence-header-only difference via process substitution. 126 for repo in "$o" "$c"; do 127 blob=$(git -C "$repo" rev-parse HEAD:src/omega_gpu_case.c) 128 object=$repo/.git/objects/${blob:0:2}/${blob:2} 129 mv "$object" "$scratch/saved-blob" 130 run 'missing blob' 2 'DRIFT-GATE: NOT_RUN (summary failed)' \ 131 bash "$c/tools/extract/drift.sh" "$o" HEAD "$base" 132 mv "$scratch/saved-blob" "$object" 133 done 134 135 # Deterministic diff I/O-error injection at the external command boundary. 136 # All git mapping and blob extraction remain real. 137 mkdir "$scratch/bin" 138 printf '#!/usr/bin/env bash\necho "injected diff error" >&2\nexit 2\n' > "$scratch/bin/diff" 139 chmod +x "$scratch/bin/diff" 140 run 'diff error' 2 'DRIFT-GATE: NOT_RUN (summary failed)' \ 141 env PATH="$scratch/bin:$PATH" bash "$c/tools/extract/drift.sh" "$o" HEAD "$base" 142 run 'diff error in self-test mode' 2 'DRIFT-GATE: NOT_RUN (summary failed)' \ 143 env PATH="$scratch/bin:$PATH" bash "$c/tools/extract/drift.sh" --self-test "$o" HEAD "$base" 144 145 # A map row labelled differs must not silently accept an empty diff as a header. 146 # Identical real blobs are covered above: map.sh labels them same and skips diff. 147 printf '#!/usr/bin/env bash\nexit 0\n' > "$scratch/bin/diff" 148 run 'diff reports identical for distinct blobs' 2 'DRIFT-GATE: NOT_RUN (summary failed)' \ 149 env PATH="$scratch/bin:$PATH" bash "$c/tools/extract/drift.sh" "$o" HEAD "$base" 150 151 # A setup error in either negative control must retain status 2 even when the 152 # later real check would succeed. Do not swallow it with `check ... || true`. 153 cat > "$scratch/bin/diff" <<'EOF' 154 #!/usr/bin/env bash 155 set -eu 156 n=0 157 if [[ -f $DRIFT_TEST_DIFF_COUNT ]]; then read -r n < "$DRIFT_TEST_DIFF_COUNT"; fi 158 n=$((n + 1)); echo "$n" > "$DRIFT_TEST_DIFF_COUNT" 159 if [[ $n -eq $DRIFT_TEST_DIFF_FAIL_AT ]]; then echo 'injected one-time diff error' >&2; exit 2; fi 160 exec "$DRIFT_TEST_REAL_DIFF" "$@" 161 EOF 162 for control in 1 2; do 163 run "one-time diff error in control $control" 2 'DRIFT-GATE: NOT_RUN (summary failed)' \ 164 env PATH="$scratch/bin:$PATH" DRIFT_TEST_DIFF_COUNT="$scratch/count-$control" \ 165 DRIFT_TEST_DIFF_FAIL_AT="$control" DRIFT_TEST_REAL_DIFF="$(command -v diff)" \ 166 bash "$c/tools/extract/drift.sh" --self-test "$o" HEAD "$base" 167 done 168 169 if [[ $fail -eq 0 ]]; then echo 'DRIFT REGRESSION TESTS PASS'; else echo 'DRIFT REGRESSION TESTS FAIL'; fi 170 exit "$fail"