]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: lib/uuid: add unit tests for dynamic UUIDs
authorCaleb Connolly <caleb.connolly@linaro.org>
Fri, 30 Aug 2024 12:34:40 +0000 (13:34 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Thu, 12 Sep 2024 15:35:38 +0000 (17:35 +0200)
Add some basic unit tests to validate that the UUID generation behaves
as expected. This matches the implementation in efi_loader for sandbox
and a Qualcomm board and should catch any regressions.

Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
test/lib/uuid.c

index 3d62e18bcfee4fab12e440faeb1f355f6f2b8efd..a36eb2ff4e8d372d4c5ccb6d9d447f39773208c8 100644 (file)
@@ -8,13 +8,18 @@
  *   Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
  */
 
+#include <charset.h>
 #include <u-boot/uuid.h>
 #include <test/lib.h>
 #include <test/test.h>
 #include <test/ut.h>
 
+#include <efi.h>
+
 /* test UUID */
 #define TEST_SVC_UUID  "ed32d533-4209-99e6-2d72-cdd998a79cc0"
+/* U-Boot default fw image namespace */
+#define DEFAULT_FW_IMAGE_NAMESPACE "8c9f137e-91dc-427b-b2d6-b420faebaf2a"
 
 #define UUID_SIZE 16
 
@@ -37,3 +42,79 @@ static int lib_test_uuid_to_le(struct unit_test_state *uts)
        return 0;
 }
 LIB_TEST(lib_test_uuid_to_le, 0);
+
+struct dynamic_uuid_test_data {
+       const char *compatible;
+       const u16 *images[4];
+       const char *expected_uuids[4];
+};
+
+static int lib_test_dynamic_uuid_case(struct unit_test_state *uts,
+                                     const struct dynamic_uuid_test_data *data)
+{
+       struct uuid namespace;
+       int j;
+
+       ut_assertok(uuid_str_to_bin(DEFAULT_FW_IMAGE_NAMESPACE, (unsigned char *)&namespace,
+                                   UUID_STR_FORMAT_GUID));
+
+       for (j = 0; data->images[j]; j++) {
+               const char *expected_uuid = data->expected_uuids[j];
+               const u16 *image = data->images[j];
+               efi_guid_t uuid;
+               char uuid_str[37];
+
+               gen_v5_guid(&namespace, &uuid,
+                           data->compatible, strlen(data->compatible),
+                           image, u16_strlen(image) * sizeof(uint16_t),
+                           NULL);
+               uuid_bin_to_str((unsigned char *)&uuid, uuid_str, UUID_STR_FORMAT_GUID);
+
+               ut_asserteq_str(expected_uuid, uuid_str);
+       }
+
+       return 0;
+}
+
+static int lib_test_dynamic_uuid(struct unit_test_state *uts)
+{
+       int ret, i;
+       const struct dynamic_uuid_test_data test_data[] = {
+               {
+                       .compatible = "sandbox",
+                       .images = {
+                               u"SANDBOX-UBOOT",
+                               u"SANDBOX-UBOOT-ENV",
+                               u"SANDBOX-FIT",
+                               NULL,
+                       },
+                       .expected_uuids = {
+                               "985f2937-7c2e-5e9a-8a5e-8e063312964b",
+                               "9e339473-c2eb-530a-a69b-0cd6bbbed40e",
+                               "46610520-469e-59dc-a8dd-c11832b877ea",
+                               NULL,
+                       }
+               },
+               {
+                       .compatible = "qcom,qrb4210-rb2",
+                       .images = {
+                               u"QUALCOMM-UBOOT",
+                               NULL,
+                       },
+                       .expected_uuids = {
+                               "d5021fac-8dd0-5ed7-90c2-763c304aaf86",
+                               NULL,
+                       }
+               },
+       };
+
+       for (i = 0; i < ARRAY_SIZE(test_data); i++) {
+               ret = lib_test_dynamic_uuid_case(uts, &test_data[i]);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
+LIB_TEST(lib_test_dynamic_uuid, 0);