Files

65 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Runs a fixed, named set of doos invocations under valgrind's memcheck, using
# valgrind/doos.supp to silence the known, explained allocation sites (see that file's
# comments), and fails only on a real, unsuppressed memory error or leak. Does not rebuild;
# run `make build` (or just `make valgrind`, which depends on it) first.
#
# Usage: scripts/valgrind.sh [path/to/doos]
set -u
cd "$(dirname "$0")/.."
DOOS="${1:-build/doos}"
SUPP="$(pwd)/valgrind/doos.supp"
REPORTS="build/valgrind-reports"
TIMEOUT=60
command -v valgrind >/dev/null || { echo "valgrind: not installed"; exit 1; }
[ -x "$DOOS" ] || { echo "valgrind: no doos binary at '$DOOS' (run 'make build' first)"; exit 1; }
[ -f "$SUPP" ] || { echo "valgrind: suppressions file missing: $SUPP"; exit 1; }
rm -rf "$REPORTS"
mkdir -p "$REPORTS"
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
export DOOS_HOME="$TMP/home"
fails=0
checked=0
run() { # run NAME -- DOOS_ARGS...
local name="$1"; shift
shift # drop the --
checked=$((checked + 1))
local log="$REPORTS/$name.log"
timeout "$TIMEOUT" valgrind \
--leak-check=full --show-leak-kinds=all --track-origins=yes \
--suppressions="$SUPP" --error-exitcode=99 \
--log-file="$log" \
"$DOOS" "$@" >/dev/null 2>&1
local rc=$?
if [ "$rc" = 99 ]; then
echo "FAIL $name: valgrind reported an unsuppressed error or leak, see $log"
fails=$((fails + 1))
elif [ "$rc" = 124 ]; then
echo "FAIL $name: timed out after ${TIMEOUT}s under valgrind, see $log"
fails=$((fails + 1))
else
echo "ok $name (doos exit=$rc; valgrind found nothing to report), see $log"
fi
}
# Fixed, named set: the four CLI commands SPEC.md documents, plus a second attach to exercise
# the join-a-running-container path. No image download here (network + extraction add their
# own long-running C library code, better covered once by a dedicated image-mode run; see
# valgrind/README.md for how to add one).
run list -- list
run get_or_create -- get_or_create --net none vgcheck
run attach_first -- attach --net none vgcheck -- true
run attach_join -- attach --net none vgcheck -- true
run image_list -- image list
run delete -- delete --yes vgcheck
echo "valgrind: $checked checked, $fails failed, reports in $REPORTS/"
[ "$fails" -eq 0 ]