From 08d4dce28ce6a3764756c15f7fa5ef19030aa87e Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Fri, 26 Mar 2021 14:10:03 +0100 Subject: [PATCH] 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: Michal Berger Change-Id: I29fbcf3f2751400980d35b4de2cce2da1cd2bf2a Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7087 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris --- test/common/autotest_common.sh | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index 2fba50005..265a40c54 100755 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -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 - echo "$@" >&$RPC_PIPE_INPUT while read -t 5 -ru $RPC_PIPE_OUTPUT rsp; do if [[ $rsp == "**STATUS="* ]]; then - break + status[${rsp#*=}]=$rsp + if ((++status_number == cmds_number)); then + break + fi + continue fi echo "$rsp" done - rc=${rsp#*=} + rc=${!status[*]} xtrace_restore [[ $rc == 0 ]] }