Commit a9337f72 authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

test/common: Check exit status of NOT() execution more carefully



The NOT() function is meant to report a success when given test
fails. This negative testing is meant for specific cases, however,
there may be some circumstances where application failed, but not
for the reasons the tests was aiming for, e.g. upon receiving
signals from the kernel, like SIGILL, SIGSEGV, etc.

To make sure the test is aborted in such a scenario, check exit
status of the execution more carefully. If it matches any of the
defined signals make sure to fail the test. By default, all signals
which generate cores are looked up and SIGKILL which may be sent
out by the kernel as well (in case of the oom-killer).

Also, $EXIT_STATUS var is provided to specifically declare which
exit status NOT() should be looking for if process terminates with
a failure (i.e., for any other reason then receiving a signal).

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 20708f35
Loading
Loading
Loading
Loading
+27 −4
Original line number Diff line number Diff line
@@ -496,11 +496,34 @@ function rpc_cmd_simple_data_json() {
	((${#jq_out[@]} > 0)) || return 1
}

# invert error code of any command and also trigger ERR on 0 (unlike bash ! prefix)
function NOT() {
	if "$@"; then
		return 1
	local es=0

	"$@" || es=$?

	# Logic looks like so:
	#  - return false if command exit successfully
	#  - return false if command exit after receiving a core signal (FIXME: or any signal?)
	#  - return true if command exit with an error

	# This naively assumes that the process doesn't exit with > 128 on its own.
	if ((es > 128)); then
		es=$((es & ~128))
		case "$es" in
			3) ;&       # SIGQUIT
			4) ;&       # SIGILL
			6) ;&       # SIGABRT
			8) ;&       # SIGFPE
			9) ;&       # SIGKILL
			11) es=0 ;; # SIGSEGV
			*) es=1 ;;
		esac
	elif [[ -n $EXIT_STATUS ]] && ((es != EXIT_STATUS)); then
		es=0
	fi

	# invert error code of any command and also trigger ERR on 0 (unlike bash ! prefix)
	((!es == 0))
}

function timing() {