88 lines
3.0 KiB
Bash
Executable File
88 lines
3.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# This program is free software, licensed under the terms of the GNU GPL.
|
|
# See the Bongo COPYING file for full details.
|
|
# Copyright (c) 2026 Bongo Project contributors
|
|
|
|
set -eu
|
|
|
|
: "${BONGO_TEST_ROOT:?set BONGO_TEST_ROOT to the staged /usr root}"
|
|
: "${BONGO_TEST_PASSWORD:?set a disposable BONGO_TEST_PASSWORD}"
|
|
BONGO_SANITIZER=${BONGO_SANITIZER:-asan}
|
|
BONGO_TEST_OUTPUT=${BONGO_TEST_OUTPUT:-/tmp/bongo-sanitizer-session}
|
|
script_directory=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
smoke=${BONGO_PROTOCOL_SMOKE:-$script_directory/protocol-smoke.py}
|
|
log="$BONGO_TEST_OUTPUT/manager.log"
|
|
mkdir -p "$BONGO_TEST_OUTPUT"
|
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
echo 'Run this script as root inside a private user/network namespace.' >&2
|
|
exit 1
|
|
fi
|
|
/usr/sbin/ip link set lo up
|
|
|
|
case "$BONGO_SANITIZER" in
|
|
asan)
|
|
runtime=${BONGO_SANITIZER_RUNTIME:-$(cc -print-file-name=libasan.so)}
|
|
export ASAN_OPTIONS=${ASAN_OPTIONS:-halt_on_error=1:abort_on_error=1:detect_leaks=1:fast_unwind_on_malloc=0:malloc_context_size=50}
|
|
export UBSAN_OPTIONS=${UBSAN_OPTIONS:-halt_on_error=1:print_stacktrace=1}
|
|
export LSAN_OPTIONS=${LSAN_OPTIONS:-exitcode=23:report_objects=1}
|
|
export BONGO_SIEVE_VALIDATE_PATH="$script_directory/sieve-validate-no-lsan.sh"
|
|
finding='LeakSanitizer|AddressSanitizer|runtime error:|UndefinedBehaviorSanitizer|stubbornly refusing to die'
|
|
;;
|
|
tsan)
|
|
runtime=${BONGO_SANITIZER_RUNTIME:-$(clang -print-file-name=libclang_rt.tsan-x86_64.so)}
|
|
export TSAN_OPTIONS=${TSAN_OPTIONS:-halt_on_error=1:second_deadlock_stack=1}
|
|
export BONGO_SIEVE_VALIDATE_PATH="$BONGO_TEST_ROOT/libexec/bongo/bongo-sieve-validate"
|
|
finding='ThreadSanitizer|WARNING: ThreadSanitizer|data race|runtime error:|stubbornly refusing to die'
|
|
;;
|
|
*)
|
|
echo "Unknown BONGO_SANITIZER: $BONGO_SANITIZER" >&2
|
|
exit 64
|
|
;;
|
|
esac
|
|
if [ ! -r "$runtime" ]; then
|
|
echo "Sanitizer runtime not found: $runtime" >&2
|
|
exit 1
|
|
fi
|
|
export LD_PRELOAD=$runtime
|
|
|
|
: >"$log"
|
|
"$BONGO_TEST_ROOT/sbin/bongo-manager" -k >"$log" 2>&1 &
|
|
manager_pid=$!
|
|
|
|
cleanup()
|
|
{
|
|
if [ -n "${manager_pid:-}" ]; then
|
|
kill -TERM "$manager_pid" 2>/dev/null || true
|
|
wait "$manager_pid" 2>/dev/null || true
|
|
fi
|
|
}
|
|
trap cleanup EXIT HUP INT TERM
|
|
|
|
if ! "$smoke" --wait-only; then
|
|
echo 'Manager listeners did not become ready.' >&2
|
|
sed -n '1,320p' "$log" >&2
|
|
exit 1
|
|
fi
|
|
if ! kill -0 "$manager_pid" 2>/dev/null; then
|
|
echo 'Manager exited during startup.' >&2
|
|
sed -n '1,320p' "$log" >&2
|
|
exit 1
|
|
fi
|
|
"$smoke"
|
|
ps -eo pid,ppid,stat,nlwp,comm,args --forest >"$BONGO_TEST_OUTPUT/processes.txt"
|
|
|
|
kill -TERM "$manager_pid"
|
|
if ! wait "$manager_pid"; then
|
|
echo 'Manager or an agent failed during shutdown.' >&2
|
|
manager_pid=
|
|
sed -n '1,400p' "$log" >&2
|
|
exit 1
|
|
fi
|
|
manager_pid=
|
|
if grep -E "$finding" "$log"; then
|
|
echo "${BONGO_SANITIZER} finding in manager/agent log" >&2
|
|
exit 1
|
|
fi
|
|
echo "PASS $BONGO_SANITIZER protocol session"
|