Commit 1baf379e authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

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: default avatarMichal Berger <michallinuxstuff@gmail.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/482694


Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
parent f54757cc
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -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 ""