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 <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15362
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Krzysztof Karas 2022-11-09 11:54:37 +00:00 committed by Tomasz Zawadzki
parent b5bdbbb959
commit 3242d3c524

View File

@ -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);