From 190b2245c5ed9ec3483a4b0e87629419e88d4e62 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Fri, 13 Dec 2019 09:12:58 -0700 Subject: [PATCH] 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 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/477965 Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Karol Latecki Tested-by: SPDK CI Jenkins Community-CI: SPDK CI Jenkins --- test/common/autotest_common.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index f790a9c8f..fe81c8775 100644 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -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