autotest_common.sh: show backtrace when something fail

To aid debuging print file, line, function and code snipet of each stack
frame in script when error is generated.

Change-Id: Ib720b90049e7102a2e11755c6f10c016634efab9
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
This commit is contained in:
Pawel Wodkowski 2017-02-20 20:32:49 +01:00 committed by Jim Harris
parent 4044f8b62e
commit 1a11e63e1c

View File

@ -196,3 +196,26 @@ function run_test() {
echo "************************************"
set -x
}
function print_backtrace() {
set +x
echo "========== Backtrace start: =========="
echo ""
for i in $(seq 1 $((${#FUNCNAME[@]} - 1))); do
local func="${FUNCNAME[$i]}"
local line_nr="${BASH_LINENO[$((i - 1))]}"
local src="${BASH_SOURCE[$i]/#$rootdir/.}"
echo "in $src:$line_nr -> $func()"
echo " ..."
nl -w 4 -ba -nln $src | grep -B 5 -A 5 "^$line_nr" | \
sed "s/^/ /g" | sed "s/^ $line_nr/=> $line_nr/g"
echo " ..."
done
echo ""
echo "========== Backtrace end =========="
set -x
return 0
}
set -o errtrace
trap "trap - ERR; print_backtrace >&2" ERR