[PATCH 8/8] efi_loader: Test that active-DMA devices are removed

Simon Glass
2025-01-06T14:49:14Z

When exit-boot-services is called, active devices should be removed.

Update testapp to call this method and check that the USB controller is
removed as expected.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

lib/efi_loader/testapp.c | 9 +++++++++
test/boot/bootflow.c | 11 +++++++++++
2 files changed, 20 insertions(+)

diff --git a/lib/efi_loader/testapp.c b/lib/efi_loader/testapp.c
index 171ecdab043..2c89e14bc5d 100644
--- a/lib/efi_loader/testapp.c
+++ b/lib/efi_loader/testapp.c
@@ -76,6 +76,15 @@ out:
return ret;
}

+ /* exit boot services so that this part of U-Boot can be tested */
+ con_out->output_string(con_out, u"Exiting boot services\n");
+ ret = boottime->exit_boot_services(handle, map_key);
+ if (ret) {
+ con_out->output_string(con_out, u"Failed exit-boot-services\n");
+ return ret;
+ }
+
+ /* now exit for real */
con_out->output_string(con_out, u"Exiting test app\n");
ret = boottime->exit(handle, ret, 0, NULL);

diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 81e81f3cfbf..bd96564c915 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -23,6 +23,7 @@
#endif
#include <dm/device-internal.h>
#include <dm/lists.h>
+#include <dm/uclass-internal.h>
#include <linux/libfdt.h>
#include <test/suites.h>
#include <test/ut.h>
@@ -1279,6 +1280,7 @@ static int bootflow_efi(struct unit_test_state *uts)
struct bootstd_priv *std;
struct udevice *bootstd;
const char **old_order;
+ struct udevice *usb;
int i;

ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
@@ -1315,6 +1317,10 @@ static int bootflow_efi(struct unit_test_state *uts)

systab.fw_vendor = test_vendor;

+ /* the USB block-device should have beeen probed */
+ ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 1, &usb));
+ ut_assert(device_active(usb));
+
ut_asserteq(1, run_command("bootflow boot", 0));
ut_assert_nextline(
"** Booting bootflow 'usb_mass_storage.lun0.bootdev.part_1' with efi");
@@ -1325,6 +1331,7 @@ static int bootflow_efi(struct unit_test_state *uts)

/* TODO: Why the \r ? */
ut_assert_nextline("U-Boot test app for EFI_LOADER\r");
+ ut_assert_nextline("Exiting boot services");
ut_assert_nextline("Exiting test app");
ut_assert_nextline("Boot failed (err=-14)");

@@ -1333,6 +1340,10 @@ static int bootflow_efi(struct unit_test_state *uts)
/* make sure the bootflow is still present */
ut_assertnonnull(std->cur_bootflow);

+ /* the USB block-device should have beeen removed */
+ ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 1, &usb));
+ ut_assert(!device_active(usb));
+
/* check memory allocations are as expected */
if (!hdr)
return 0;
--
2.34.1