]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Provide unit test driver
authorMichal Nowak <mnowak@isc.org>
Fri, 3 Apr 2020 09:26:02 +0000 (11:26 +0200)
committerMichal Nowak <mnowak@isc.org>
Thu, 21 May 2020 10:13:01 +0000 (12:13 +0200)
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.

configure.ac
lib/.gitignore
lib/dns/tests/Makefile.am
lib/irs/tests/Makefile.am
lib/isc/tests/Makefile.am
lib/isccc/tests/Makefile.am
lib/isccfg/tests/Makefile.am
lib/ns/tests/Makefile.am
lib/unit-test-driver.sh.in [new file with mode: 0644]

index d9a9c528f50f20f54dffda10532f0e222cbd02e5..dd075e65f297723f2d5c5efe9a7115d0d218e6a7 100644 (file)
@@ -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
index 8445734faf597416972386127cf6c9adc37069ad..9c93fd5f6b990c07a42708416eead783dd6a2c32 100644 (file)
@@ -1,3 +1,4 @@
 platform.h
 netdb.h
 gen
+/unit-test-driver.sh
index 0d658db2518d40d967c93d099390005f15e9bfe7..9f3ee80cce22131a88b101f6a2909400c544f8c5 100644 (file)
@@ -108,3 +108,5 @@ rsa_test_CPPFLAGS =         \
        $(OPENSSL_CFLAGS)
 
 unit-local: check
+
+LOG_COMPILER = $(builddir)/../../unit-test-driver.sh
index 0246f34cc798a317044a781865c9650e3072cd26..6b9bb583eb979dcbe4b843703c8539dd7b3d4dbc 100644 (file)
@@ -15,3 +15,5 @@ check_PROGRAMS = \
 TESTS = $(check_PROGRAMS)
 
 unit-local: check
+
+LOG_COMPILER = $(builddir)/../../unit-test-driver.sh
index c7ae206d78e3ce352e799e98a60901d59fb4399a..3723a392de4d5c9ec8557aeb2580e2fe93270187 100644 (file)
@@ -65,3 +65,5 @@ random_test_LDADD =   \
        -lm
 
 unit-local: check
+
+LOG_COMPILER = $(builddir)/../../unit-test-driver.sh
index a0b5abd3b82a2bbfc519bb9203320a6b81df96d8..048f2a9f0f65e9197dd4584ae0d97e971d222bcc 100644 (file)
@@ -15,3 +15,5 @@ check_PROGRAMS =      \
 TESTS = $(check_PROGRAMS)
 
 unit-local: check
+
+LOG_COMPILER = $(builddir)/../../unit-test-driver.sh
index 42242ad0705a0612f2165e36299270e4cb2c03c5..ce4ea0fd42f8d0dd261214ddc33d140c52ed7b45 100644 (file)
@@ -17,3 +17,5 @@ check_PROGRAMS = \
 TESTS = $(check_PROGRAMS)
 
 unit-local: check
+
+LOG_COMPILER = $(builddir)/../../unit-test-driver.sh
index c7ff73cd316ff2a1c8016adfd794d3bb453c9eee..415a21ee9633dcba851007b2f036512eed17fe72 100644 (file)
@@ -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 (file)
index 0000000..4fbd84b
--- /dev/null
@@ -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}