numam-spdk/test/rpc/rpc.sh

57 lines
1.4 KiB
Bash
Raw Normal View History

scripts/rpc.py: add daemon mode Add rpc_cmd() bash command that sends rpc command to an rpc.py instance permanently running in background. This makes sending RPC commands even 17 times faster. We make use of bash coprocesses - a builtin bash feature that allow starting background processes with stdin and stdout connected to pipes. rpc.py will block trying to read stdin, effectively being always "ready" to read an RPC command. The background rpc.py is started with a new --server flag that's described as: > Start listening on stdin, parse each line as a regular > rpc.py execution and create a separate connection for each command. > Each command's output ends with either **STATUS=0 if the > command succeeded or **STATUS=1 if it failed. > --server is meant to be used in conjunction with bash > coproc, where stdin and stdout are named pipes and can be > used as a faster way to send RPC commands. As a part of this patch I'm attaching a sample test that runs the following rpc commands first with the regular rpc.py, then the new rpc_cmd() function. ``` time { bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "0" ] malloc=$($rpc bdev_malloc_create 8 512) bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "1" ] $rpc bdev_passthru_create -b "$malloc" -p Passthru0 bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "2" ] $rpc bdev_passthru_delete Passthru0 $rpc bdev_malloc_delete $malloc bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "0" ] } ``` Regular rpc.py: ``` real 0m1.477s user 0m1.289s sys 0m0.139s ``` rpc_cmd(): ``` real 0m0.085s user 0m0.025s sys 0m0.006s ``` autotest_common.sh will now spawn an rpc.py daemon if it's not running yet, and it will offer rpc_cmd() function to quickly send RPC commands. If the command is invalid or SPDK returns with error, the bash function will return a non-zero code and may trigger ERR trap just like a regular rpc.py instance. Pipes have major advantage over e.g. unix domain sockets - the pipes will be automatically closed once the owner process exits. This means we can create a named pipe in autotest_common.sh, open it, then start rpc.py in background and never worry about it again - it will be closed automatically once the test exits. It doesn't even matter if the test is executed manually in isolation, or as a part of the entire autotest. (check_so_deps.sh needs to be modified not to wait for *all* background processes to finish, but just the ones it started) Change-Id: If0ded961b7fef3af3837b44532300dee8b5b4663 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Signed-off-by: Michal Berger <michalx.berger@intel.com> Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/621 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
2019-06-21 07:38:47 +00:00
#!/usr/bin/env bash
testdir=$(readlink -f $(dirname $0))
rootdir=$(readlink -f $testdir/../..)
source $rootdir/test/common/autotest_common.sh
# simply check if rpc commands have any effect on spdk
function rpc_integrity() {
time {
bdevs=$($rpc bdev_get_bdevs)
[ "$(jq length <<< "$bdevs")" == "0" ]
malloc=$($rpc bdev_malloc_create 8 512)
bdevs=$($rpc bdev_get_bdevs)
[ "$(jq length <<< "$bdevs")" == "1" ]
$rpc bdev_passthru_create -b "$malloc" -p Passthru0
bdevs=$($rpc bdev_get_bdevs)
[ "$(jq length <<< "$bdevs")" == "2" ]
$rpc bdev_passthru_delete Passthru0
$rpc bdev_malloc_delete $malloc
bdevs=$($rpc bdev_get_bdevs)
[ "$(jq length <<< "$bdevs")" == "0" ]
}
}
function rpc_plugins() {
time {
malloc=$($rpc --plugin rpc_plugin create_malloc)
bdevs=$($rpc bdev_get_bdevs)
[ "$(jq length <<< "$bdevs")" == "1" ]
$rpc --plugin rpc_plugin delete_malloc $malloc
bdevs=$($rpc bdev_get_bdevs)
[ "$(jq length <<< "$bdevs")" == "0" ]
}
}
$SPDK_BIN_DIR/spdk_tgt &
scripts/rpc.py: add daemon mode Add rpc_cmd() bash command that sends rpc command to an rpc.py instance permanently running in background. This makes sending RPC commands even 17 times faster. We make use of bash coprocesses - a builtin bash feature that allow starting background processes with stdin and stdout connected to pipes. rpc.py will block trying to read stdin, effectively being always "ready" to read an RPC command. The background rpc.py is started with a new --server flag that's described as: > Start listening on stdin, parse each line as a regular > rpc.py execution and create a separate connection for each command. > Each command's output ends with either **STATUS=0 if the > command succeeded or **STATUS=1 if it failed. > --server is meant to be used in conjunction with bash > coproc, where stdin and stdout are named pipes and can be > used as a faster way to send RPC commands. As a part of this patch I'm attaching a sample test that runs the following rpc commands first with the regular rpc.py, then the new rpc_cmd() function. ``` time { bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "0" ] malloc=$($rpc bdev_malloc_create 8 512) bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "1" ] $rpc bdev_passthru_create -b "$malloc" -p Passthru0 bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "2" ] $rpc bdev_passthru_delete Passthru0 $rpc bdev_malloc_delete $malloc bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "0" ] } ``` Regular rpc.py: ``` real 0m1.477s user 0m1.289s sys 0m0.139s ``` rpc_cmd(): ``` real 0m0.085s user 0m0.025s sys 0m0.006s ``` autotest_common.sh will now spawn an rpc.py daemon if it's not running yet, and it will offer rpc_cmd() function to quickly send RPC commands. If the command is invalid or SPDK returns with error, the bash function will return a non-zero code and may trigger ERR trap just like a regular rpc.py instance. Pipes have major advantage over e.g. unix domain sockets - the pipes will be automatically closed once the owner process exits. This means we can create a named pipe in autotest_common.sh, open it, then start rpc.py in background and never worry about it again - it will be closed automatically once the test exits. It doesn't even matter if the test is executed manually in isolation, or as a part of the entire autotest. (check_so_deps.sh needs to be modified not to wait for *all* background processes to finish, but just the ones it started) Change-Id: If0ded961b7fef3af3837b44532300dee8b5b4663 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Signed-off-by: Michal Berger <michalx.berger@intel.com> Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/621 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
2019-06-21 07:38:47 +00:00
spdk_pid=$!
trap 'killprocess $spdk_pid; exit 1' SIGINT SIGTERM EXIT
waitforlisten $spdk_pid
export PYTHONPATH=$testdir
scripts/rpc.py: add daemon mode Add rpc_cmd() bash command that sends rpc command to an rpc.py instance permanently running in background. This makes sending RPC commands even 17 times faster. We make use of bash coprocesses - a builtin bash feature that allow starting background processes with stdin and stdout connected to pipes. rpc.py will block trying to read stdin, effectively being always "ready" to read an RPC command. The background rpc.py is started with a new --server flag that's described as: > Start listening on stdin, parse each line as a regular > rpc.py execution and create a separate connection for each command. > Each command's output ends with either **STATUS=0 if the > command succeeded or **STATUS=1 if it failed. > --server is meant to be used in conjunction with bash > coproc, where stdin and stdout are named pipes and can be > used as a faster way to send RPC commands. As a part of this patch I'm attaching a sample test that runs the following rpc commands first with the regular rpc.py, then the new rpc_cmd() function. ``` time { bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "0" ] malloc=$($rpc bdev_malloc_create 8 512) bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "1" ] $rpc bdev_passthru_create -b "$malloc" -p Passthru0 bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "2" ] $rpc bdev_passthru_delete Passthru0 $rpc bdev_malloc_delete $malloc bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "0" ] } ``` Regular rpc.py: ``` real 0m1.477s user 0m1.289s sys 0m0.139s ``` rpc_cmd(): ``` real 0m0.085s user 0m0.025s sys 0m0.006s ``` autotest_common.sh will now spawn an rpc.py daemon if it's not running yet, and it will offer rpc_cmd() function to quickly send RPC commands. If the command is invalid or SPDK returns with error, the bash function will return a non-zero code and may trigger ERR trap just like a regular rpc.py instance. Pipes have major advantage over e.g. unix domain sockets - the pipes will be automatically closed once the owner process exits. This means we can create a named pipe in autotest_common.sh, open it, then start rpc.py in background and never worry about it again - it will be closed automatically once the test exits. It doesn't even matter if the test is executed manually in isolation, or as a part of the entire autotest. (check_so_deps.sh needs to be modified not to wait for *all* background processes to finish, but just the ones it started) Change-Id: If0ded961b7fef3af3837b44532300dee8b5b4663 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Signed-off-by: Michal Berger <michalx.berger@intel.com> Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/621 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
2019-06-21 07:38:47 +00:00
# basic integrity test
rpc="$rootdir/scripts/rpc.py"
run_test "rpc_integrity" rpc_integrity
run_test "rpc_plugins" rpc_plugins
# same integrity test, but with rpc_cmd() instead
scripts/rpc.py: add daemon mode Add rpc_cmd() bash command that sends rpc command to an rpc.py instance permanently running in background. This makes sending RPC commands even 17 times faster. We make use of bash coprocesses - a builtin bash feature that allow starting background processes with stdin and stdout connected to pipes. rpc.py will block trying to read stdin, effectively being always "ready" to read an RPC command. The background rpc.py is started with a new --server flag that's described as: > Start listening on stdin, parse each line as a regular > rpc.py execution and create a separate connection for each command. > Each command's output ends with either **STATUS=0 if the > command succeeded or **STATUS=1 if it failed. > --server is meant to be used in conjunction with bash > coproc, where stdin and stdout are named pipes and can be > used as a faster way to send RPC commands. As a part of this patch I'm attaching a sample test that runs the following rpc commands first with the regular rpc.py, then the new rpc_cmd() function. ``` time { bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "0" ] malloc=$($rpc bdev_malloc_create 8 512) bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "1" ] $rpc bdev_passthru_create -b "$malloc" -p Passthru0 bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "2" ] $rpc bdev_passthru_delete Passthru0 $rpc bdev_malloc_delete $malloc bdevs=$($rpc bdev_get_bdevs) [ "$(jq length <<< "$bdevs")" == "0" ] } ``` Regular rpc.py: ``` real 0m1.477s user 0m1.289s sys 0m0.139s ``` rpc_cmd(): ``` real 0m0.085s user 0m0.025s sys 0m0.006s ``` autotest_common.sh will now spawn an rpc.py daemon if it's not running yet, and it will offer rpc_cmd() function to quickly send RPC commands. If the command is invalid or SPDK returns with error, the bash function will return a non-zero code and may trigger ERR trap just like a regular rpc.py instance. Pipes have major advantage over e.g. unix domain sockets - the pipes will be automatically closed once the owner process exits. This means we can create a named pipe in autotest_common.sh, open it, then start rpc.py in background and never worry about it again - it will be closed automatically once the test exits. It doesn't even matter if the test is executed manually in isolation, or as a part of the entire autotest. (check_so_deps.sh needs to be modified not to wait for *all* background processes to finish, but just the ones it started) Change-Id: If0ded961b7fef3af3837b44532300dee8b5b4663 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Signed-off-by: Michal Berger <michalx.berger@intel.com> Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/621 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
2019-06-21 07:38:47 +00:00
rpc="rpc_cmd"
run_test "rpc_daemon_integrity" rpc_integrity
trap - SIGINT SIGTERM EXIT
killprocess $spdk_pid