Re: [PATCH v1 2/2] test: boot: Check that efi_mgr boot failures are reported

Heinrich Schuchardt <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <[email protected]>
On 8/11/26 17:40, Aristo Chen via U-Boot wrote:
> Add a bootstd test for the error path of the efi_mgr bootmeth: point
> BootOrder at a load option that does not exist and check that booting
> the bootflow returns -EIO rather than the generic -EFAULT that
> bootflow_boot() reports when a boot() method returns zero.
> 
> Running the real boot manager initialises the EFI subsystem in the
> sandbox process, which would leak into later tests, so restart U-Boot
> after this test in test_ut.py as is already done for other
> session-changing tests.
> 
> Signed-off-by: Aristo Chen <[email protected]>
> ---
>   test/boot/bootflow.c     | 35 +++++++++++++++++++++++++++++++++++
>   test/py/tests/test_ut.py |  3 ++-
>   2 files changed, 37 insertions(+), 1 deletion(-)
> 
> diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
> index 1cc137c9700..2d80577921f 100644
> --- a/test/boot/bootflow.c
> +++ b/test/boot/bootflow.c
> @@ -470,6 +470,41 @@ static int bootflow_system(struct unit_test_state *uts)
>   }
>   BOOTSTD_TEST(bootflow_system, UTF_DM | UTF_SCAN_PDATA | UTF_SCAN_FDT |
>   	     UTF_CONSOLE);
> +
> +/* Check that a failed 'efi_mgr' boot reports the boot manager's error */
> +static int bootflow_efi_mgr_err(struct unit_test_state *uts)
> +{
> +	struct udevice *bootstd, *dev;
> +	struct bootflow *bflow;
> +	int ret;
> +
> +	if (!IS_ENABLED(CONFIG_EFI_BOOTMGR) || !IS_ENABLED(CONFIG_CMD_EFIDEBUG))
> +		return -EAGAIN;
> +	ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
> +	ut_assertok(device_bind(bootstd, DM_DRIVER_GET(bootmeth_3efi_mgr),
> +				"efi_mgr", 0, ofnode_null(), &dev));
> +	ut_assertok(device_probe(dev));
> +	sandbox_set_fake_efi_mgr_dev(dev, true);
> +
> +	bootstd_clear_glob();
> +	ut_assertok(run_command("bootflow scan -H", 0));
> +
> +	/* Point BootOrder at a load option that does not exist */
> +	ut_assertok(run_command("efidebug boot order 00ff", 0));

It should not be possible to add non-existent boot-options to BootOrder. 
We should fix this in the efidebug command.

Please, do not rely on this buggy behavior.

Best regards

Heinrich

> +
> +	for (ret = bootflow_first_glob(&bflow); !ret;
> +	     ret = bootflow_next_glob(&bflow)) {
> +		if (!strcmp("efi_mgr", bflow->method->name))
> +			break;
> +	}
> +	ut_assertok(ret);
> +
> +	/* The boot manager cannot load anything; its error must not be lost */
> +	ut_asserteq(-EIO, bootflow_boot(bflow));
> +
> +	return 0;
> +}
> +BOOTSTD_TEST(bootflow_efi_mgr_err, UTF_DM | UTF_SCAN_PDATA | UTF_SCAN_FDT);
>   #endif
>   
>   /* Check disabling a bootmethod if it requests it */
> diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
> index fa50c8008a5..787020e3e0c 100644
> --- a/test/py/tests/test_ut.py
> +++ b/test/py/tests/test_ut.py
> @@ -643,7 +643,8 @@ def ut_ubman_fixture(ubman, ut_subtest):
>   
>       yield ubman
>   
> -    if ut_subtest in ("bootstd bootflow_cmd_boot", "bootstd bootflow_scan_boot"):
> +    if ut_subtest in ("bootstd bootflow_cmd_boot", "bootstd bootflow_scan_boot",
> +                      "bootstd bootflow_efi_mgr_err"):
>           ubman.restart_uboot()
>   
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.