From f751ea172331d4c4d001e7a26adbfff2552f2e7b Mon Sep 17 00:00:00 2001 From: Pawel Wodkowski Date: Fri, 9 Nov 2018 15:05:23 +0100 Subject: [PATCH] autotest_common.sh: enable trace flag only if it was anabled before We are too verbose in many places. Some scripts don't want to be traced all the way, instad they enable tracing only for some parts and autotest_common.sh just do 'set -x' in many places. This patch save 'x' flag on function enter and restore it at exit. Change-Id: I39b3d3dd3f711e1131e476f9d322d9e1b097ad12 Signed-off-by: Pawel Wodkowski Reviewed-on: https://review.gerrithub.io/432604 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- test/common/autotest_common.sh | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index 1b6d7d7b3..fdfa37225 100644 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -222,15 +222,17 @@ function timing() { } function timing_enter() { + local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )" set +x timing "enter" "$1" - set -x + $shell_restore_x } function timing_exit() { + local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )" set +x timing "exit" "$1" - set -x + $shell_restore_x } function timing_finish() { @@ -304,17 +306,19 @@ function waitforlisten() { exit 1 fi - rpc_addr="${2:-$DEFAULT_RPC_ADDR}" + local rpc_addr="${2:-$DEFAULT_RPC_ADDR}" 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 - ret=1 - while [ $ret -ne 0 ]; do + local ret=0 + while true; do # if the process is no longer running, then exit the script # since it means the application crashed if ! kill -s 0 $1; then - exit 1 + ret=1 + break fi namespace=$(ip netns identify $1) @@ -324,16 +328,20 @@ function waitforlisten() { if hash ss; then if $ns_cmd ss -ln | egrep -q "\s+$rpc_addr\s+"; then - ret=0 + break fi else # if system doesn't have ss, just assume it has netstat if $ns_cmd netstat -an | grep -iw LISTENING | egrep -q "\s+$rpc_addr\$"; then - ret=0 + break fi fi done - set -x + + $shell_restore_x + if [ $ret -ne 0 ]; then + exit 1 + fi } function waitfornbd() { @@ -462,19 +470,20 @@ function kill_stub() { } function run_test() { + local shell_restore_x="$( [[ "$-" =~ x ]] && echo 'set -x' )" set +x local test_type="$(echo $1 | tr 'a-z' 'A-Z')" shift echo "************************************" echo "START TEST $test_type $@" echo "************************************" - set -x + $shell_restore_x time "$@" set +x echo "************************************" echo "END TEST $test_type $@" echo "************************************" - set -x + $shell_restore_x } function print_backtrace() {