osmith has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38503?usp=email )
Change subject: testenv: qemu: get coredump and show backtrace
......................................................................
testenv: qemu: get coredump and show backtrace
Related: OS#6600
Change-Id: Ia08ac58c43388b5ea4d3712c5ef83f54b538b10a
---
M _testenv/data/scripts/qemu/qemu_functions.sh
M _testenv/data/scripts/qemu/qemu_init.sh
2 files changed, 21 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/03/38503/1
diff --git a/_testenv/data/scripts/qemu/qemu_functions.sh
b/_testenv/data/scripts/qemu/qemu_functions.sh
index c0dd8cc..e2014a1 100755
--- a/_testenv/data/scripts/qemu/qemu_functions.sh
+++ b/_testenv/data/scripts/qemu/qemu_functions.sh
@@ -1,5 +1,6 @@
#!/bin/sh -ex
INITRD_DIR="$PWD/_initrd"
+CORE_DIR="$PWD/_coredump"
# Add one or more files to the initramfs, with parent directories.
# usr-merge: resolve symlinks for /lib -> /usr/lib etc. so "cp --parents"
does
@@ -171,6 +172,8 @@
machine_arg="-machine pc"
fi
+ mkdir -p "$CORE_DIR"
+
# sudo is required to set up networking in qemu_ifup.sh
# </dev/null to deatch stdin, so qemu doesn't capture ^C
sudo sh -c "
@@ -186,6 +189,13 @@
-serial stdio \
-netdev 'tap,id=nettest,script=$TESTENV_QEMU_SCRIPTS/qemu_ifup.sh' \
-device 'virtio-net-pci,netdev=nettest,mac=$(qemu_random_mac)' \
+ -virtfs
'local,path=$CORE_DIR,mount_tag=coredir,security_model=passthrough,fmode=666,writeout=immediate'
\
</dev/null
"
+
+ # Show coredump backtrace
+ if [ -e "$CORE_DIR/coredump" ]; then
+ execfn="$(file "$CORE_DIR/coredump" | grep -o "execfn:
'.*'" | cut -d "'" -f 2)"
+ gdb --batch "$execfn" "$CORE_DIR/coredump" -ex bt
+ fi
}
diff --git a/_testenv/data/scripts/qemu/qemu_init.sh
b/_testenv/data/scripts/qemu/qemu_init.sh
index 1c8b39b..1c100f8 100755
--- a/_testenv/data/scripts/qemu/qemu_init.sh
+++ b/_testenv/data/scripts/qemu/qemu_init.sh
@@ -1,6 +1,7 @@
#!/bin/busybox sh
echo "Running initrd-init.sh"
set -ex
+COREDUMP=/tmp/coredump
export HOME=/root
export LD_LIBRARY_PATH=/usr/local/lib
@@ -27,10 +28,20 @@
ip link set lo up
ip link set eth0 up
+sysctl -w kernel.core_pattern="$COREDUMP"
+ulimit -c unlimited
+
echo "KERNEL_TEST_VM_IS_READY"
# Use '|| true' to avoid "attempting to kill init" kernel panic on
failure
/cmd.sh || true
+if [ -e "$COREDUMP" ]; then
+ mkdir -p /mnt/coredir
+ mount -t 9p -o trans=virtio coredir /mnt/coredir -oversion=9p2000.L
+ chmod 666 "$COREDUMP"
+ cp "$COREDUMP" /mnt/coredir
+fi
+
# Avoid kernel panic when init exits
poweroff -f
--
To view, visit
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38503?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Ia08ac58c43388b5ea4d3712c5ef83f54b538b10a
Gerrit-Change-Number: 38503
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith(a)sysmocom.de>