diff mbox series

[v2] efi_selftests: fix controllers repeated selftesting

Message ID 20230614065549.143485-1-ilias.apalodimas@linaro.org
State Accepted
Commit 3ae95fe21cbd1e367e6169968ed2497a2ea8561a
Headers show
Series [v2] efi_selftests: fix controllers repeated selftesting | expand

Commit Message

Ilias Apalodimas June 14, 2023, 6:55 a.m. UTC
Running the controller selftest more than one times fails with

=> setenv efi_selftest 'controllers' && bootefi selftest
Testing EFI API implementation
Selected test: 'controllers'
Setting up 'controllers'
Setting up 'controllers' succeeded
Executing 'controllers'
Executing 'controllers' succeeded
Summary: 0 failures

=> bootefi selftest
Testing EFI API implementation
Selected test: 'controllers'
Setting up 'controllers'
lib/efi_selftest/efi_selftest_controllers.c(280):
ERROR: InstallProtocolInterface failed
lib/efi_selftest/efi_selftest.c(89):
ERROR: Setting up 'controllers' failed
Summary: 1 failures

There are multiple reason for this.  We don't uninstall the binding
interface from the controller handle and we don't reset the handle
pointers either.  So let's uninstall all the protocols properly and
reset the handles to NULL on setup().

While at it add a forgotten check when uninstalling protocols from the
handle_controller and make sure the number of child controllers is 0

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
Changes since v1:
- Move the binding protocol removal to .teardown()
- return EFI_ST_FAILURE if the last count_child_controllers() fails

 lib/efi_selftest/efi_selftest_controllers.c | 26 ++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

--
2.39.2

Comments

Heinrich Schuchardt June 14, 2023, 1:25 p.m. UTC | #1
On 6/14/23 08:55, Ilias Apalodimas wrote:
> Running the controller selftest more than one times fails with
>
> => setenv efi_selftest 'controllers' && bootefi selftest
> Testing EFI API implementation
> Selected test: 'controllers'
> Setting up 'controllers'
> Setting up 'controllers' succeeded
> Executing 'controllers'
> Executing 'controllers' succeeded
> Summary: 0 failures
>
> => bootefi selftest
> Testing EFI API implementation
> Selected test: 'controllers'
> Setting up 'controllers'
> lib/efi_selftest/efi_selftest_controllers.c(280):
> ERROR: InstallProtocolInterface failed
> lib/efi_selftest/efi_selftest.c(89):
> ERROR: Setting up 'controllers' failed
> Summary: 1 failures
>
> There are multiple reason for this.  We don't uninstall the binding
> interface from the controller handle and we don't reset the handle
> pointers either.  So let's uninstall all the protocols properly and
> reset the handles to NULL on setup().
>
> While at it add a forgotten check when uninstalling protocols from the
> handle_controller and make sure the number of child controllers is 0
>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
diff mbox series

Patch

diff --git a/lib/efi_selftest/efi_selftest_controllers.c b/lib/efi_selftest/efi_selftest_controllers.c
index d2bbd1c4f65b..79bc86fb0c3a 100644
--- a/lib/efi_selftest/efi_selftest_controllers.c
+++ b/lib/efi_selftest/efi_selftest_controllers.c
@@ -271,6 +271,8 @@  static int setup(const efi_handle_t img_handle,
 	efi_status_t ret;

 	boottime = systable->boottime;
+	handle_controller =  NULL;
+	handle_driver = NULL;

 	/* Create controller handle */
 	ret = boottime->install_protocol_interface(
@@ -402,14 +404,36 @@  static int execute(void)
 	/* Check number of child controllers */
 	ret = count_child_controllers(handle_controller, &guid_controller,
 				      &count);
-	if (ret == EFI_SUCCESS)
+	if (ret == EFI_SUCCESS || count != 0) {
 		efi_st_error("Uninstall failed\n");
+		return EFI_ST_FAILURE;
+	}
+
+
 	return EFI_ST_SUCCESS;
 }

+  /*
+   * Tear down unit test.
+   *
+   */
+static int teardown(void)
+{
+	efi_status_t ret;
+	/* Uninstall binding protocol */
+	ret = boottime->uninstall_protocol_interface(handle_driver,
+						     &guid_driver_binding_protocol,
+						     &binding_interface);
+	if (ret != EFI_SUCCESS)
+		efi_st_error("Failed to uninstall protocols\n");
+
+	return ret;
+}
+
 EFI_UNIT_TEST(controllers) = {
 	.name = "controllers",
 	.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
 	.setup = setup,
 	.execute = execute,
+	.teardown = teardown,
 };