2021-04-12 22:53:07 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Sean Anderson <sean.anderson@seco.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <mmc.h>
|
|
|
|
#include <part.h>
|
|
|
|
#include <part_efi.h>
|
|
|
|
#include <dm/test.h>
|
|
|
|
#include <test/ut.h>
|
|
|
|
|
2023-01-17 17:47:13 +00:00
|
|
|
static int do_test(struct unit_test_state *uts, int expected,
|
|
|
|
const char *part_str, bool whole)
|
2021-05-15 18:13:54 +00:00
|
|
|
{
|
|
|
|
struct blk_desc *mmc_dev_desc;
|
|
|
|
struct disk_partition part_info;
|
|
|
|
|
|
|
|
ut_asserteq(expected,
|
|
|
|
part_get_info_by_dev_and_name_or_num("mmc", part_str,
|
|
|
|
&mmc_dev_desc,
|
|
|
|
&part_info, whole));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-12 22:53:07 +00:00
|
|
|
static int dm_test_part(struct unit_test_state *uts)
|
|
|
|
{
|
2021-05-15 18:13:54 +00:00
|
|
|
char *oldbootdevice;
|
2021-04-12 22:53:07 +00:00
|
|
|
char str_disk_guid[UUID_STR_LEN + 1];
|
2021-05-15 18:13:54 +00:00
|
|
|
int ret;
|
2021-04-12 22:53:07 +00:00
|
|
|
struct blk_desc *mmc_dev_desc;
|
|
|
|
struct disk_partition parts[2] = {
|
|
|
|
{
|
|
|
|
.start = 48, /* GPT data takes up the first 34 blocks or so */
|
|
|
|
.size = 1,
|
|
|
|
.name = "test1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.start = 49,
|
|
|
|
.size = 1,
|
|
|
|
.name = "test2",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-01-17 17:47:22 +00:00
|
|
|
ut_asserteq(2, blk_get_device_by_str("mmc", "2", &mmc_dev_desc));
|
2021-04-12 22:53:07 +00:00
|
|
|
if (CONFIG_IS_ENABLED(RANDOM_UUID)) {
|
|
|
|
gen_rand_uuid_str(parts[0].uuid, UUID_STR_FORMAT_STD);
|
|
|
|
gen_rand_uuid_str(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, parts,
|
|
|
|
ARRAY_SIZE(parts)));
|
|
|
|
|
2021-05-15 18:13:54 +00:00
|
|
|
oldbootdevice = env_get("bootdevice");
|
2021-04-12 22:53:07 +00:00
|
|
|
|
2023-01-17 17:47:13 +00:00
|
|
|
#define test(expected, part_str, whole) \
|
|
|
|
ut_assertok(do_test(uts, expected, part_str, whole))
|
2021-05-15 18:13:54 +00:00
|
|
|
|
|
|
|
env_set("bootdevice", NULL);
|
|
|
|
test(-ENODEV, NULL, true);
|
2021-04-12 22:53:07 +00:00
|
|
|
test(-ENODEV, "", true);
|
|
|
|
env_set("bootdevice", "0");
|
2021-05-15 18:13:54 +00:00
|
|
|
test(0, NULL, true);
|
2021-04-12 22:53:07 +00:00
|
|
|
test(0, "", true);
|
2023-01-17 17:47:22 +00:00
|
|
|
env_set("bootdevice", "2");
|
2021-05-15 18:13:54 +00:00
|
|
|
test(1, NULL, false);
|
2021-04-12 22:53:07 +00:00
|
|
|
test(1, "", false);
|
|
|
|
test(1, "-", false);
|
|
|
|
env_set("bootdevice", "");
|
|
|
|
test(-EPROTONOSUPPORT, "0", false);
|
|
|
|
test(0, "0", true);
|
|
|
|
test(0, ":0", true);
|
|
|
|
test(0, ".0", true);
|
|
|
|
test(0, ".0:0", true);
|
|
|
|
test(-EINVAL, "#test1", true);
|
2023-01-17 17:47:22 +00:00
|
|
|
test(1, "2", false);
|
|
|
|
test(1, "2", true);
|
2021-04-12 22:53:07 +00:00
|
|
|
test(-ENOENT, "1:0", false);
|
|
|
|
test(0, "1:0", true);
|
|
|
|
test(1, "1:1", false);
|
|
|
|
test(2, "1:2", false);
|
|
|
|
test(1, "1.0", false);
|
|
|
|
test(0, "1.0:0", true);
|
|
|
|
test(1, "1.0:1", false);
|
|
|
|
test(2, "1.0:2", false);
|
|
|
|
test(-EINVAL, "1#bogus", false);
|
2023-01-17 17:47:22 +00:00
|
|
|
test(1, "2#test1", false);
|
|
|
|
test(2, "2#test2", false);
|
2021-05-15 18:13:54 +00:00
|
|
|
ret = 0;
|
2021-04-12 22:53:07 +00:00
|
|
|
|
2021-05-15 18:13:54 +00:00
|
|
|
env_set("bootdevice", oldbootdevice);
|
|
|
|
return ret;
|
2021-04-12 22:53:07 +00:00
|
|
|
}
|
|
|
|
DM_TEST(dm_test_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2023-01-17 17:47:41 +00:00
|
|
|
|
|
|
|
static int dm_test_part_bootable(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct blk_desc *desc;
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_BLK, "mmc1.blk", &dev));
|
|
|
|
desc = dev_get_uclass_plat(dev);
|
|
|
|
ut_asserteq(1, part_get_bootable(desc));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_part_bootable, UT_TESTF_SCAN_FDT);
|