1#!/usr/bin/env bash 2# 3# SPDX-License-Identifier: BSD-3-Clause 4# Copyright (C) 2024 Intel Corporation 5# All rights reserved. 6# 7testdir=$(readlink -f $(dirname $0)) 8rootdir=$(readlink -f $testdir/../..) 9source $rootdir/test/common/autotest_common.sh 10 11CONFIG_PATH="$rootdir/test/rpc/config.json" 12LOG_PATH="$rootdir/test/rpc/log.txt" 13 14test_skip_rpc() { 15 $SPDK_BIN_DIR/spdk_tgt --no-rpc-server -m 0x1 & 16 local spdk_pid=$! 17 18 trap 'killprocess $spdk_pid; exit 1' SIGINT SIGTERM EXIT 19 sleep 5 20 21 NOT rpc_cmd spdk_get_version &> /dev/null 22 trap - SIGINT SIGTERM EXIT 23 killprocess $spdk_pid 24} 25 26gen_json_config() { 27 $SPDK_BIN_DIR/spdk_tgt -m 0x1 & 28 local spdk_pid=$! 29 30 trap 'killprocess $spdk_pid; exit 1' SIGINT SIGTERM EXIT 31 waitforlisten $spdk_pid 32 33 # Use an RPC that results in an output to the terminal 34 rpc_cmd nvmf_get_transports --trtype tcp || rpc_cmd nvmf_create_transport -t tcp 35 36 rpc_cmd save_config > $CONFIG_PATH 37 cat $CONFIG_PATH 38 39 trap - SIGINT SIGTERM EXIT 40 killprocess $spdk_pid 41} 42 43test_skip_rpc_with_json() { 44 gen_json_config 45 46 $SPDK_BIN_DIR/spdk_tgt --no-rpc-server -m 0x1 --json $CONFIG_PATH &> $LOG_PATH & 47 local spdk_pid=$! 48 sleep 5 49 50 killprocess $spdk_pid 51 grep -q "TCP Transport Init" $LOG_PATH 52 rm $LOG_PATH 53} 54 55test_skip_rpc_with_delay() { 56 # Skipping RPC init and adding a delay are exclusive 57 NOT $SPDK_BIN_DIR/spdk_tgt --no-rpc-server -m 0x1 --wait-for-rpc 58} 59 60test_exit_on_failed_rpc_init() { 61 $SPDK_BIN_DIR/spdk_tgt -m 0x1 & 62 local spdk_pid=$! 63 waitforlisten $spdk_pid 64 65 trap 'killprocess $spdk_pid; exit 1' SIGINT SIGTERM EXIT 66 # RPC listening sockets must be unique for each SPDK instance, so this will fail 67 NOT $SPDK_BIN_DIR/spdk_tgt -m 0x2 68 69 trap - SIGINT SIGTERM EXIT 70 killprocess $spdk_pid 71} 72 73run_test "skip_rpc" test_skip_rpc 74run_test "skip_rpc_with_json" test_skip_rpc_with_json 75run_test "skip_rpc_with_delay" test_skip_rpc_with_delay 76# Only one DPDK process can run under FreeBSD (see lib/eal/freebsd/eal_hugepage_info.c in DPDK) 77if [ $(uname) != "FreeBSD" ]; then 78 run_test "exit_on_failed_rpc_init" test_exit_on_failed_rpc_init 79fi 80 81rm $CONFIG_PATH 82