bind9/lib/unit-test-driver.sh.in
Michal Nowak bfa6ecb796
Provide unit test driver
This adds a unit test driver for BIND with Automake.  It runs the unit
test program provided as its sole command line argument and then looks
for a core dump generated by that test program.  If one is found, the
driver prints the backtrace into the test log.
2020-05-21 12:13:01 +02:00

34 lines
1.1 KiB
Bash

#!/bin/sh
TOP_BUILDDIR=@abs_top_builddir@
TOP_SRCDIR=@abs_top_srcdir@
if [ -z "${1}" ]; then
echo "Usage: ${0} test_program" >&2
exit 1
fi
TEST_PROGRAM="${1}"
"${TEST_PROGRAM}"
STATUS=${?}
TEST_PROGRAM_NAME=$(basename "${TEST_PROGRAM}")
TEST_PROGRAM_WORK_DIR=$(dirname "${TEST_PROGRAM}")
find "${TEST_PROGRAM_WORK_DIR}" -name 'core*' -or -name '*.core' | while read -r CORE_DUMP; do
BINARY=$(gdb --batch --core="${CORE_DUMP}" 2>/dev/null | sed -n "s/^Core was generated by \`\(.*\)'\.\$/\1/p")
if ! echo "${BINARY}" | grep -q "${TEST_PROGRAM_NAME}\$"; then
continue
fi
echo "I:${TEST_PROGRAM_NAME}:Core dump found: ${CORE_DUMP}"
echo "D:${TEST_PROGRAM_NAME}:backtrace from ${CORE_DUMP} start"
"${TOP_BUILDDIR}/libtool" --mode=execute gdb \
--batch \
--command="${TOP_SRCDIR}/bin/tests/system/run.gdb" \
--core="${CORE_DUMP}" \
-- \
"${BINARY}"
echo "D:${TEST_PROGRAM_NAME}:backtrace from ${CORE_DUMP} end"
done
exit ${STATUS}