From 5f0ed1cc973e031f621c8a706d0916c6c29edaa6 Mon Sep 17 00:00:00 2001 From: Mao Jiang Date: Fri, 27 Aug 2021 02:47:18 +0000 Subject: [PATCH] test/nvmf/subsystem: cases for valid nqn Change-Id: I4dbbc4ec555c08395d257568aa2fcc49e7bd3cbf Signed-off-by: Mao Jiang Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9321 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Changpeng Liu Reviewed-by: Tomasz Zawadzki --- test/unit/lib/nvmf/subsystem.c/subsystem_ut.c | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c b/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c index 9147de0f9b..3d61a30214 100644 --- a/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c +++ b/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c @@ -39,6 +39,7 @@ #include "spdk/bdev_module.h" #include "nvmf/subsystem.c" +#include SPDK_LOG_REGISTER_COMPONENT(nvmf) @@ -1583,6 +1584,59 @@ test_nvmf_ns_reservation_report(void) free(reg); } +static void +test_nvmf_valid_nqn(void) +{ + bool rc; + char uuid[SPDK_NVMF_UUID_STRING_LEN + 1] = {}; + char nqn[SPDK_NVMF_NQN_MAX_LEN + 1] = {}; + struct spdk_uuid s_uuid = {}; + + spdk_uuid_generate(&s_uuid); + uuid_unparse((void *)&s_uuid, uuid); + + /* discovery nqn */ + snprintf(nqn, sizeof(nqn), "%s", SPDK_NVMF_DISCOVERY_NQN); + + rc = nvmf_valid_nqn(nqn); + CU_ASSERT(rc == true); + + /* nqn with uuid */ + memset(nqn, 0xff, sizeof(nqn)); + snprintf(nqn, sizeof(nqn), "%s%s", SPDK_NVMF_NQN_UUID_PRE, uuid); + + rc = nvmf_valid_nqn(nqn); + CU_ASSERT(rc == true); + + /* Check nqn valid reverse domain */ + memset(nqn, 0xff, sizeof(nqn)); + snprintf(nqn, sizeof(nqn), "%s", "nqn.2016-06.io.spdk:cnode1"); + + rc = nvmf_valid_nqn(nqn); + CU_ASSERT(rc == true); + + /* Invalid nqn length */ + memset(nqn, 0xff, sizeof(nqn)); + snprintf(nqn, sizeof(nqn), "%s", "nqn."); + + rc = nvmf_valid_nqn(nqn); + CU_ASSERT(rc == false); + + /* Copy uuid to the nqn string, but omit the last character to make it invalid */ + memset(nqn, 0, SPDK_NVMF_NQN_MAX_LEN + 1); + snprintf(nqn, sizeof(nqn), "%s", SPDK_NVMF_NQN_UUID_PRE); + memcpy(&nqn[SPDK_NVMF_NQN_UUID_PRE_LEN], uuid, SPDK_NVMF_UUID_STRING_LEN - 1); + + rc = nvmf_valid_nqn(nqn); + CU_ASSERT(rc == false); + + /* Invalid domain */ + memset(nqn, 0xff, SPDK_NVMF_NQN_MAX_LEN + 1); + snprintf(nqn, sizeof(nqn), "%s", "nqn.2016-06.io...spdk:cnode1"); + + rc = nvmf_valid_nqn(nqn); + CU_ASSERT(rc == false); +} int main(int argc, char **argv) { @@ -1612,6 +1666,7 @@ int main(int argc, char **argv) CU_ADD_TEST(suite, test_nvmf_subsystem_add_ctrlr); CU_ADD_TEST(suite, test_spdk_nvmf_subsystem_add_host); CU_ADD_TEST(suite, test_nvmf_ns_reservation_report); + CU_ADD_TEST(suite, test_nvmf_valid_nqn); allocate_threads(1); set_thread(0);