1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2020 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 11multi_target_rpc=$rootdir/test/nvmf/target/multitarget_rpc.py 12rpc=$rootdir/scripts/rpc.py 13nqn=nqn.2016-06.io.spdk:cnode 14target=foobar 15# pre-seed the rng to generate predictive values across different test runs 16RANDOM=0 17 18gen_random_s() { 19 local length=$1 ll 20 # generate ascii table which nvme supports 21 local chars=({32..127}) 22 local string 23 24 for ((ll = 0; ll < length; ll++)); do 25 string+="$(echo -e "\x$(printf '%x' "${chars[RANDOM % ${#chars[@]}]}")")" 26 done 27 # Be nice to rpc.py's arg parser and escape `-` in case it's a first character 28 if [[ ${string::1} == "-" ]]; then 29 string=${string/-/\\-} 30 fi 31 echo "$string" 32} 33 34nvmftestinit 35nvmfappstart -m 0xF 36 37trap 'process_shm --id $NVMF_APP_SHM_ID; nvmftestfini $1; exit 1' SIGINT SIGTERM EXIT 38 39# Attempt to create subsystem with non-existing target 40out=$("$rpc" nvmf_create_subsystem -t "$target" "$nqn$RANDOM" 2>&1) && false 41[[ $out == *"Unable to find target"* ]] 42 43# Attempt to create subsystem with invalid serial number - inject ASCII char that's 44# not in the range (0x20-0x7e) of these supported by the nvme spec. 45out=$("$rpc" nvmf_create_subsystem -s "$NVMF_SERIAL$(echo -e "\x1f")" "$nqn$RANDOM" 2>&1) && false 46[[ $out == *"Invalid SN"* ]] 47 48# Attempt to create subsystem with invalid model - inject ASCII char that's not in the 49# range (0x20-0x7e) of these supported by the nvme spec. 50out=$("$rpc" nvmf_create_subsystem -d "SPDK_Controller$(echo -e "\x1f")" "$nqn$RANDOM" 2>&1) && false 51[[ $out == *"Invalid MN"* ]] 52 53# Attempt to create subsystem with invalid serial number - exceed SPDK_NVME_CTRLR_SN_LEN (20) 54out=$("$rpc" nvmf_create_subsystem -s "$(gen_random_s 21)" "$nqn$RANDOM" 2>&1) && false 55[[ $out == *"Invalid SN"* ]] 56 57# Attempt to create subsystem with invalid model - exceed SPDK_NVME_CTRLR_MN_LEN (40) 58out=$("$rpc" nvmf_create_subsystem -d "$(gen_random_s 41)" "$nqn$RANDOM" 2>&1) && false 59[[ $out == *"Invalid MN"* ]] 60 61# Attempt to delete non-existing subsystem listener 62$rpc nvmf_create_transport --trtype "$TEST_TRANSPORT" 63$rpc nvmf_create_subsystem $nqn -s SPDK001 -a 64if [[ $TEST_TRANSPORT == "TCP" ]]; then 65 IP="127.0.0.1" 66else 67 IP=$(echo "$RDMA_IP_LIST" | head -n 1) 68fi 69out=$("$rpc" nvmf_subsystem_remove_listener "$nqn" -t "$TEST_TRANSPORT" -a "$IP" -s 4421 2>&1) && false 70[[ $out != *"Unable to stop listener."* ]] 71 72# Attempt to create subsystem with invalid controller ID range - outside [1, 0xffef] 73out=$("$rpc" nvmf_create_subsystem "$nqn$RANDOM" -i 0 2>&1) && false 74[[ $out == *"Invalid cntlid range"* ]] 75out=$("$rpc" nvmf_create_subsystem "$nqn$RANDOM" -i 65520 2>&1) && false 76[[ $out == *"Invalid cntlid range"* ]] 77out=$("$rpc" nvmf_create_subsystem "$nqn$RANDOM" -I 0 2>&1) && false 78[[ $out == *"Invalid cntlid range"* ]] 79out=$("$rpc" nvmf_create_subsystem "$nqn$RANDOM" -I 65520 2>&1) && false 80[[ $out == *"Invalid cntlid range"* ]] 81 82# Attempt to create subsystem with invalid controller ID range - [x, y] where x>y 83out=$("$rpc" nvmf_create_subsystem "$nqn$RANDOM" -i 6 -I 5 2>&1) && false 84[[ $out == *"Invalid cntlid range"* ]] 85 86# Attempt to delete non-existing target 87out=$("$multi_target_rpc" nvmf_delete_target --name "$target" 2>&1) && false 88[[ $out == *"The specified target doesn't exist, cannot delete it."* ]] 89 90trap - SIGINT SIGTERM EXIT 91nvmftestfini 92