All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 12/13] efi_selftest: test key notification functions
Date: Tue, 11 Sep 2018 22:38:13 +0200	[thread overview]
Message-ID: <20180911203814.16960-13-xypron.glpk@gmx.de> (raw)
In-Reply-To: <20180911203814.16960-1-xypron.glpk@gmx.de>

Use a key notification function to leave the
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL test.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v3
	no change
v2
	no change
---
 lib/efi_selftest/efi_selftest_textinputex.c | 73 +++++++++++++++++++--
 test/py/tests/test_efi_selftest.py          |  4 +-
 2 files changed, 68 insertions(+), 9 deletions(-)

diff --git a/lib/efi_selftest/efi_selftest_textinputex.c b/lib/efi_selftest/efi_selftest_textinputex.c
index 935bf065c4..d20d8ad89d 100644
--- a/lib/efi_selftest/efi_selftest_textinputex.c
+++ b/lib/efi_selftest/efi_selftest_textinputex.c
@@ -21,6 +21,25 @@ static struct efi_simple_text_input_ex_protocol *con_in_ex;
 
 static struct efi_boot_services *boottime;
 
+static void *efi_key_notify_handle;
+static bool efi_running;
+
+/**
+ * efi_key_notify_function() - key notification function
+ *
+ * This function is called when the registered key is hit.
+ *
+ * @key_data:		next key
+ * Return:		status code
+ */
+static efi_status_t EFIAPI efi_key_notify_function
+				(struct efi_key_data *key_data)
+{
+	efi_running = false;
+
+	return EFI_SUCCESS;
+}
+
 /*
  * Setup unit test.
  *
@@ -32,6 +51,17 @@ static int setup(const efi_handle_t handle,
 		 const struct efi_system_table *systable)
 {
 	efi_status_t ret;
+	struct efi_key_data key_data = {
+		.key = {
+			.scan_code = 0,
+			.unicode_char = 0x18
+		},
+		.key_state = {
+			.key_shift_state = EFI_SHIFT_STATE_VALID |
+					   EFI_LEFT_CONTROL_PRESSED,
+			.key_toggle_state = EFI_TOGGLE_STATE_INVALID,
+		},
+	};
 
 	boottime = systable->boottime;
 
@@ -44,9 +74,41 @@ static int setup(const efi_handle_t handle,
 		return EFI_ST_FAILURE;
 	}
 
+	ret = con_in_ex->register_key_notify(con_in_ex, &key_data,
+					     efi_key_notify_function,
+					     &efi_key_notify_handle);
+	if (ret != EFI_SUCCESS) {
+		efi_key_notify_handle = NULL;
+		efi_st_error
+			("Notify function could not be registered.\n");
+		return EFI_ST_FAILURE;
+	}
+	efi_running = true;
+
 	return EFI_ST_SUCCESS;
 }
 
+/*
+ * Tear down unit test.
+ *
+ * Unregister notify function.
+ *
+ * @return:	EFI_ST_SUCCESS for success
+ */
+static int teardown(void)
+{
+	efi_status_t ret;
+
+	ret = con_in_ex->unregister_key_notify
+			(con_in_ex, efi_key_notify_handle);
+	if (ret != EFI_SUCCESS) {
+		efi_st_error
+			("Notify function could not be registered.\n");
+		return EFI_ST_FAILURE;
+	}
+
+	return EFI_ST_SUCCESS;
+}
 /*
  * Execute unit test.
  *
@@ -76,9 +138,9 @@ static int execute(void)
 	}
 
 	efi_st_printf("Waiting for your input\n");
-	efi_st_printf("To terminate type 'x'\n");
+	efi_st_printf("To terminate type 'CTRL+x'\n");
 
-	for (;;) {
+	while (efi_running) {
 		/* Wait for next key */
 		ret = boottime->wait_for_event(1, &con_in_ex->wait_for_key_ex,
 					       &index);
@@ -122,12 +184,8 @@ static int execute(void)
 		efi_st_printf("%ps)\n",
 			      efi_st_translate_code(input_key.key.scan_code));
 
-		switch (input_key.key.unicode_char) {
-		case 'x':
-		case 'X':
-			return EFI_ST_SUCCESS;
-		}
 	}
+	return EFI_ST_SUCCESS;
 }
 
 EFI_UNIT_TEST(textinputex) = {
@@ -135,5 +193,6 @@ EFI_UNIT_TEST(textinputex) = {
 	.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
 	.setup = setup,
 	.execute = execute,
+	.teardown = teardown,
 	.on_request = true,
 };
diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py
index f84aa4d706..e0833ffe22 100644
--- a/test/py/tests/test_efi_selftest.py
+++ b/test/py/tests/test_efi_selftest.py
@@ -130,7 +130,7 @@ def test_efi_selftest_text_input_ex(u_boot_console):
 	u_boot_console.run_command(cmd='setenv efi_selftest extended text input')
 	output = u_boot_console.run_command(cmd='bootefi selftest',
 					    wait_for_prompt=False)
-	m = u_boot_console.p.expect(['To terminate type \'x\''])
+	m = u_boot_console.p.expect(['To terminate type \'CTRL\+x\''])
 	if m != 0:
 		raise Exception('No prompt for \'text input\' test')
 	u_boot_console.drain_console()
@@ -191,7 +191,7 @@ def test_efi_selftest_text_input_ex(u_boot_console):
 	if m != 0:
 		raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')
 	u_boot_console.drain_console()
-	u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,
+	u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
 				   wait_for_prompt=False)
 	m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
 	if m != 0:
-- 
2.18.0

  parent reply	other threads:[~2018-09-11 20:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-11 20:38 [U-Boot] [PATCH v3 0/13] efi_loader: EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL Heinrich Schuchardt
2018-09-11 20:38 ` [U-Boot] [PATCH v3 01/13] efi_loader: support Unicode text input Heinrich Schuchardt
2018-09-11 21:37   ` Alexander Graf
2018-09-11 21:51     ` [U-Boot] [PATCH v4 " Heinrich Schuchardt
2018-09-11 22:05     ` [U-Boot] [PATCH v5 1/13] " Heinrich Schuchardt
2018-09-11 20:38 ` [U-Boot] [PATCH v3 02/13] test/py: Unicode w/ EFI_SIMPLE_TEXT_INPUT_PROTOCOL Heinrich Schuchardt
2018-09-11 20:38 ` [U-Boot] [PATCH v3 03/13] efi_selftest: refactor text input test Heinrich Schuchardt
2018-09-11 20:38 ` [U-Boot] [PATCH v3 04/13] efi_loader: rework event handling for console Heinrich Schuchardt
2018-09-11 20:38 ` [U-Boot] [PATCH v3 05/13] efi_selftest: use WaitForKey to test text input Heinrich Schuchardt
2018-09-11 20:38 ` [U-Boot] [PATCH v3 06/13] test/py: rework test_efi_selftest_text_input() Heinrich Schuchardt
2018-09-11 20:38 ` [U-Boot] [PATCH v3 07/13] efi_loader: EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL Heinrich Schuchardt
2018-09-11 20:38 ` [U-Boot] [PATCH v3 08/13] efi_loader: support modifiers for F1 - F4 Heinrich Schuchardt
2018-09-11 20:38 ` [U-Boot] [PATCH v3 09/13] efi_selftest: test EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL Heinrich Schuchardt
2018-09-11 20:38 ` [U-Boot] [PATCH v3 10/13] test/py: " Heinrich Schuchardt
2018-09-11 20:38 ` [U-Boot] [PATCH v3 11/13] efi_loader: implement key notify functions Heinrich Schuchardt
2018-09-11 20:38 ` Heinrich Schuchardt [this message]
2018-09-11 20:38 ` [U-Boot] [PATCH v3 13/13] efi_loader: unset CONFIG_EFI_UNICODE_CAPITALIZATION Heinrich Schuchardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180911203814.16960-13-xypron.glpk@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.