]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: test: Add test for part_get_info_by_type
authorJoshua Watt <jpewhacker@gmail.com>
Mon, 3 Jul 2023 13:39:55 +0000 (08:39 -0500)
committerTom Rini <trini@konsulko.com>
Mon, 17 Jul 2023 20:19:47 +0000 (16:19 -0400)
Adds a test suite to ensure that part_get_info_by_type works correctly
by creating a hybrid GPT/MBR partition table and reading both.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
[trini: Add this on the other sandbox configs]
Signedd-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
configs/sandbox64_defconfig
configs/sandbox_defconfig
configs/sandbox_flattree_defconfig
configs/sandbox_noinst_defconfig
configs/sandbox_spl_defconfig
configs/sandbox_vpl_defconfig
test/dm/part.c

index 98b3e0cda44c7e957e487b5e1bc71e837c0c0204..9bd81c1d03c4fa6c72bf4166802b5e09f08e2364 100644 (file)
@@ -51,6 +51,7 @@ CONFIG_CMD_GPT_RENAME=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_LOADM=y
+CONFIG_CMD_MBR=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_READ=y
index 4cef6c515396eb9a5a9a2721344aa0e4a3623fbf..19cc6701e62961d97e0950ae1dcb6a8fd4bfdf28 100644 (file)
@@ -76,6 +76,7 @@ CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_LOADM=y
 CONFIG_CMD_LSBLK=y
+CONFIG_CMD_MBR=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_MUX=y
 CONFIG_CMD_OSD=y
@@ -132,6 +133,7 @@ CONFIG_CMD_MTDPARTS=y
 CONFIG_CMD_STACKPROTECTOR_TEST=y
 CONFIG_MAC_PARTITION=y
 CONFIG_AMIGA_PARTITION=y
+CONFIG_DOS_PARTITION=y
 CONFIG_OF_CONTROL=y
 CONFIG_OF_LIVE=y
 CONFIG_ENV_IS_NOWHERE=y
index e7657d40dc510c4a8e45882f564bc581f7d71f61..8aa295686dcf73ae4aadb12577a9be2ae3f126e0 100644 (file)
@@ -44,6 +44,7 @@ CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_MBR=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
index fc20317ac8ba557791a269e579fa15ddd5d58582..2c6aab6c859e230f0a8a34b15fcf992f16d75f31 100644 (file)
@@ -59,6 +59,7 @@ CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_MBR=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_REMOTEPROC=y
index dd848c57c6bfc4145fa118abb0032b3f8c4f5f31..8d50162b274ab07f13c3717db0b0d98f4e0857e9 100644 (file)
@@ -60,6 +60,7 @@ CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_MBR=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_REMOTEPROC=y
index 27971c018a3e61e4a38eea81e43891c24914c6e3..f3a0fd19a9668f613417d72d1c30d7a71a38e352 100644 (file)
@@ -75,6 +75,7 @@ CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_MBR=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_REMOTEPROC=y
index 7dd8bc7a3c4ebebaef11fc2268433613a1d9d50f..d6e4345812748f6d12e85db8061dce47a2b9c7cd 100644 (file)
@@ -108,3 +108,90 @@ static int dm_test_part_bootable(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_part_bootable, UT_TESTF_SCAN_FDT);
+
+static int do_get_info_test(struct unit_test_state *uts,
+                           struct blk_desc *dev_desc, int part, int part_type,
+                           struct disk_partition const *reference)
+{
+       struct disk_partition p;
+       int ret;
+
+       memset(&p, 0, sizeof(p));
+
+       ret = part_get_info_by_type(dev_desc, part, part_type, &p);
+       printf("part_get_info_by_type(%d, 0x%x) = %d\n", part, part_type, ret);
+       if (ut_assertok(ret)) {
+               return 0;
+       }
+
+       ut_asserteq(reference->start, p.start);
+       ut_asserteq(reference->size, p.size);
+       ut_asserteq(reference->sys_ind, p.sys_ind);
+
+       return 0;
+}
+
+static int dm_test_part_get_info_by_type(struct unit_test_state *uts)
+{
+       char str_disk_guid[UUID_STR_LEN + 1];
+       struct blk_desc *mmc_dev_desc;
+       struct disk_partition gpt_parts[] = {
+               {
+                       .start = 48, /* GPT data takes up the first 34 blocks or so */
+                       .size = 1,
+                       .name = "test1",
+                       .sys_ind = 0,
+               },
+               {
+                       .start = 49,
+                       .size = 1,
+                       .name = "test2",
+                       .sys_ind = 0,
+               },
+       };
+       struct disk_partition mbr_parts[] = {
+               {
+                       .start = 1,
+                       .size = 33,
+                       .name = "gpt",
+                       .sys_ind = EFI_PMBR_OSTYPE_EFI_GPT,
+               },
+               {
+                       .start = 48,
+                       .size = 1,
+                       .name = "test1",
+                       .sys_ind = 0x83,
+               },
+       };
+
+       ut_asserteq(2, blk_get_device_by_str("mmc", "2", &mmc_dev_desc));
+       if (CONFIG_IS_ENABLED(RANDOM_UUID)) {
+               gen_rand_uuid_str(gpt_parts[0].uuid, UUID_STR_FORMAT_STD);
+               gen_rand_uuid_str(gpt_parts[1].uuid, UUID_STR_FORMAT_STD);
+               gen_rand_uuid_str(str_disk_guid, UUID_STR_FORMAT_STD);
+       }
+       ut_assertok(gpt_restore(mmc_dev_desc, str_disk_guid, gpt_parts,
+                               ARRAY_SIZE(gpt_parts)));
+
+       ut_assertok(write_mbr_partitions(mmc_dev_desc, mbr_parts,
+                                        ARRAY_SIZE(mbr_parts), 0));
+
+#define get_info_test(_part, _part_type, _reference) \
+       ut_assertok(do_get_info_test(uts, mmc_dev_desc, _part, _part_type, \
+                                    _reference))
+
+       for (int i = 0; i < ARRAY_SIZE(gpt_parts); i++) {
+               get_info_test(i + 1, PART_TYPE_UNKNOWN, &gpt_parts[i]);
+       }
+
+       for (int i = 0; i < ARRAY_SIZE(mbr_parts); i++) {
+               get_info_test(i + 1, PART_TYPE_DOS, &mbr_parts[i]);
+       }
+
+       for (int i = 0; i < ARRAY_SIZE(gpt_parts); i++) {
+               get_info_test(i + 1, PART_TYPE_EFI, &gpt_parts[i]);
+       }
+
+       return 0;
+}
+DM_TEST(dm_test_part_get_info_by_type, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);