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

test/common: Allow rpc_cmd() to execute multiple commands



This allows to pass to rpc_cmd() sets of commands via stdin. E.g.:

rpc_cmd <<-CMDS
	bdev_malloc_create -b Malloc0 32 512
	bdev_malloc_create -b Malloc1 32 512
	bdev_malloc_create -b Malloc2 32 512
CMDS

Since rpc.py is already running in a server mode, this is slightly
faster than grouping commands and running scripts/rpc.py directly.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 9aa3c063
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -445,17 +445,32 @@ function get_config_params() {

function rpc_cmd() {
	xtrace_disable
	local rsp rc
	local rsp rc=1
	local stdin cmd cmds_number=0 status_number=0 status

	if (($#)); then
		cmds_number=1
		echo "$@" >&$RPC_PIPE_INPUT
	elif [[ ! -t 0 ]]; then
		mapfile -t stdin <&0
		cmds_number=${#stdin[@]}
		printf '%s\n' "${stdin[@]}" >&$RPC_PIPE_INPUT
	else
		return 0
	fi

	while read -t 5 -ru $RPC_PIPE_OUTPUT rsp; do
		if [[ $rsp == "**STATUS="* ]]; then
			status[${rsp#*=}]=$rsp
			if ((++status_number == cmds_number)); then
				break
			fi
			continue
		fi
		echo "$rsp"
	done

	rc=${rsp#*=}
	rc=${!status[*]}
	xtrace_restore
	[[ $rc == 0 ]]
}