autotest/common: factor out xtrace disable/restore

Factor out `set -x` and +x to separate functions. Changing
xtraces is not so trivial and we'll be improving it later
on. We can't factor out the code as is due to local variables,
so we already simplify it a bit in this patch.

Change-Id: Iecbf5cedf821b7b1b71da933ceb158761881a843
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/453246
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-05-06 11:36:15 +02:00 committed by Jim Harris
parent 63d5459656
commit 3b660ea857

View File

@ -4,6 +4,17 @@ if $SPDK_AUTOTEST_X; then
set -x
fi
function xtrace_disable() {
PREV_BASH_OPTS="$-"
set +x
}
function xtrace_restore() {
if [[ "$PREV_BASH_OPTS" == *"x"* ]]; then
set -x
fi
}
set -e
# Export flag to skip the known bug that exists in librados
@ -209,17 +220,15 @@ function timing() {
}
function timing_enter() {
local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )"
set +x
xtrace_disable
timing "enter" "$1"
$shell_restore_x
xtrace_restore
}
function timing_exit() {
local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )"
set +x
xtrace_disable
timing "exit" "$1"
$shell_restore_x
xtrace_restore
}
function timing_finish() {
@ -309,8 +318,7 @@ function waitforlisten() {
echo "Waiting for process to start up and listen on UNIX domain socket $rpc_addr..."
# turn off trace for this loop
local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )"
set +x
xtrace_disable
local ret=0
local i
for (( i = 40; i != 0; i-- )); do
@ -350,7 +358,7 @@ function waitforlisten() {
sleep 0.5
done
$shell_restore_x
xtrace_restore
if (( i == 0 )); then
echo "ERROR: timeout while waiting for process (pid: $1) to start listening on '$rpc_addr'"
ret=1
@ -484,28 +492,26 @@ function kill_stub() {
}
function run_test() {
local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )"
set +x
xtrace_disable
local test_type="$(echo $1 | tr 'a-z' 'A-Z')"
shift
echo "************************************"
echo "START TEST $test_type $@"
echo "************************************"
$shell_restore_x
xtrace_restore
time "$@"
set +x
xtrace_disable
echo "************************************"
echo "END TEST $test_type $@"
echo "************************************"
$shell_restore_x
xtrace_restore
}
function print_backtrace() {
# if errexit is not enabled, don't print a backtrace
[[ "$-" =~ e ]] || return 0
local shell_options="$-"
set +x
xtrace_disable
echo "========== Backtrace start: =========="
echo ""
for i in $(seq 1 $((${#FUNCNAME[@]} - 1))); do
@ -520,7 +526,7 @@ function print_backtrace() {
done
echo ""
echo "========== Backtrace end =========="
[[ "$shell_options" =~ x ]] && set -x
xtrace_restore
return 0
}