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 / tools / extract / audit-error-selftest.sh
| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | set -euo pipefail |
| 4 | here=$(cd "$(dirname "$0")" && pwd) |
| 5 | t=$(mktemp -d) |
| 6 | trap 'rm -rf "$t"' EXIT |
| 7 | mkdir -p "$t/scanner" "$t/bin" "$t/repo" |
| 8 | cp "$here/audit-scan.sh" "$t/scanner/audit-scan.sh" |
| 9 | printf '%s\n' SYNTHETIC_ONLY > "$t/scanner/rules-secrets.txt" |
| 10 | printf '%s\n' PRIVATE_ONLY > "$t/scanner/rules-private.txt" |
| 11 | git -C "$t/repo" init -q |
| 12 | git -C "$t/repo" config user.name test |
| 13 | git -C "$t/repo" config user.email test@example.invalid |
| 14 | printf '%s\n' benign > "$t/repo/input" |
| 15 | git -C "$t/repo" add input |
| 16 | git -C "$t/repo" commit -qm initial |
| 17 | real_grep=$(command -v grep) |
| 18 | printf '#!/bin/bash\nif [[ ${1-} == "${SCAN_FAIL_MODE-}" ]]; then exit 2; fi\nexec %q "$@"\n' "$real_grep" > "$t/bin/grep" |
| 19 | chmod +x "$t/bin/grep" |
| 20 | for phase in -naP -noaP -nP -noP; do |
| 21 | rc=0 |
| 22 | PATH="$t/bin:$PATH" SCAN_FAIL_MODE="$phase" bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" 2>&1 || rc=$? |
| 23 | if [[ $rc != 2 ]]; then |
| 24 | echo "ERROR SELFTEST FAIL: grep phase $phase returned $rc, expected 2" |
| 25 | exit 1 |
| 26 | fi |
| 27 | done |
| 28 | mkdir "$t/openfailbin" |
| 29 | real_mktemp=$(command -v mktemp) |
| 30 | printf '#!/bin/bash\nset -e\np=$(%q "$@")\nmkdir "$p/matches"\nprintf "%%s\\n" "$p"\n' "$real_mktemp" > "$t/openfailbin/mktemp" |
| 31 | chmod +x "$t/openfailbin/mktemp" |
| 32 | rc=0 |
| 33 | PATH="$t/openfailbin:$PATH" bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" 2>&1 || rc=$? |
| 34 | [[ $rc == 2 ]] || { echo "ERROR SELFTEST FAIL: output-open error returned $rc"; exit 1; } |
| 35 | for rule in secrets private; do |
| 36 | cp "$t/scanner/rules-$rule.txt" "$t/rule.save" |
| 37 | printf '[\n' > "$t/scanner/rules-$rule.txt" |
| 38 | rc=0 |
| 39 | bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" 2>&1 || rc=$? |
| 40 | cp "$t/rule.save" "$t/scanner/rules-$rule.txt" |
| 41 | [[ $rc == 2 ]] || { echo "ERROR SELFTEST FAIL: invalid $rule regex returned $rc"; exit 1; } |
| 42 | done |
| 43 | bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" |
| 44 | printf '\037\213broken' > "$t/repo/corrupt.gz" |
| 45 | git -C "$t/repo" add . |
| 46 | git -C "$t/repo" commit -qm corrupt |
| 47 | rc=0 |
| 48 | bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" 2>&1 || rc=$? |
| 49 | [[ $rc == 2 && -s $t/out/unscanned.txt ]] || { echo 'ERROR SELFTEST FAIL: corrupt compression was not refused'; exit 1; } |
| 50 | printf '%s\n' SYNTHETIC_ONLY > "$t/repo/delimiter|file" |
| 51 | git -C "$t/repo" add . |
| 52 | git -C "$t/repo" commit -qm delimiter |
| 53 | rc=0 |
| 54 | bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" 2>&1 || rc=$? |
| 55 | [[ $rc == 1 ]] || { echo "ERROR SELFTEST FAIL: delimiter-path secret returned $rc"; exit 1; } |
| 56 | grep -F 'delimiter|file:' "$t/out/secrets.txt" > /dev/null |
| 57 | echo 'ERROR SELFTEST PASS: scan errors refuse; clean input and delimiter-path detection preserved' |