Sean Anderson | 619a182 | 2021-04-12 18:53:07 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2020 Sean Anderson <sean.anderson@seco.com> |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <mmc.h> |
| 9 | #include <part.h> |
| 10 | #include <part_efi.h> |
| 11 | #include <dm/test.h> |
| 12 | #include <test/ut.h> |
| 13 | |
| 14 | static int dm_test_part(struct unit_test_state *uts) |
| 15 | { |
| 16 | char str_disk_guid[UUID_STR_LEN + 1]; |
| 17 | struct blk_desc *mmc_dev_desc; |
| 18 | struct disk_partition part_info; |
| 19 | struct disk_partition parts[2] = { |
| 20 | { |
| 21 | .start = 48, /* GPT data takes up the first 34 blocks or so */ |
| 22 | .size = 1, |
| 23 | .name = "test1", |
| 24 | }, |
| 25 | { |
| 26 | .start = 49, |
| 27 | .size = 1, |
| 28 | .name = "test2", |
| 29 | }, |
| 30 | }; |
| 31 | |
| 32 | ut_asserteq(1, blk_get_device_by_str("mmc", "1", &mmc_dev_desc)); |
| 33 | if (CONFIG_IS_ENABLED(RANDOM_UUID)) { |
| 34 | gen_rand_uuid_str(parts[0].uuid, UUID_STR_FORMAT_STD); |
| 35 | gen_rand_uuid_str(parts[1].uuid, UUID_STR_FORMAT_STD); |
| 36 | gen_rand_uuid_str(str_disk_guid, UUID_STR_FORMAT_STD); |
| 37 | } |
| 38 | ut_assertok(gpt_restore(mmc_dev_desc, str_disk_guid, parts, |
| 39 | ARRAY_SIZE(parts))); |
| 40 | |
| 41 | #define test(expected, part_str, whole) \ |
| 42 | ut_asserteq(expected, \ |
| 43 | part_get_info_by_dev_and_name_or_num("mmc", part_str, \ |
| 44 | &mmc_dev_desc, \ |
| 45 | &part_info, whole)) |
| 46 | |
| 47 | test(-ENODEV, "", true); |
| 48 | env_set("bootdevice", "0"); |
| 49 | test(0, "", true); |
| 50 | env_set("bootdevice", "1"); |
| 51 | test(1, "", false); |
| 52 | test(1, "-", false); |
| 53 | env_set("bootdevice", ""); |
| 54 | test(-EPROTONOSUPPORT, "0", false); |
| 55 | test(0, "0", true); |
| 56 | test(0, ":0", true); |
| 57 | test(0, ".0", true); |
| 58 | test(0, ".0:0", true); |
| 59 | test(-EINVAL, "#test1", true); |
| 60 | test(1, "1", false); |
| 61 | test(1, "1", true); |
| 62 | test(-ENOENT, "1:0", false); |
| 63 | test(0, "1:0", true); |
| 64 | test(1, "1:1", false); |
| 65 | test(2, "1:2", false); |
| 66 | test(1, "1.0", false); |
| 67 | test(0, "1.0:0", true); |
| 68 | test(1, "1.0:1", false); |
| 69 | test(2, "1.0:2", false); |
| 70 | test(-EINVAL, "1#bogus", false); |
| 71 | test(1, "1#test1", false); |
| 72 | test(2, "1#test2", false); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | DM_TEST(dm_test_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |