1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2021 Intel Corporation 4# All rights reserved. 5# 6 7rootdir=$(readlink -f $(dirname $0)/../..) 8source "$rootdir/test/common/autotest_common.sh" 9source "$rootdir/test/nvmf/common.sh" 10 11# Check that adding arbitrary top-level key to JSON SPDK config alongside 12# "subsystems" doesn't break SPDK parsing that occurs when loading config 13# to initialize subsystems. This enables applications to use the same config 14# file to communicate private and SPDK data. 15 16declare -A app_pid=([target]="") 17declare -A app_socket=([target]='/var/tmp/spdk_tgt.sock') 18declare -A app_params=([target]='-m 0x1 -s 1024') 19declare -A configs_path=([target]="$rootdir/test/json_config/extra_key.json") 20 21# $1 - target 22# $2..$n app parameters 23function json_config_test_start_app() { 24 local app=$1 25 shift 26 27 [[ -n "${#app_socket[$app]}" ]] # Check app type 28 [[ -z "${app_pid[$app]}" ]] # Assert if app is not running 29 30 $SPDK_BIN_DIR/spdk_tgt ${app_params[$app]} -r ${app_socket[$app]} "$@" & 31 app_pid[$app]=$! 32 33 echo "Waiting for $app to run..." 34 waitforlisten ${app_pid[$app]} ${app_socket[$app]} 35 echo "" 36} 37 38# $1 - target / initiator 39function json_config_test_shutdown_app() { 40 local app=$1 41 42 # Check app type && assert app was started 43 [[ -n "${#app_socket[$app]}" ]] 44 [[ -n "${app_pid[$app]}" ]] 45 46 # spdk_kill_instance RPC will trigger ASAN 47 kill -SIGINT ${app_pid[$app]} 48 49 for ((i = 0; i < 30; i++)); do 50 if ! kill -0 ${app_pid[$app]} 2> /dev/null; then 51 app_pid[$app]= 52 break 53 fi 54 sleep 0.5 55 done 56 57 if [[ -n "${app_pid[$app]}" ]]; then 58 echo "SPDK $app shutdown timeout" 59 return 1 60 fi 61 62 echo "SPDK $app shutdown done" 63} 64 65on_error_exit() { 66 set -x 67 set +e 68 print_backtrace 69 trap - ERR 70 echo "Error on $1 - $2" 71 exit 1 72} 73 74trap 'on_error_exit "${FUNCNAME}" "${LINENO}"' ERR 75 76echo "INFO: launching applications..." 77json_config_test_start_app target --json ${configs_path[target]} 78 79echo "INFO: shutting down applications..." 80json_config_test_shutdown_app target 81 82echo "Success" 83