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

test/common: Avoid potential false-positives in NOT() by validating the arguments



Cover cases where, for instance, user passes non-existing path for
execution - currently, NOT() would successfully return in such a
case, so make sure it doesn't.

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


Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarPawel Piatek <pawelx.piatek@intel.com>
parent 6a613d6b
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -627,9 +627,22 @@ function rpc_cmd_simple_data_json() {
	((${#jq_out[@]} > 0)) || return 1
}

function valid_exec_arg() {
	local arg=$1
	# First argument must be the executable so do some basic sanity checks first. For bash, this
	# covers two basic cases where es == 126 || es == 127 so catch them early on and fail hard
	# if needed.
	case "$(type -t "$arg")" in
		builtin | function) ;;
		file) arg=$(type -P "$arg") && [[ -x $arg ]] ;;
		*) return 1 ;;
	esac
}

function NOT() {
	local es=0

	valid_exec_arg "$@" || return 1
	"$@" || es=$?

	# Logic looks like so: