xref: /spdk/test/rpc/skip_rpc.sh (revision 93731ac74153c87168401ec05c111d213aa1e533)
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
60run_test "skip_rpc" test_skip_rpc
61run_test "skip_rpc_with_json" test_skip_rpc_with_json
62run_test "skip_rpc_with_delay" test_skip_rpc_with_delay
63
64rm $CONFIG_PATH
65