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 <tom.nabarro@intel.com>
Change-Id: I3ef6fe20d21398d30fa8011e20de1524e60ee841
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10204
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Niu Yawei <yawei.niu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Tom Nabarro 2021-11-12 06:08:04 -05:00 committed by Tomasz Zawadzki
parent a15b6af0a6
commit 921c92e2a5
3 changed files with 110 additions and 0 deletions

View File

@ -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

View File

@ -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"
}
]
}
]
}

View File

@ -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"