Debian Codegraph @

tests/unit-test-driver.sh.in

raw
1 #!/bin/sh
2 #
3 # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4 #
5 # SPDX-License-Identifier: MPL-2.0
6 #
7 # This Source Code Form is subject to the terms of the Mozilla Public
8 # License, v. 2.0. If a copy of the MPL was not distributed with this
9 # file, you can obtain one at https://mozilla.org/MPL/2.0/.
10 #
11 # See the COPYRIGHT file distributed with this work for additional
12 # information regarding copyright ownership.
13
14 TOP_BUILDDIR=@abs_top_builddir@
15 TOP_SRCDIR=@abs_top_srcdir@
16
17 if [ -z "${1}" ]; then
18 echo "Usage: ${0} test_program" >&2
19 exit 1
20 fi
21
22 TEST_PROGRAM="${1}"
23 TIMEOUT=300
24
25 "${TEST_PROGRAM}" &
26 TEST_PROGRAM_PID=${!}
27 STATUS=124
28 while [ ${TIMEOUT} -gt 0 ]; do
29 if ! kill -0 "${TEST_PROGRAM_PID}" 2>/dev/null; then
30 wait "${TEST_PROGRAM_PID}"
31 STATUS=${?}
32 break
33 fi
34 sleep 1
35 TIMEOUT=$((TIMEOUT - 1))
36 done
37 if [ ${TIMEOUT} -eq 0 ]; then
38 echo "PID ${TEST_PROGRAM_PID} exceeded run time limit, sending SIGABRT" >&2
39 kill -ABRT "${TEST_PROGRAM_PID}" 2>/dev/null
40 fi
41
42 TEST_PROGRAM_NAME=$(basename "${TEST_PROGRAM}")
43 TEST_PROGRAM_WORK_DIR=$(dirname "${TEST_PROGRAM}")
44 find "${TEST_PROGRAM_WORK_DIR}" -name 'core*' -or -name '*.core' | while read -r CORE_DUMP; do
45 BINARY=$(gdb --batch --core="${CORE_DUMP}" 2>/dev/null | sed -n "s/^Core was generated by \`\(.*\)'\.\$/\1/p")
46 if ! echo "${BINARY}" | grep -q "${TEST_PROGRAM_NAME}\$"; then
47 continue
48 fi
49 echo "I:${TEST_PROGRAM_NAME}:Core dump found: ${CORE_DUMP}"
50 echo "D:${TEST_PROGRAM_NAME}:backtrace from ${CORE_DUMP} start"
51 "${TOP_BUILDDIR}/libtool" --mode=execute gdb \
52 --batch \
53 --command="${TOP_SRCDIR}/bin/tests/system/run.gdb" \
54 --core="${CORE_DUMP}" \
55 -- \
56 "${BINARY}"
57 echo "D:${TEST_PROGRAM_NAME}:backtrace from ${CORE_DUMP} end"
58 done
59
60 exit ${STATUS}