Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit d9a9720

Browse files
committed
Factor out script to handle system test core dumps
Move the core dump detection functionality for system test runs into a separate script. This enables reuse by the pytest runner. The functionality remains the same.
1 parent 61330a7 commit d9a9720

File tree

2 files changed

+68
-46
lines changed

2 files changed

+68
-46
lines changed

bin/tests/system/get_core_dumps.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
dir=$(dirname "$0")
15+
. "$dir/conf.sh"
16+
17+
systest=$1
18+
status=0
19+
20+
export SYSTESTDIR="${TOP_SRCDIR}/bin/tests/system/${systest}"
21+
22+
get_core_dumps() {
23+
find "$SYSTESTDIR/" \( -name 'core' -or -name 'core.*' -or -name '*.core' \) ! -name '*.gz' ! -name '*.txt' | sort
24+
}
25+
26+
core_dumps=$(get_core_dumps | tr '\n' ' ')
27+
assertion_failures=$(find "$SYSTESTDIR/" -name named.run -exec grep "assertion failure" {} + | wc -l)
28+
sanitizer_summaries=$(find "$SYSTESTDIR/" -name 'tsan.*' | wc -l)
29+
if [ -n "$core_dumps" ]; then
30+
status=1
31+
echoinfo "I:$systest:Core dump(s) found: $core_dumps"
32+
get_core_dumps | while read -r coredump; do
33+
echoinfo "D:$systest:backtrace from $coredump:"
34+
echoinfo "D:$systest:--------------------------------------------------------------------------------"
35+
binary=$(gdb --batch --core="$coredump" 2>/dev/null | sed -ne "s|Core was generated by \`\([^' ]*\)[' ].*|\1|p")
36+
if [ ! -f "${binary}" ]; then
37+
binary=$(find "${TOP_BUILDDIR}" -path "*/.libs/${binary}" -type f)
38+
fi
39+
"${TOP_BUILDDIR}/libtool" --mode=execute gdb \
40+
-batch \
41+
-ex bt \
42+
-core="$coredump" \
43+
-- \
44+
"$binary" 2>/dev/null | sed -n '/^Core was generated by/,$p' | cat_d
45+
echoinfo "D:$systest:--------------------------------------------------------------------------------"
46+
coredump_backtrace="${coredump}-backtrace.txt"
47+
echoinfo "D:$systest:full backtrace from $coredump saved in $coredump_backtrace"
48+
"${TOP_BUILDDIR}/libtool" --mode=execute gdb \
49+
-batch \
50+
-command=run.gdb \
51+
-core="$coredump" \
52+
-- \
53+
"$binary" > "$coredump_backtrace" 2>&1
54+
echoinfo "D:$systest:core dump $coredump archived as $coredump.gz"
55+
gzip -1 "${coredump}"
56+
done
57+
elif [ "$assertion_failures" -ne 0 ]; then
58+
status=1
59+
echoinfo "I:$systest:$assertion_failures assertion failure(s) found"
60+
find "$SYSTESTDIR/" -name 'tsan.*' -exec grep "SUMMARY: " {} + | sort -u | cat_d
61+
elif [ "$sanitizer_summaries" -ne 0 ]; then
62+
status=1
63+
echoinfo "I:$systest:$sanitizer_summaries sanitizer report(s) found"
64+
fi
65+
66+
exit $status

bin/tests/system/run.sh.in

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ if [ "${srcdir}" != "${builddir}" ]; then
113113
cp -a "${srcdir}/common" "${builddir}"
114114
fi
115115
# Some tests require additional files to work for out-of-tree test runs.
116-
for file in ckdnsrps.sh conftest.py digcomp.pl ditch.pl fromhex.pl kasp.sh packet.pl pytest_custom_markers.py start.pl stop.pl testcrypto.sh; do
116+
for file in ckdnsrps.sh conftest.py digcomp.pl ditch.pl fromhex.pl get_core_dumps.sh kasp.sh packet.pl pytest_custom_markers.py start.pl stop.pl testcrypto.sh; do
117117
if [ ! -r "${file}" ]; then
118118
cp -a "${srcdir}/${file}" "${builddir}"
119119
fi
@@ -265,51 +265,7 @@ else
265265
exit $status
266266
fi
267267

268-
get_core_dumps() {
269-
find "$systest/" \( -name 'core' -or -name 'core.*' -or -name '*.core' \) ! -name '*.gz' ! -name '*.txt' | sort
270-
}
271-
272-
core_dumps=$(get_core_dumps | tr '\n' ' ')
273-
assertion_failures=$(find "$systest/" -name named.run -exec grep "assertion failure" {} + | wc -l)
274-
sanitizer_summaries=$(find "$systest/" -name 'tsan.*' | wc -l)
275-
if [ -n "$core_dumps" ]; then
276-
status=1
277-
echoinfo "I:$systest:Core dump(s) found: $core_dumps"
278-
get_core_dumps | while read -r coredump; do
279-
export SYSTESTDIR="$systest"
280-
echoinfo "D:$systest:backtrace from $coredump:"
281-
echoinfo "D:$systest:--------------------------------------------------------------------------------"
282-
binary=$(gdb --batch --core="$coredump" 2>/dev/null | sed -ne "s|Core was generated by \`\([^' ]*\)[' ].*|\1|p")
283-
if [ ! -f "${binary}" ]; then
284-
binary=$(find "${top_builddir}" -path "*/.libs/${binary}" -type f)
285-
fi
286-
"${top_builddir}/libtool" --mode=execute gdb \
287-
-batch \
288-
-ex bt \
289-
-core="$coredump" \
290-
-- \
291-
"$binary" 2>/dev/null | sed -n '/^Core was generated by/,$p' | cat_d
292-
echoinfo "D:$systest:--------------------------------------------------------------------------------"
293-
coredump_backtrace="${coredump}-backtrace.txt"
294-
echoinfo "D:$systest:full backtrace from $coredump saved in $coredump_backtrace"
295-
"${top_builddir}/libtool" --mode=execute gdb \
296-
-batch \
297-
-command=run.gdb \
298-
-core="$coredump" \
299-
-- \
300-
"$binary" > "$coredump_backtrace" 2>&1
301-
echoinfo "D:$systest:core dump $coredump archived as $coredump.gz"
302-
gzip -1 "${coredump}"
303-
done
304-
elif [ "$assertion_failures" -ne 0 ]; then
305-
status=1
306-
SYSTESTDIR="$systest"
307-
echoinfo "I:$systest:$assertion_failures assertion failure(s) found"
308-
find "$systest/" -name 'tsan.*' -exec grep "SUMMARY: " {} + | sort -u | cat_d
309-
elif [ "$sanitizer_summaries" -ne 0 ]; then
310-
status=1
311-
echoinfo "I:$systest:$sanitizer_summaries sanitizer report(s) found"
312-
fi
268+
$SHELL get_core_dumps.sh "$systest" || status=1
313269

314270
print_outstanding_files() {
315271
if test -d ${srcdir}/../../../.git; then

0 commit comments

Comments
 (0)