From 2695854b90c84e842aa0964b7e726b2a88612b58 Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Mon, 10 Feb 2020 14:47:52 +0100 Subject: [PATCH] test/nvmf: Add skel for nvmf error testing The goal of this test is to make sure that proper parts of the lib fail as they should. These particular tests focus on: - spdk_rpc_nvmf_create_subsystem(): model and serial number checks Change-Id: I504279d08b192d6dfe37a8a601eda44084b596d4 Signed-off-by: Michal Berger Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/693 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki --- test/nvmf/nvmf.sh | 1 + test/nvmf/target/invalid.sh | 61 +++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 test/nvmf/target/invalid.sh diff --git a/test/nvmf/nvmf.sh b/test/nvmf/nvmf.sh index 56ea03b96b..7ab5c88755 100755 --- a/test/nvmf/nvmf.sh +++ b/test/nvmf/nvmf.sh @@ -39,6 +39,7 @@ run_test "nvmf_rpc" test/nvmf/target/rpc.sh "${TEST_ARGS[@]}" run_test "nvmf_fio" test/nvmf/target/fio.sh "${TEST_ARGS[@]}" run_test "nvmf_shutdown" test/nvmf/target/shutdown.sh "${TEST_ARGS[@]}" run_test "nvmf_bdevio" test/nvmf/target/bdevio.sh "${TEST_ARGS[@]}" +run_test "nvmf_invalid" test/nvmf/target/invalid.sh "${TEST_ARGS[@]}" timing_enter host diff --git a/test/nvmf/target/invalid.sh b/test/nvmf/target/invalid.sh new file mode 100755 index 0000000000..3f7b48c1f5 --- /dev/null +++ b/test/nvmf/target/invalid.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +testdir=$(readlink -f "$(dirname "$0")") +rootdir=$(readlink -f "$testdir/../../..") +source "$rootdir/test/common/autotest_common.sh" +source "$rootdir/test/nvmf/common.sh" + +multi_target_rpc=$rootdir/test/nvmf/target/multitarget_rpc.py +rpc=$rootdir/scripts/rpc.py +nqn=nqn.2016-06.io.spdk:cnode +target=foobar +# pre-seed the rng to generate predictive values across different test runs +RANDOM=0 + + +gen_random_s () { + local length=$1 ll + # generate ascii table which nvme supports + local chars=({32..127}) + local string + + for (( ll = 0; ll < length; ll++ )); do + string+="$(echo -e "\x$(printf '%x' "${chars[RANDOM % ${#chars[@]}]}")")" + done + echo "$string" +} + +nvmftestinit +nvmfappstart "-m 0xF" + +trap 'process_shm --id $NVMF_APP_SHM_ID; nvmftestfini $1; exit 1' SIGINT SIGTERM EXIT + + +# Attempt to create subsystem with non-existing target +out=$("$rpc" nvmf_create_subsystem -t "$target" "$nqn$RANDOM" 2>&1) && false +[[ $out == *"Unable to find target"* ]] + +# Attempt to create subsystem with invalid serial number - inject ASCII char that's +# not in the range (0x20-0x7e) of these supported by the nvme spec. +out=$("$rpc" nvmf_create_subsystem -s "$NVMF_SERIAL$(echo -e "\x1f")" "$nqn$RANDOM" 2>&1) && false +[[ $out == *"Invalid SN"* ]] + +# Attempt to create subsystem with invalid model - inject ASCII char that's not in the +# range (0x20-0x7e) of these supported by the nvme spec. +out=$("$rpc" nvmf_create_subsystem -d "SPDK_Controller$(echo -e "\x1f")" "$nqn$RANDOM" 2>&1) && false +[[ $out == *"Invalid MN"* ]] + +# Attempt to create subsystem with invalid serial number - exceed SPDK_NVME_CTRLR_SN_LEN (20) +out=$("$rpc" nvmf_create_subsystem -s "$(gen_random_s 21)" "$nqn$RANDOM" 2>&1) && false +[[ $out == *"Invalid SN"* ]] + +# Attempt to create subsystem with invalid model - exceed SPDK_NVME_CTRLR_MN_LEN (40) +out=$("$rpc" nvmf_create_subsystem -d "$(gen_random_s 41)" "$nqn$RANDOM" 2>&1) && false +[[ $out == *"Invalid MN"* ]] + +# Attempt to delete non-existing target +out=$("$multi_target_rpc" nvmf_delete_target --name "$target" 2>&1) && false +[[ $out == *"The specified target doesn't exist, cannot delete it."* ]] + +trap - SIGINT SIGTERM EXIT +nvmftestfini