From 3242d3c524fcbd19a6cb329bb724a69456365d0b Mon Sep 17 00:00:00 2001 From: Krzysztof Karas Date: Wed, 9 Nov 2022 11:54:37 +0000 Subject: [PATCH] bdev_nvme_ut: add tests for UUID generation mechanism Test uniqueness of generated UUIDs in two cases: 1) For a single controller with two namespaces. Serial number remains the same, but different namespace IDs should contribute enough to get a unique UUID. 2) For two controllers with one namespace each. Serial numbers differ only by one character and namespace IDs are the same. Single different character in serial number should make UUID unique. Also validate UUID generated from serial number containing only space characters. Change-Id: I16e39e269ced4d8405fb5b3af6aa8bf98ecfd7ba Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15362 Tested-by: SPDK CI Jenkins Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris Community-CI: Mellanox Build Bot --- .../lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c b/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c index fb69de14a..64505c8da 100644 --- a/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c +++ b/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c @@ -6135,6 +6135,38 @@ test_set_multipath_policy(void) CU_ASSERT(nvme_ctrlr_get_by_name("nvme0") == NULL); } +static void +test_uuid_generation(void) +{ + uint32_t nsid1 = 1, nsid2 = 2; + char sn1[21] = "SPDK CTRLR SERIAL 01", sn2[21] = "SPDK CTRLR SERIAL 02"; + char sn3[21] = " "; + char uuid_str[SPDK_UUID_STRING_LEN] = {'\0'}; + struct spdk_uuid uuid1, uuid2; + + /* Test case 1: + * Serial numbers are the same, nsids are different. + * Compare two generated UUID - they should be different. */ + uuid1 = nvme_generate_uuid(sn1, nsid1); + uuid2 = nvme_generate_uuid(sn1, nsid2); + + CU_ASSERT((spdk_uuid_compare(&uuid1, &uuid2)) != 0); + + /* Test case 2: + * Serial numbers differ only by one character, nsids are the same. + * Compare two generated UUID - they should be different. */ + uuid1 = nvme_generate_uuid(sn1, nsid1); + uuid2 = nvme_generate_uuid(sn2, nsid1); + + CU_ASSERT((spdk_uuid_compare(&uuid1, &uuid2)) != 0); + + /* Test case 3: + * Serial number comprises only of space characters. + * Validate the generated UUID. */ + uuid1 = nvme_generate_uuid(sn3, nsid1); + CU_ASSERT((spdk_uuid_fmt_lower(uuid_str, sizeof(uuid_str), &uuid1)) == 0); +} + int main(int argc, const char **argv) { @@ -6185,6 +6217,7 @@ main(int argc, const char **argv) CU_ADD_TEST(suite, test_find_next_io_path); CU_ADD_TEST(suite, test_disable_auto_failback); CU_ADD_TEST(suite, test_set_multipath_policy); + CU_ADD_TEST(suite, test_uuid_generation); CU_basic_set_mode(CU_BRM_VERBOSE);