]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
test: dm: part: add test for part_get_info_by_uuid
authorDario Binacchi <dario.binacchi@amarulasolutions.com>
Thu, 30 Apr 2026 08:06:03 +0000 (10:06 +0200)
committerPatrice Chotard <patrice.chotard@foss.st.com>
Tue, 12 May 2026 13:52:01 +0000 (15:52 +0200)
Add a new unit test for the part_get_info_by_uuid() function.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
test/dm/part.c

index caae23bd4aadf0cbafacc5f5b9476d2add6333a1..ad37d7f406f4f1afa6b4e87a1dbaaf0145766685 100644 (file)
@@ -195,3 +195,56 @@ static int dm_test_part_get_info_by_type(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_part_get_info_by_type, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+static int dm_test_part_get_info_by_uuid(struct unit_test_state *uts)
+{
+       struct disk_partition parts[] = {
+               {
+                       .start = 48,
+                       .size = 1,
+                       .name = "test1",
+                       .uuid = "c5bce7a2-03f0-4d03-9048-01ff23b9d527",
+               },
+               {
+                       .start = 49,
+                       .size = 1,
+                       .name = "test2",
+                       .uuid = "9df346e8-2c53-4cd8-b9ac-3af83f9a9b74",
+               },
+       };
+       char disk_guid[UUID_STR_LEN + 1] =
+               "8d60b397-1bb6-4d33-80ee-b1587d24c2f8";
+       struct blk_desc *mmc_dev_desc;
+       struct disk_partition info;
+       int part, i;
+
+       ut_asserteq(2, blk_get_device_by_str("mmc", "2", &mmc_dev_desc));
+
+       if (CONFIG_IS_ENABLED(RANDOM_UUID)) {
+               for (i = 0; i < ARRAY_SIZE(parts); i++)
+                       gen_rand_uuid_str(parts[i].uuid, UUID_STR_FORMAT_STD);
+
+               gen_rand_uuid_str(disk_guid, UUID_STR_FORMAT_STD);
+       }
+
+       ut_assertok(gpt_restore(mmc_dev_desc, disk_guid, parts,
+                               ARRAY_SIZE(parts)));
+
+       for (i = 0; i < ARRAY_SIZE(parts); i++) {
+               part = part_get_info_by_uuid(mmc_dev_desc, parts[i].uuid,
+                                            &info);
+
+               ut_asserteq(i + 1, part);
+               ut_asserteq_str(parts[i].name, info.name);
+               ut_asserteq(parts[i].start, info.start);
+               ut_asserteq(parts[i].size, info.size);
+       }
+
+       part = part_get_info_by_uuid(mmc_dev_desc,
+                                    "00000000-0000-0000-0000-000000000000",
+                                    &info);
+       ut_assert(part < 0);
+
+       return 0;
+}
+DM_TEST(dm_test_part_get_info_by_uuid, UTF_SCAN_PDATA | UTF_SCAN_FDT);