1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
15 #include <linux/stringify.h>
17 #define FB_ALIAS_PREFIX "fastboot_partition_alias_"
19 static int dm_test_fastboot_mmc_part(struct unit_test_state *uts)
21 char response[FASTBOOT_RESPONSE_LEN] = {0};
22 char str_disk_guid[UUID_STR_LEN + 1];
23 struct blk_desc *mmc_dev_desc, *fb_dev_desc;
24 struct disk_partition part_info;
25 struct disk_partition parts[2] = {
27 .start = 48, /* GPT data takes up the first 34 blocks or so */
39 * There are a lot of literal 0s I don't want to have to construct from
42 ut_asserteq(0, CONFIG_FASTBOOT_FLASH_MMC_DEV);
43 ut_assertok(blk_get_device_by_str("mmc", "0", &mmc_dev_desc));
44 if (CONFIG_IS_ENABLED(RANDOM_UUID)) {
45 gen_rand_uuid_str(parts[0].uuid, UUID_STR_FORMAT_STD);
46 gen_rand_uuid_str(parts[1].uuid, UUID_STR_FORMAT_STD);
47 gen_rand_uuid_str(str_disk_guid, UUID_STR_FORMAT_STD);
49 ut_assertok(gpt_restore(mmc_dev_desc, str_disk_guid, parts,
52 /* "Classic" partition labels */
53 ut_asserteq(1, fastboot_mmc_get_part_info("test1", &fb_dev_desc,
54 &part_info, response));
55 ut_asserteq(2, fastboot_mmc_get_part_info("test2", &fb_dev_desc,
56 &part_info, response));
59 ut_assertnull(env_get(FB_ALIAS_PREFIX "test3"));
60 ut_assertok(env_set(FB_ALIAS_PREFIX "test3", "test1"));
61 ut_asserteq(1, fastboot_mmc_get_part_info("test3", &fb_dev_desc,
62 &part_info, response));
63 ut_assertok(env_set(FB_ALIAS_PREFIX "test3", NULL));
65 /* "New" partition labels */
66 ut_asserteq(1, fastboot_mmc_get_part_info("#test1", &fb_dev_desc,
67 &part_info, response));
68 ut_asserteq(1, fastboot_mmc_get_part_info("0#test1", &fb_dev_desc,
69 &part_info, response));
70 ut_asserteq(1, fastboot_mmc_get_part_info("0.0#test1", &fb_dev_desc,
71 &part_info, response));
72 ut_asserteq(1, fastboot_mmc_get_part_info("0:1", &fb_dev_desc,
73 &part_info, response));
74 ut_asserteq(1, fastboot_mmc_get_part_info("0.0:1", &fb_dev_desc,
75 &part_info, response));
76 ut_asserteq(1, fastboot_mmc_get_part_info("0", &fb_dev_desc,
77 &part_info, response));
78 ut_asserteq(1, fastboot_mmc_get_part_info("0.0", &fb_dev_desc,
79 &part_info, response));
80 ut_asserteq(0, fastboot_mmc_get_part_info("0:0", &fb_dev_desc,
81 &part_info, response));
82 ut_asserteq(0, fastboot_mmc_get_part_info("0.0:0", &fb_dev_desc,
83 &part_info, response));
84 ut_asserteq(0, fastboot_mmc_get_part_info("1", &fb_dev_desc,
85 &part_info, response));
86 ut_asserteq(0, fastboot_mmc_get_part_info("1.0", &fb_dev_desc,
87 &part_info, response));
88 ut_asserteq(1, fastboot_mmc_get_part_info(":1", &fb_dev_desc,
89 &part_info, response));
90 ut_asserteq(0, fastboot_mmc_get_part_info(":0", &fb_dev_desc,
91 &part_info, response));
95 DM_TEST(dm_test_fastboot_mmc_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);