summaryrefslogtreecommitdiff
path: root/test/integration
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2021-04-25 22:26:42 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2021-08-28 21:11:33 +0200
commit255ec5a46aa55ad96e7dc7f9d43d5cdf71627812 (patch)
treea582d854eeaa77907fe94baa0669bd7646cc1892 /test/integration
parentf3885ecec2d8ef1a35495d6c6b979d25d3da6d5c (diff)
Try to show core dump info in test framework
If the system tells us that a core dump was created we should try to display the contained info as that system might not be easily available when we see the error (like C-I or autopkgtest). Gbp-Dch: Ignore
Diffstat (limited to 'test/integration')
-rw-r--r--test/integration/framework63
1 files changed, 61 insertions, 2 deletions
diff --git a/test/integration/framework b/test/integration/framework
index 8c9abfbe4..1f942d162 100644
--- a/test/integration/framework
+++ b/test/integration/framework
@@ -307,6 +307,13 @@ find_project_binary_dir() {
export PROJECT_BINARY_DIR
fi
}
+_removetmpworkingdirectory() {
+ cd /
+ if [ -n "$TMPWORKINGDIRECTORY" -a -d "$TMPWORKINGDIRECTORY" ]; then
+ rm -rf "$TMPWORKINGDIRECTORY"
+ fi
+ TMPWORKINGDIRECTORY=''
+}
setupenvironment() {
# Next check needs a gnu stat, let's figure that out early.
stat=stat
@@ -317,8 +324,10 @@ setupenvironment() {
if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$($stat --format '%a' "$TMPDIR")" != '1777' ]; then
unset TMPDIR
fi
- TMPWORKINGDIRECTORY="$(mktemp -d)"
- addtrap "cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';"
+ if [ -z "$TMPWORKINGDIRECTORY" ]; then
+ addtrap '_removetmpworkingdirectory;'
+ TMPWORKINGDIRECTORY="$(mktemp -d)"
+ fi
if [ -n "$TMPDIR_ADD" ]; then
TMPWORKINGDIRECTORY="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}"
mkdir -p "$TMPWORKINGDIRECTORY"
@@ -361,6 +370,7 @@ setupenvironment() {
APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/solvers/apt"}"
APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/solvers/dump"}"
APTINTERNALPLANNER="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/planners/apt"}"
+ ARTIFACTSDIR="${APT_INTEGRATION_TESTS_ARTIFACTS_DIR:-"${BUILDDIRECTORY}/artifacts"}"
test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
# -----
@@ -1778,6 +1788,52 @@ msgfailoutput() {
ls -l
fi
catfile "$OUTPUT"
+ if [ "$CMD" != 'echo' ] && tail -n 1 "$OUTPUT" | grep -q '(core dumped)$'; then
+ local COREDUMP="${TMPWORKINGDIRECTORY}/rootdir/tmp/core.dump"
+ local COREEXE=''
+ for CORENAME in 'core' 'core.pid'; do
+ if [ -s "$CORENAME" ]; then
+ cp -a ${CORENAME} "$COREDUMP"
+ elif [ -s "${TMPWORKINGDIRECTORY}/${CORENAME}" ]; then
+ cp -a "${TMPWORKINGDIRECTORY}/${CORENAME}" "$COREDUMP"
+ else
+ continue
+ fi
+ break
+ done
+ if [ -s "$COREDUMP" ]; then
+ true # found already as a file
+ elif dpkg-checkbuilddeps -d 'systemd-coredump' /dev/null >/dev/null 2>&1; then
+ COREEXE="$(coredumpctl -1 --no-legend list | sed -e 's#^.* \([^ ]\+\)$#\1#')"
+ coredumpctl -1 dump "$COREEXE" -o "$COREDUMP" 2>/dev/null >&2 || true
+ else
+ echo '### core dump not found ###'
+ cat /proc/sys/kernel/core_pattern
+ fi
+ if [ -s "$COREDUMP" ]; then
+ if [ -z "$COREEXE" ]; then
+ case "$CMD" in
+ apt) COREEXE="${BUILDDIRECTORY}/${CMD}";;
+ aptftparchive) COREEXE="${APTFTPARCHIVEBINDIR}/apt-ftparchive";;
+ apthelper) COREEXE="${APTHELPERBINDIR}/apt-helper";;
+ aptwebserver) COREEXE="${APTTESTHELPERSBINDIR}/aptwebserver";;
+ apt*) COREEXE="${BUILDDIRECTORY}/apt-${CMD##*apt}";;
+ *) COREEXE="${BUILDDIRECTORY}/${CMD}";;
+ esac
+ fi
+
+ if [ -d "${ARTIFACTSDIR}" ]; then
+ local ARTIFACT_COREDUMP="$(mktemp --suffix=.coredump -p "${ARTIFACTSDIR}" "${COREEXE##*/}-XXXXXX")"
+ cp -a "$COREDUMP" "$ARTIFACT_COREDUMP"
+ echo "#### coredump in $ARTIFACT_COREDUMP for $COREEXE ####"
+ fi
+ if [ -n "$COREEXE" -a -s "$COREEXE" ] && dpkg-checkbuilddeps -d 'gdb' /dev/null >/dev/null 2>&1; then
+ echo "#### gdb backtrace ####"
+ command gdb --batch -n -ex 'set pagination off' --ex 'thread apply all bt full' "$COREEXE" "$COREDUMP" || true
+ fi
+ fi
+ rm -f "$COREDUMP"
+ fi
msgfail "$MSG"
}
@@ -1801,6 +1857,9 @@ testsuccesswithglobalerror() {
if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
| cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev/null 2>&1; then
msgpass
+ elif echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (13: Permission denied)' \
+ | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev/null 2>&1; then
+ msgpass
else
msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
fi