From 921c92e2a558a6abee68ed47fa8ffdc956bde5ae Mon Sep 17 00:00:00 2001 From: Tom Nabarro Date: Fri, 12 Nov 2021 06:08:04 -0500 Subject: [PATCH] test/config: verify extra key in config doesnt break parsing Add autotest case to verify that additional top-level key in JSON config file doesn't break parsing when loading and initializing subsystems from said file. This is a regression test to help applications use the same config file to communicate private and SPDK data. Signed-off-by: Tom Nabarro Change-Id: I3ef6fe20d21398d30fa8011e20de1524e60ee841 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10204 Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Niu Yawei Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki --- autotest.sh | 1 + test/json_config/extra_key.json | 31 +++++++++ test/json_config/json_config_extra_key.sh | 78 +++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 test/json_config/extra_key.json create mode 100755 test/json_config/json_config_extra_key.sh diff --git a/autotest.sh b/autotest.sh index de3d320ab1..d7c41b17d7 100755 --- a/autotest.sh +++ b/autotest.sh @@ -174,6 +174,7 @@ if [ $SPDK_RUN_FUNCTIONAL_TEST -eq 1 ]; then run_test "rpc" test/rpc/rpc.sh run_test "rpc_client" test/rpc_client/rpc_client.sh run_test "json_config" ./test/json_config/json_config.sh + run_test "json_config_extra_key" ./test/json_config/json_config_extra_key.sh run_test "alias_rpc" test/json_config/alias_rpc/alias_rpc.sh run_test "spdkcli_tcp" test/spdkcli/tcp.sh run_test "dpdk_mem_utility" test/dpdk_memory_utility/test_dpdk_mem_info.sh diff --git a/test/json_config/extra_key.json b/test/json_config/extra_key.json new file mode 100644 index 0000000000..ae5dca60a1 --- /dev/null +++ b/test/json_config/extra_key.json @@ -0,0 +1,31 @@ +{ + "extrakey": [ + { + "foo": "bar" + } + ], + "subsystems": [ + { + "subsystem": "bdev", + "config": [ + { + "params": { + "bdev_io_pool_size": 65536, + "bdev_io_cache_size": 256 + }, + "method": "bdev_set_options" + }, + { + "params": { + "retry_count": 4, + "timeout_us": 0, + "nvme_adminq_poll_period_us": 100000, + "action_on_timeout": "none", + "nvme_ioq_poll_period_us": 0 + }, + "method": "bdev_nvme_set_options" + } + ] + } + ] +} diff --git a/test/json_config/json_config_extra_key.sh b/test/json_config/json_config_extra_key.sh new file mode 100755 index 0000000000..592b465dc4 --- /dev/null +++ b/test/json_config/json_config_extra_key.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +rootdir=$(readlink -f $(dirname $0)/../..) +source "$rootdir/test/common/autotest_common.sh" +source "$rootdir/test/nvmf/common.sh" + +# Check that adding arbitrary top-level key to JSON SPDK config alongside +# "subsystems" doesn't break SPDK parsing that occurs when loading config +# to initialize subsystems. This enables applications to use the same config +# file to communicate private and SPDK data. + +declare -A app_pid=([target]="") +declare -A app_socket=([target]='/var/tmp/spdk_tgt.sock') +declare -A app_params=([target]='-m 0x1 -s 1024') +declare -A configs_path=([target]="$rootdir/test/json_config/extra_key.json") + +# $1 - target +# $2..$n app parameters +function json_config_test_start_app() { + local app=$1 + shift + + [[ -n "${#app_socket[$app]}" ]] # Check app type + [[ -z "${app_pid[$app]}" ]] # Assert if app is not running + + $SPDK_BIN_DIR/spdk_tgt ${app_params[$app]} -r ${app_socket[$app]} "$@" & + app_pid[$app]=$! + + echo "Waiting for $app to run..." + waitforlisten ${app_pid[$app]} ${app_socket[$app]} + echo "" +} + +# $1 - target / initiator +function json_config_test_shutdown_app() { + local app=$1 + + # Check app type && assert app was started + [[ -n "${#app_socket[$app]}" ]] + [[ -n "${app_pid[$app]}" ]] + + # spdk_kill_instance RPC will trigger ASAN + kill -SIGINT ${app_pid[$app]} + + for ((i = 0; i < 30; i++)); do + if ! kill -0 ${app_pid[$app]} 2> /dev/null; then + app_pid[$app]= + break + fi + sleep 0.5 + done + + if [[ -n "${app_pid[$app]}" ]]; then + echo "SPDK $app shutdown timeout" + return 1 + fi + + echo "SPDK $app shutdown done" +} + +on_error_exit() { + set -x + set +e + print_backtrace + trap - ERR + echo "Error on $1 - $2" + exit 1 +} + +trap 'on_error_exit "${FUNCNAME}" "${LINENO}"' ERR + +echo "INFO: launching applications..." +json_config_test_start_app target --json ${configs_path[target]} + +echo "INFO: shutting down applications..." +json_config_test_shutdown_app target + +echo "Success"