bootstd: Add a test for bootmeth_cros

The ChromiumOS bootmeth has no tests at present. Before adding more
features. add a basic test.

This creates a disk which can be scanned by the bootmeth, so make sure
things work. It is quite rudimentary, since the kernel is faked, the root
disk is missing and there is no cmdline stored.

Enable the bootmeth for snow so it can build the unit test.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2023-08-24 13:55:41 -06:00 committed by Tom Rini
parent 2b9adcaca2
commit d08db02d2d
4 changed files with 183 additions and 2 deletions

View file

@ -27,6 +27,7 @@
DECLARE_GLOBAL_DATA_PTR;
extern U_BOOT_DRIVER(bootmeth_cros);
extern U_BOOT_DRIVER(bootmeth_script);
static int inject_response(struct unit_test_state *uts)
@ -514,7 +515,8 @@ BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
* @mmc_dev: MMC device to use, e.g. "mmc4"
* Returns 0 on success, -ve on failure
*/
static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev)
static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
bool bind_cros)
{
const char *order[] = {"mmc2", "mmc1", mmc_dev, NULL};
struct udevice *dev, *bootstd;
@ -533,6 +535,13 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev)
ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_script),
"bootmeth_script", 0, ofnode_null(), &dev));
/* Enable the cros bootmeth if needed */
if (bind_cros) {
ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_cros),
"cros", 0, ofnode_null(), &dev));
}
/* Change the order to include the device */
std = dev_get_priv(bootstd);
old_order = std->bootdev_order;
@ -556,7 +565,7 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev)
*/
static int prep_mmc4_bootdev(struct unit_test_state *uts)
{
ut_assertok(prep_mmc_bootdev(uts, "mmc4"));
ut_assertok(prep_mmc_bootdev(uts, "mmc4", false));
return 0;
}
@ -963,3 +972,23 @@ static int bootflow_cmdline(struct unit_test_state *uts)
return 0;
}
BOOTSTD_TEST(bootflow_cmdline, 0);
/* Test ChromiumOS bootmeth */
static int bootflow_cros(struct unit_test_state *uts)
{
ut_assertok(prep_mmc_bootdev(uts, "mmc5", true));
ut_assertok(run_command("bootflow list", 0));
ut_assert_nextlinen("Showing all");
ut_assert_nextlinen("Seq");
ut_assert_nextlinen("---");
ut_assert_nextlinen(" 0 extlinux");
ut_assert_nextlinen(" 1 cros ready mmc 2 mmc5.bootdev.whole ");
ut_assert_nextlinen("---");
ut_assert_skip_to_line("(2 bootflows, 2 valid)");
ut_assert_console_end();
return 0;
}
BOOTSTD_TEST(bootflow_cros, 0);