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 / extract / audit-error-selftest.sh

57 lines · 2696 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3set -euo pipefail
4here=$(cd "$(dirname "$0")" && pwd)
5t=$(mktemp -d)
6trap 'rm -rf "$t"' EXIT
7mkdir -p "$t/scanner" "$t/bin" "$t/repo"
8cp "$here/audit-scan.sh" "$t/scanner/audit-scan.sh"
9printf '%s\n' SYNTHETIC_ONLY > "$t/scanner/rules-secrets.txt"
10printf '%s\n' PRIVATE_ONLY > "$t/scanner/rules-private.txt"
11git -C "$t/repo" init -q
12git -C "$t/repo" config user.name test
13git -C "$t/repo" config user.email test@example.invalid
14printf '%s\n' benign > "$t/repo/input"
15git -C "$t/repo" add input
16git -C "$t/repo" commit -qm initial
17real_grep=$(command -v grep)
18printf '#!/bin/bash\nif [[ ${1-} == "${SCAN_FAIL_MODE-}" ]]; then exit 2; fi\nexec %q "$@"\n' "$real_grep" > "$t/bin/grep"
19chmod +x "$t/bin/grep"
20for 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
27done
28mkdir "$t/openfailbin"
29real_mktemp=$(command -v mktemp)
30printf '#!/bin/bash\nset -e\np=$(%q "$@")\nmkdir "$p/matches"\nprintf "%%s\\n" "$p"\n' "$real_mktemp" > "$t/openfailbin/mktemp"
31chmod +x "$t/openfailbin/mktemp"
32rc=0
33PATH="$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; }
35for 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; }
42done
43bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log"
44printf '\037\213broken' > "$t/repo/corrupt.gz"
45git -C "$t/repo" add .
46git -C "$t/repo" commit -qm corrupt
47rc=0
48bash "$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; }
50printf '%s\n' SYNTHETIC_ONLY > "$t/repo/delimiter|file"
51git -C "$t/repo" add .
52git -C "$t/repo" commit -qm delimiter
53rc=0
54bash "$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; }
56grep -F 'delimiter|file:' "$t/out/secrets.txt" > /dev/null
57echo 'ERROR SELFTEST PASS: scan errors refuse; clean input and delimiter-path detection preserved'