1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2020 Sean Anderson <sean.anderson@seco.com>
14 static inline int do_test(struct unit_test_state *uts, int expected,
15 const char *part_str, bool whole)
17 struct blk_desc *mmc_dev_desc;
18 struct disk_partition part_info;
21 part_get_info_by_dev_and_name_or_num("mmc", part_str,
27 static int dm_test_part(struct unit_test_state *uts)
30 char str_disk_guid[UUID_STR_LEN + 1];
32 struct blk_desc *mmc_dev_desc;
33 struct disk_partition parts[2] = {
35 .start = 48, /* GPT data takes up the first 34 blocks or so */
46 ut_asserteq(1, blk_get_device_by_str("mmc", "1", &mmc_dev_desc));
47 if (CONFIG_IS_ENABLED(RANDOM_UUID)) {
48 gen_rand_uuid_str(parts[0].uuid, UUID_STR_FORMAT_STD);
49 gen_rand_uuid_str(parts[1].uuid, UUID_STR_FORMAT_STD);
50 gen_rand_uuid_str(str_disk_guid, UUID_STR_FORMAT_STD);
52 ut_assertok(gpt_restore(mmc_dev_desc, str_disk_guid, parts,
55 oldbootdevice = env_get("bootdevice");
57 #define test(expected, part_str, whole) do { \
58 ret = do_test(uts, expected, part_str, whole); \
63 env_set("bootdevice", NULL);
64 test(-ENODEV, NULL, true);
65 test(-ENODEV, "", true);
66 env_set("bootdevice", "0");
69 env_set("bootdevice", "1");
73 env_set("bootdevice", "");
74 test(-EPROTONOSUPPORT, "0", false);
78 test(0, ".0:0", true);
79 test(-EINVAL, "#test1", true);
82 test(-ENOENT, "1:0", false);
84 test(1, "1:1", false);
85 test(2, "1:2", false);
86 test(1, "1.0", false);
87 test(0, "1.0:0", true);
88 test(1, "1.0:1", false);
89 test(2, "1.0:2", false);
90 test(-EINVAL, "1#bogus", false);
91 test(1, "1#test1", false);
92 test(2, "1#test2", false);
96 env_set("bootdevice", oldbootdevice);
99 DM_TEST(dm_test_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);