From fadcb08db35c44074049dfa345997c02d16f3cfd Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Mon, 13 May 2019 16:09:51 +0200 Subject: [PATCH] autotest/common: define xtrace_restore as an alias This doesn't make difference right now, but would be useful if we printed $BASH_SOURCE or $LINENO in xtrace (via PS4). Those two will now point to the original line where xtrace_restore was called rather than always the single line inside autotest_common.sh. Change-Id: Idf3ac8d00ad9610960678351014334013149b88d Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/456964 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- test/common/autotest_common.sh | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index 263024b78..7f5a09569 100644 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -3,6 +3,10 @@ function xtrace_disable() { set +x } +xtrace_disable +set -e +shopt -s expand_aliases + # Dummy function to be called after restoring xtrace just so that it appears in the # xtrace log. This way we can consistently track when xtrace is enabled/disabled. function xtrace_enable() { @@ -11,17 +15,10 @@ function xtrace_enable() { function xtrace_dummy() { :; } } -function xtrace_restore() { - if [[ "$PREV_BASH_OPTS" != *"x"* ]]; then - return - fi - - set -x - xtrace_enable -} - -xtrace_disable -set -e +# Keep it as alias to avoid xtrace_enable backtrace always pointing to xtrace_restore. +# xtrace_enable will appear as called directly from the user script, from the same line +# that "called" xtrace_restore. +alias xtrace_restore='if [[ "$PREV_BASH_OPTS" == *"x"* ]]; then set -x; xtrace_enable; fi' : ${RUN_NIGHTLY:=0} export RUN_NIGHTLY