From 229de6b71d0b90de1ce95c9c692a132b3cf056b1 Mon Sep 17 00:00:00 2001 From: David Zafman Date: Fri, 4 Aug 2017 12:34:47 -0700 Subject: [PATCH] qa: Add support for core dumps Save core dumps when running tests locally Dump logs to output whenever cores seen Signed-off-by: David Zafman --- qa/run-standalone.sh | 9 ++++++++ qa/standalone/ceph-helpers.sh | 30 ++++++++++++++++++++++++++- qa/standalone/special/test-failure.sh | 13 ++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/qa/run-standalone.sh b/qa/run-standalone.sh index a30200993b4f2..45f69434f9d83 100755 --- a/qa/run-standalone.sh +++ b/qa/run-standalone.sh @@ -15,9 +15,13 @@ if [ `uname` = FreeBSD ]; then # otherwise module prettytable will not be found export PYTHONPATH=/usr/local/lib/python2.7/site-packages exec_mode=+111 + KERNCORE="kern.corefile" + COREPATTERN="core.%N.%P" else export PYTHONPATH=/usr/lib/python2.7/dist-packages exec_mode=/111 + KERNCORE="kernel.core_pattern" + COREPATTERN="core.%e.%p.%t" fi PATH=$(pwd)/bin:$PATH @@ -41,6 +45,9 @@ location="../qa/standalone" count=0 errors=0 userargs="" +precore="$(sysctl -n $KERNCORE)" +sudo sysctl -w ${KERNCORE}=${COREPATTERN} +ulimit -c unlimited for f in $(cd $location ; find . -perm $exec_mode -type f) do f=$(echo $f | sed 's/\.\///') @@ -82,12 +89,14 @@ do if ! PATH=$PATH:bin \ CEPH_ROOT=.. \ CEPH_LIB=lib \ + LOCALRUN=yes \ $cmd ; then echo "$f .............. FAILED" errors=$(expr $errors + 1) fi fi done +sudo sysctl -w ${KERNCORE}=${precore} if [ "$errors" != "0" ]; then echo "$errors TESTS FAILED, $count TOTAL TESTS" diff --git a/qa/standalone/ceph-helpers.sh b/qa/standalone/ceph-helpers.sh index 58d6211d1336d..5325ec7c2961e 100755 --- a/qa/standalone/ceph-helpers.sh +++ b/qa/standalone/ceph-helpers.sh @@ -33,6 +33,7 @@ fi if [ `uname` = FreeBSD ]; then SED=gsed DIFFCOLOPTS="" + KERNCORE="kern.corefile" else SED=sed termwidth=$(stty -a | head -1 | sed -e 's/.*columns \([0-9]*\).*/\1/') @@ -40,6 +41,7 @@ else termwidth="-W ${termwidth}" fi DIFFCOLOPTS="-y $termwidth" + KERNCORE="kernel.core_pattern" fi EXTRA_OPTS="" @@ -158,11 +160,37 @@ function teardown() { && [ $(stat -f -c '%T' .) == "btrfs" ]; then __teardown_btrfs $dir fi - if [ "$dumplogs" = "1" ]; then + local cores="no" + local pattern="$(sysctl -n $KERNCORE)" + # See if we have apport core handling + if [ "${pattern:0:1}" = "|" ]; then + # TODO: Where can we get the dumps? + # Not sure where the dumps really are so this will look in the CWD + pattern="" + fi + # Local we start with core and teuthology ends with core + if ls $(dirname $pattern) | grep -q '^core\|core$' ; then + cores="yes" + if [ -n "$LOCALRUN" ]; then + mkdir /tmp/cores.$$ 2> /dev/null || true + for i in $(ls $(dirname $(sysctl -n $KERNCORE)) | grep '^core\|core$'); do + mv $i /tmp/cores.$$ + done + fi + fi + if [ "$cores" = "yes" -o "$dumplogs" = "1" ]; then display_logs $dir fi rm -fr $dir rm -rf $(get_asok_dir) + if [ "$cores" = "yes" ]; then + echo "ERROR: Failure due to cores found" + if [ -n "$LOCALRUN" ]; then + echo "Find saved core files in /tmp/cores.$$" + fi + return 1 + fi + return 0 } function __teardown_btrfs() { diff --git a/qa/standalone/special/test-failure.sh b/qa/standalone/special/test-failure.sh index d110d94921031..cede887d2823d 100755 --- a/qa/standalone/special/test-failure.sh +++ b/qa/standalone/special/test-failure.sh @@ -7,6 +7,11 @@ function run() { local dir=$1 shift + export CEPH_MON="127.0.0.1:7202" # git grep '\<7202\>' : there must be only one + export CEPH_ARGS + CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none " + CEPH_ARGS+="--mon-host=$CEPH_MON " + local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')} for func in $funcs ; do setup $dir || return 1 @@ -32,4 +37,12 @@ EOF return 1 } +function TEST_failure_core_only() { + local dir=$1 + + run_mon $dir a || return 1 + kill_daemons $dir SEGV mon 5 + return 0 +} + main test_failure "$@" -- 2.39.5