From: Joshua Watt <jpewhacker@gmail.com>
To: u-boot@lists.denx.de
Cc: Joshua Watt <JPEWhacker@gmail.com>, Simon Glass <sjg@chromium.org>
Subject: [PATCH v2 4/5] dm: test: Add test for part_get_info_by_type
Date: Mon, 3 Jul 2023 08:39:55 -0500 [thread overview]
Message-ID: <20230703133959.3880305-5-JPEWhacker@gmail.com> (raw)
In-Reply-To: <20230703133959.3880305-1-JPEWhacker@gmail.com>
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>
---
configs/sandbox_defconfig | 2 +
test/dm/part.c | 87 +++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 1ec44d5b33..cbc5d5b895 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -71,6 +71,7 @@ CONFIG_CMD_GPIO_READ=y
CONFIG_CMD_PWM=y
CONFIG_CMD_GPT=y
CONFIG_CMD_GPT_RENAME=y
+CONFIG_CMD_MBR=y
CONFIG_CMD_IDE=y
CONFIG_CMD_I2C=y
CONFIG_CMD_LOADM=y
@@ -131,6 +132,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
diff --git a/test/dm/part.c b/test/dm/part.c
index 7dd8bc7a3c..d6e4345812 100644
--- a/test/dm/part.c
+++ b/test/dm/part.c
@@ -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);
--
2.33.0
next prev parent reply other threads:[~2023-07-03 13:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-23 19:59 [PATCH 0/2] Fix 'mbr' command with hybrid MBR/GPT Joshua Watt
2023-06-23 19:59 ` [PATCH 1/2] disk: part: Add API to get partitions with specific driver Joshua Watt
2023-06-26 9:07 ` Simon Glass
2023-06-28 13:33 ` Joshua Watt
2023-06-29 19:09 ` Simon Glass
2023-06-23 20:00 ` [PATCH 2/2] cmd: mbr: Force DOS driver to be used for verify Joshua Watt
2023-07-03 13:39 ` [PATCH v2 0/5] Fix 'mbr' command with hybrid MBR/GPT Joshua Watt
2023-07-03 13:39 ` [PATCH v2 1/5] dm: test: Fix partition test to use mmc2 Joshua Watt
2023-07-04 2:40 ` Simon Glass
2023-07-05 0:16 ` Jaehoon Chung
2023-07-18 13:58 ` Tom Rini
2023-07-03 13:39 ` [PATCH v2 2/5] dm: test: Improve partition test error output Joshua Watt
2023-07-04 2:40 ` Simon Glass
2023-07-18 13:58 ` Tom Rini
2023-07-03 13:39 ` [PATCH v2 3/5] disk: part: Add API to get partitions with specific driver Joshua Watt
2023-07-04 2:40 ` Simon Glass
2023-07-18 13:58 ` Tom Rini
2023-07-03 13:39 ` Joshua Watt [this message]
2023-07-04 2:40 ` [PATCH v2 4/5] dm: test: Add test for part_get_info_by_type Simon Glass
2023-07-18 13:58 ` Tom Rini
2023-07-03 13:39 ` [PATCH v2 5/5] cmd: mbr: Force DOS driver to be used for verify Joshua Watt
2023-07-04 2:40 ` Simon Glass
2023-07-18 13:58 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230703133959.3880305-5-JPEWhacker@gmail.com \
--to=jpewhacker@gmail.com \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox