From: Michal Nowak Date: Fri, 3 Apr 2020 09:26:02 +0000 (+0200) Subject: Provide unit test driver X-Git-Tag: v9.17.2~62^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bfa6ecb796e9b0d0ca3986128a79a483e58416bf;p=thirdparty%2Fbind9.git 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. --- diff --git a/configure.ac b/configure.ac index d9a9c528f50..dd075e65f29 100644 --- a/configure.ac +++ b/configure.ac @@ -1637,6 +1637,9 @@ AC_CONFIG_FILES([lib/isc/tests/Makefile lib/isccc/tests/Makefile lib/isccfg/tests/Makefile]) +AC_CONFIG_FILES([lib/unit-test-driver.sh], + [chmod +x lib/unit-test-driver.sh]) + # System Tests AC_CONFIG_FILES([bin/tests/Makefile diff --git a/lib/.gitignore b/lib/.gitignore index 8445734faf5..9c93fd5f6b9 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -1,3 +1,4 @@ platform.h netdb.h gen +/unit-test-driver.sh diff --git a/lib/dns/tests/Makefile.am b/lib/dns/tests/Makefile.am index 0d658db2518..9f3ee80cce2 100644 --- a/lib/dns/tests/Makefile.am +++ b/lib/dns/tests/Makefile.am @@ -108,3 +108,5 @@ rsa_test_CPPFLAGS = \ $(OPENSSL_CFLAGS) unit-local: check + +LOG_COMPILER = $(builddir)/../../unit-test-driver.sh diff --git a/lib/irs/tests/Makefile.am b/lib/irs/tests/Makefile.am index 0246f34cc79..6b9bb583eb9 100644 --- a/lib/irs/tests/Makefile.am +++ b/lib/irs/tests/Makefile.am @@ -15,3 +15,5 @@ check_PROGRAMS = \ TESTS = $(check_PROGRAMS) unit-local: check + +LOG_COMPILER = $(builddir)/../../unit-test-driver.sh diff --git a/lib/isc/tests/Makefile.am b/lib/isc/tests/Makefile.am index c7ae206d78e..3723a392de4 100644 --- a/lib/isc/tests/Makefile.am +++ b/lib/isc/tests/Makefile.am @@ -65,3 +65,5 @@ random_test_LDADD = \ -lm unit-local: check + +LOG_COMPILER = $(builddir)/../../unit-test-driver.sh diff --git a/lib/isccc/tests/Makefile.am b/lib/isccc/tests/Makefile.am index a0b5abd3b82..048f2a9f0f6 100644 --- a/lib/isccc/tests/Makefile.am +++ b/lib/isccc/tests/Makefile.am @@ -15,3 +15,5 @@ check_PROGRAMS = \ TESTS = $(check_PROGRAMS) unit-local: check + +LOG_COMPILER = $(builddir)/../../unit-test-driver.sh diff --git a/lib/isccfg/tests/Makefile.am b/lib/isccfg/tests/Makefile.am index 42242ad0705..ce4ea0fd42f 100644 --- a/lib/isccfg/tests/Makefile.am +++ b/lib/isccfg/tests/Makefile.am @@ -17,3 +17,5 @@ check_PROGRAMS = \ TESTS = $(check_PROGRAMS) unit-local: check + +LOG_COMPILER = $(builddir)/../../unit-test-driver.sh diff --git a/lib/ns/tests/Makefile.am b/lib/ns/tests/Makefile.am index c7ff73cd316..415a21ee963 100644 --- a/lib/ns/tests/Makefile.am +++ b/lib/ns/tests/Makefile.am @@ -45,3 +45,5 @@ query_test_LDFLAGS = \ endif unit-local: check + +LOG_COMPILER = $(builddir)/../../unit-test-driver.sh diff --git a/lib/unit-test-driver.sh.in b/lib/unit-test-driver.sh.in new file mode 100644 index 00000000000..4fbd84b361b --- /dev/null +++ b/lib/unit-test-driver.sh.in @@ -0,0 +1,34 @@ +#!/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}