1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2019 Intel Corporation 4# All rights reserved. 5# 6testdir=$(readlink -f $(dirname $0)) 7rootdir=$(readlink -f $testdir/../../..) 8source $rootdir/test/common/autotest_common.sh 9source $rootdir/test/nvmf/common.sh 10 11PLUGIN_DIR=$rootdir/examples/nvme/fio_plugin 12 13MALLOC_BDEV_SIZE=64 14MALLOC_BLOCK_SIZE=512 15 16function disconnect_init() { 17 nvmfappstart -m 0xF0 18 19 $rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc0 20 21 $rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS 22 $rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode1 -a -s SPDK00000000000001 23 24 $rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode1 Malloc0 25 $rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $1 -s $NVMF_PORT 26 $rpc_py nvmf_subsystem_add_listener discovery -t $TEST_TRANSPORT -a $1 -s $NVMF_PORT 27} 28 29# Test to make sure we don't segfault or access null pointers when we try to connect to 30# a discovery controller that doesn't exist yet. 31function nvmf_target_disconnect_tc1() { 32 set +e 33 $SPDK_EXAMPLE_DIR/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \ 34 -r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT" 35 # If the program crashes, the high bit of $? will be set so we will get a value in the hundreds. 36 # But if the reconnect code detects errors and exits normally it will return 1. 37 if [ $? != 1 ]; then 38 set -e 39 exit 1 40 fi 41 set -e 42} 43 44function nvmf_target_disconnect_tc2() { 45 disconnect_init $NVMF_FIRST_TARGET_IP 46 47 # If perf doesn't shut down, this test will time out. 48 $SPDK_EXAMPLE_DIR/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \ 49 -r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT" & 50 reconnectpid=$! 51 52 sleep 2 53 kill -9 $nvmfpid 54 55 sleep 2 56 disconnect_init $NVMF_FIRST_TARGET_IP 57 58 wait $reconnectpid 59 sync 60} 61 62function nvmf_target_disconnect_tc3() { 63 $SPDK_EXAMPLE_DIR/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \ 64 -r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT alt_traddr:$NVMF_SECOND_TARGET_IP" & 65 reconnectpid=$! 66 67 sleep 2 68 kill -9 $nvmfpid 69 70 sleep 2 71 disconnect_init $NVMF_SECOND_TARGET_IP 72 73 wait $reconnectpid 74 sync 75} 76 77nvmftestinit 78run_test "nvmf_target_disconnect_tc1" nvmf_target_disconnect_tc1 79run_test "nvmf_target_disconnect_tc2" nvmf_target_disconnect_tc2 80if [ -n "$NVMF_SECOND_TARGET_IP" ]; then 81 run_test "nvmf_target_disconnect_tc3" nvmf_target_disconnect_tc3 82fi 83 84trap - SIGINT SIGTERM EXIT 85nvmftestfini 86