summaryrefslogtreecommitdiffstats
path: root/unit
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 07:24:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 07:24:22 +0000
commit45d6379135504814ab723b57f0eb8be23393a51d (patch)
treed4f2ec4acca824a8446387a758b0ce4238a4dffa /unit
parentInitial commit. (diff)
downloadbind9-45d6379135504814ab723b57f0eb8be23393a51d.tar.xz
bind9-45d6379135504814ab723b57f0eb8be23393a51d.zip
Adding upstream version 1:9.16.44.upstream/1%9.16.44
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'unit')
-rw-r--r--unit/README8
-rwxr-xr-xunit/gdb33
-rwxr-xr-xunit/unittest.sh.in96
3 files changed, 137 insertions, 0 deletions
diff --git a/unit/README b/unit/README
new file mode 100644
index 0000000..9cdcf9b
--- /dev/null
+++ b/unit/README
@@ -0,0 +1,8 @@
+Unit tests for BIND 9 are based on the CMocka testing framework and
+the Kyua test execution engine.
+
+If your distribution of choice doesn't include packages for kyua or cmocka, the
+sources can be found here:
+
+ * Kyua 0.13 - https://github.com/jmmv/kyua/releases
+ * CMocka 1.0 - https://cmocka.org/files/
diff --git a/unit/gdb b/unit/gdb
new file mode 100755
index 0000000..0eedd63
--- /dev/null
+++ b/unit/gdb
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+# `kyua debug` command does not work with libtool (see
+# https://github.com/jmmv/kyua/issues/207). On some distributions `kyua debug`
+# runs the first `gdb` it finds in $PATH, but on Debian and Ubuntu it looks for
+# `/usr/bin/gdb`. This script expects `gdb` to be moved to `gdb.orig` and
+# executed from there.
+coredump="$6"
+binary=$(gdb.orig --batch --core="${coredump}" 2>/dev/null | sed -ne "s/Core was generated by \`\(.*\)'./\1/p")
+# GDB 6.3 from OpenBSD 6.6 does not tell the full path of the broken binary.
+# We need to fix it. Either the binary or it's libtool script will do.
+if [ ! -e "${binary}" ]; then
+ binary="$(find "${TOP}" -name "${binary}" | head -n 1)"
+fi
+
+# $TOP points to BIND sources and should be set on `kyua debug` invocation.
+"${TOP}/libtool" --mode=execute gdb.orig \
+ --batch \
+ --command="${TOP}/bin/tests/system/run.gdb" \
+ --core="${coredump}" \
+ -- \
+ "${binary}"
diff --git a/unit/unittest.sh.in b/unit/unittest.sh.in
new file mode 100755
index 0000000..b707e70
--- /dev/null
+++ b/unit/unittest.sh.in
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+# Find the top of the BIND9 tree.
+export TOP=@abs_top_builddir@
+KYUA=@KYUA@
+CMOCKA_MESSAGE_OUTPUT=TAP
+export CMOCKA_MESSAGE_OUTPUT
+GDB="$(command -v gdb)"
+
+kyua_report() {
+ ${KYUA} --logfile /dev/null report --results-file "${KYUA_RESULT:-LATEST}"
+}
+
+clear_kyua_work_dir() {
+ KYUA_WORK_DIR="$(grep -i -m1 "failed" "${1}" | sed -n 's|.*\(/tmp/kyua\.[A-Za-z0-9]*\).*|\1|p')"
+ if [ -n "${CI}" ] && [ -d "${KYUA_WORK_DIR}" ]; then
+ find "${KYUA_WORK_DIR}" \( -name 'core*' -o -name '*.core' \) -exec mv -v {} . \;
+ rm -rf "${KYUA_WORK_DIR}"
+ fi
+}
+
+if [ -z "${KYUA}" ]; then
+ exit 0
+fi
+
+echo "S:unit:$(date)"
+echo "T:unit:1:A"
+echo "I:unit tests (using kyua)"
+
+${KYUA} -v parallelism="${TEST_PARALLEL_JOBS:-1}" --logfile kyua.log --loglevel debug test --results-file "${KYUA_RESULT:-NEW}"
+status=$?
+
+kyua_report
+
+clear_kyua_work_dir kyua.log
+
+# Use kyua-debug(1) facility to gather additional data on failed tests.
+# Some runs will just show verbose information from the run, some will
+# show backtrace via gdb(1).
+USER_ID=$(id -u)
+BROKEN_TESTS=$(kyua_report | awk '$2 == "->" && ( $3 == "broken:" || $3 == "failed:" ) { print $1 }')
+# Conditions for getting kyua debug info and GDB backtrace: runs under CI
+# (safety), GDB present, root privileges, failed tests.
+if [ -n "${CI}" ] && [ -n "${GDB}" ] && [ "${USER_ID:-1}" -eq 0 ] && [ -n "${BROKEN_TESTS}" ]; then
+ if [ "$(uname -s)" = "Linux" ] && ! sysctl -n "kernel.core_pattern" | grep -xq "core.%p"; then
+ echo "I:*** kernel.core_pattern is not set to 'core.%p'"
+ echo "I:*** kyua may not be able to find core dumps for broken tests"
+ fi
+ if [ "$(uname -s)" = "FreeBSD" ] && ! sysctl -n "kern.corefile" | grep -xq "core.%P"; then
+ echo "I:*** kern.corefile is not set to 'core.%P'"
+ echo "I:*** kyua may not be able to find core dumps for broken tests"
+ fi
+ if grep '^#define USE_LIBTOOL 1$' "${TOP}/config.h" >/dev/null; then
+ # kyua debug command misidentifies broken binaries when libtool
+ # is used (see https://github.com/jmmv/kyua/issues/207).
+ # Here we try to "trick" kyua to use our custom gdb script instead
+ # of using gdb(1) directly. Hence this part needs to be run as root
+ # and, for safety reasons, only in the CI.
+ mv "${GDB}" "${GDB}.orig"
+ cp "${TOP}/unit/gdb" "${GDB}"
+ fi
+ i=1
+ for test in ${BROKEN_TESTS}; do
+ echo
+ echo "----- $test -----"
+ KYUA_DEBUG_LOG="kyua.debug.log.${i}"
+ ${KYUA} debug "${test}" 2>&1 | tee "${KYUA_DEBUG_LOG}"
+ clear_kyua_work_dir "${KYUA_DEBUG_LOG}"
+ i=$((i + 1))
+ done
+ if grep '^#define USE_LIBTOOL 1$' "${TOP}/config.h" >/dev/null; then
+ mv "${GDB}.orig" "${GDB}"
+ fi
+fi
+
+if [ "${status}" -eq 0 ]
+then
+ rm -f kyua.log
+ echo "R:PASS"
+else
+ echo "R:FAIL:status:${status}"
+fi
+echo "E:unit:$(date)"
+
+exit ${status}