From 8d2247e2c4afd3e42d9a5b23728b4cfff8c75f9f Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Mon, 6 May 2019 12:03:53 +0200 Subject: [PATCH] autotest/common: produce xtrace output on xtrace_restore This way we can consistently track when xtrace in our scripts is enabled or disabled. > [...] > xtrace_disable > PREV_BASH_OPTS=ehxBE > set +x > xtrace_enable > [...] Change-Id: I2e813dc2a237a4620ea72d26a22a3c8cbeb269f9 Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/453248 Tested-by: SPDK CI Jenkins Reviewed-by: Karol Latecki Reviewed-by: Jim Harris --- test/common/autotest_common.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index 6b1713ea6..4d130925b 100644 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -9,10 +9,21 @@ function xtrace_disable() { set +x } +# 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() { + # We have to do something inside a function in bash, and calling any command + # (even `:`) will produce an xtrace entry, so we just define another function. + function xtrace_dummy() { :; } +} + function xtrace_restore() { - if [[ "$PREV_BASH_OPTS" == *"x"* ]]; then - set -x + if [[ "$PREV_BASH_OPTS" != *"x"* ]]; then + return fi + + set -x + xtrace_enable } set -e