test: make xtrace_disable multi-call safe.

Previously, if you made two sequential calls to xtrace_disable without
calling xtrace_enable, you would lose the original value of x. Now this
is not the case. It allows us to call xtrace_disable freely without
worrying about whether xtrace_disable is invoked later in a function we
call.

Change-Id: I9818ae97532e7a31db576bb9bd2e2e30d67ab410
Signed-off-by: Seth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/477965
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Seth Howell 2019-12-13 09:12:58 -07:00 committed by Tomasz Zawadzki
parent c4d4abcf64
commit 190b2245c5

View File

@ -1,6 +1,11 @@
function xtrace_disable() {
PREV_BASH_OPTS="$-"
set +x
if [ "$XTRACE_DISABLED" != "yes" ]; then
PREV_BASH_OPTS="$-"
if [[ "$PREV_BASH_OPTS" == *"x"* ]]; then
XTRACE_DISABLED="yes"
fi
set +x
fi
}
xtrace_disable
@ -18,7 +23,7 @@ function xtrace_enable() {
# 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'
alias xtrace_restore='if [[ "$PREV_BASH_OPTS" == *"x"* ]]; then set -x; XTRACE_DISABLED="no"; PREV_BASH_OPTS=""; xtrace_enable; fi'
: ${RUN_NIGHTLY:=0}
export RUN_NIGHTLY