#!/bin/sh # The unit tests under AddressSanitizer + UndefinedBehaviorSanitizer. # # `make check` proves behaviour; this proves the memory the behaviour runs on. # It found two real defects the normal run cannot see: the agent never freed # the reply of a terminal transport failure, and the mock transport leaked a # queued body. Both are fixed; the remaining suppressions are the MCP plugin's # teardown allocations (tests/asan.supp explains why). # # The whole tree is rebuilt with sanitizers and then rebuilt normally, because # the Makefile builds in place. Run it when the tree is idle. set -e cd "$(dirname "$0")/.." ACF="-std=c99 -O1 -g -Wall -Wextra -fPIC -D_POSIX_C_SOURCE=200809L \ -fsanitize=address,undefined -fno-omit-frame-pointer \ -Iinclude -Isrc/backend -Isrc/frontend -Ivendor/libmcp \ -Ivendor/netbsd-curses/libcurses" TESTS=$(make -s print-tests) [ -n "$TESTS" ] || { echo "no test binaries to run" >&2; exit 1; } make clean >/dev/null if ! make -j"$(nproc)" CFLAGS="$ACF" all $TESTS > /tmp/check_asan_build.log 2>&1; then tail -20 /tmp/check_asan_build.log >&2 echo "asan build failed" >&2 exit 1 fi failed=0 for t in $TESTS; do if ! ASAN_OPTIONS=detect_leaks=1:abort_on_error=1 \ UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 \ LSAN_OPTIONS=suppressions=tests/asan.supp \ LD_LIBRARY_PATH=. "./$t" > /tmp/check_asan_one.log 2>&1; then echo "FAIL $t" tail -20 /tmp/check_asan_one.log | sed 's/^/ /' failed=1 fi done # leave the tree as it was found: a normal build make clean >/dev/null make -j"$(nproc)" >/dev/null if [ "$failed" -eq 0 ]; then echo "check_asan: all $(echo "$TESTS" | wc -w) test binaries clean" else echo "check_asan: FAILURES" >&2 fi exit "$failed"