From 1baf379e697af87dcceee5d06b0fc38aefe7a7dd Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Fri, 24 Jan 2020 15:35:55 +0100 Subject: [PATCH] test/common: Don't attempt to read backtrace from unavailable source In case cwd is changed during the execution of given BASH_SOURCE, i.e., when the dirstack is mangled by calls to cd, the actual executable may end up missing from the path when run directly from its directory in the ./ fashion. Example: [root@fedora31 fuzz]# ./autofuzz.sh --module=vhost --transport=all autofuzz.sh cds into the $rootdir hence the BASH_SOURCE[i] in form of ./autofuzz.sh won't be found there, thus during a failure, since run under a debug tracer, nl will fail with -ENOENT while trying to read it. To mitigate, check if $src is available for reading, if not, log that the backtrace is not available. Change-Id: I68988350ba36cca8464bdfac437f662ed4c30f67 Signed-off-by: Michal Berger Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/482694 Community-CI: Broadcom SPDK FC-NVMe CI Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker Reviewed-by: Karol Latecki --- test/common/autotest_common.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index af62c0326..39abbb815 100644 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -651,10 +651,16 @@ function print_backtrace() { local func="${FUNCNAME[$i]}" local line_nr="${BASH_LINENO[$((i - 1))]}" local src="${BASH_SOURCE[$i]}" + local bt="" + + if [[ -f $src ]]; then + bt=$(nl -w 4 -ba -nln $src | grep -B 5 -A 5 "^${line_nr}[^0-9]" | \ + sed "s/^/ /g" | sed "s/^ $line_nr /=> $line_nr /g") + fi + echo "in $src:$line_nr -> $func()" echo " ..." - nl -w 4 -ba -nln $src | grep -B 5 -A 5 "^${line_nr}[^0-9]" | \ - sed "s/^/ /g" | sed "s/^ $line_nr /=> $line_nr /g" + echo "${bt:-backtrace unavailable}" echo " ..." done echo ""