Commit b24df7cf authored by Michal Berger's avatar Michal Berger Committed by Jim Harris
Browse files

test: Drop superfluous calls to print_backtrace()



Since we use errtrace, the ERR trap is inherited and preserved in
each subshell, cmd substitution, etc. that we execute along the
way. This means that each failure inside such subshell triggers
call to print_backtrace(). Depending on the context, this may not
be desired. Consider simple example:

  # foo() { return 1; }
  # [[ $(foo) == no_output_so_fail_me ]]

This assumes that from the test perspective we don't care if foo(),
internally, fails, we just look for a specific string it should
return. If it doesn't, errexit will be triggered at the [[ level
and fail the test. This is fine, but before this happens, extra
print_backtrace() call will be made from the $() context.

Changing logic above and we may start spamming these calls:

 # foo() { return 1; }
 # [[ $(foo) -eq 0 ]]

Here failure still triggers the print_backtrace() but logically
the [[ test succeeds so we end up with a useless call in the log
which may be downright confusing.

Cherry on top is the fact that we don't inherit errexit inside
the subshell. So this print_backtrace() call is entirely foobar
as it won't do anything at all.

Best case would be to enable inherit_errexit from autotest_common.sh
across all the test suites. This, however, will require proper
discipline in maintaining the tests as use of subshell environment
would have to be more explicit - in other words the ambiguity from
the first example (i.e. failure != no output) would not be allowed.

For now, refactor code a bit to get rid of these extra calls, next
step would be to test behavior of inherit_errexit.

Change-Id: Ice3f072008162c1713e78a6da99a833919bc716c
Signed-off-by: default avatarMichal Berger <michal.berger@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/23078


Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 7b52e4c1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ cuse_out[2]=$(nvme spdk list -v -o json)
cuse_out[3]=$(nvme spdk list-subsys)

# plugin does not support json output for the list-subsys
[[ $(nvme spdk list-subsys -v -o json 2>&1) == "Json output format is not supported." ]]
[[ $(nvme spdk list-subsys -v -o json 2>&1 || true) == "Json output format is not supported." ]]

diff -ub \
	<(printf '%s\n' "${kernel_out[@]}") \
+2 −1
Original line number Diff line number Diff line
@@ -10,7 +10,8 @@ source "$rootdir/test/nvme/cuse/common.sh"
"$rootdir/scripts/setup.sh" reset

scan_nvme_ctrls
ctrl=$(get_ctrl_with_feature fdp) bdf=${bdfs["$ctrl"]}
ctrl=$(get_ctrl_with_feature fdp) || exit 1
bdf=${bdfs["$ctrl"]}

"$rootdir/scripts/setup.sh"

+1 −9
Original line number Diff line number Diff line
@@ -29,16 +29,8 @@ function disconnect_init() {
# Test to make sure we don't segfault or access null pointers when we try to connect to
# a discovery controller that doesn't exist yet.
function nvmf_target_disconnect_tc1() {
	set +e
	$SPDK_EXAMPLE_DIR/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \
	NOT "$SPDK_EXAMPLE_DIR/reconnect" -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \
		-r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT"
	# If the program crashes, the high bit of $? will be set so we will get a value in the hundreds.
	# But if the reconnect code detects errors and exits normally it will return 1.
	if [ $? != 1 ]; then
		set -e
		exit 1
	fi
	set -e
}

function nvmf_target_disconnect_tc2() {
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ waitforlisten $spdk_pid

# Check that ocfWT was not loaded on app start

[[ -z $("$rpc_py" bdev_ocf_get_bdevs | jq -r '.[] | select(name == "ocfWT") | .name') ]]
(($("$rpc_py" bdev_ocf_get_bdevs | jq 'length') == 0))

trap - SIGINT SIGTERM EXIT

+3 −3
Original line number Diff line number Diff line
@@ -688,9 +688,9 @@ cpu_usage_clk_tck() {

	# Construct delta based on last two samples of a given time.
	case "$time" in
		user | all) ((clk_delta += (user[-1] - user[-2]))) ;;&
		nice | all) ((clk_delta += (nice[-1] - nice[-2]))) ;;&
		system | all) ((clk_delta += (system[-1] - system[-2]))) ;;
		user | all) : $((clk_delta += (user[-1] - user[-2]))) ;;&
		nice | all) : $((clk_delta += (nice[-1] - nice[-2]))) ;;&
		system | all) : $((clk_delta += (system[-1] - system[-2]))) ;;
		*) ;;
	esac
	# We assume 1s between each sample. See get_cpu_time().
Loading