summaryrefslogtreecommitdiffstats
path: root/tests/unit-test-driver.sh.in
blob: 9a60db1337bec32fc5cd31890672be8311eb4326 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/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.

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}"
TIMEOUT=300

"${TEST_PROGRAM}" &
TEST_PROGRAM_PID=${!}
STATUS=124
while [ ${TIMEOUT} -gt 0 ]; do
	if ! kill -0 "${TEST_PROGRAM_PID}" 2>/dev/null; then
		wait "${TEST_PROGRAM_PID}"
		STATUS=${?}
		break
	fi
	sleep 1
	TIMEOUT=$((TIMEOUT - 1))
done
if [ ${TIMEOUT} -eq 0 ]; then
	echo "PID ${TEST_PROGRAM_PID} exceeded run time limit, sending SIGABRT" >&2
	kill -ABRT "${TEST_PROGRAM_PID}" 2>/dev/null
fi

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}