summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2018-09-11 22:38:13 +0200
committerAlexander Graf <agraf@suse.de>2018-09-23 21:55:30 +0200
commit6dec87396e4780b8148664908345e8e61273ea2e (patch)
tree678b6fedbdc69c1f4d9907cf5312adfad52a2422 /lib
parent4fdcf0664842b6e289f1421d1a68e8797da5e4ef (diff)
efi_selftest: test key notification functions
Use a key notification function to leave the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL test. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/efi_selftest/efi_selftest_textinputex.c73
1 files changed, 66 insertions, 7 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,10 +74,42 @@ 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.
*
* @return: EFI_ST_SUCCESS for success
@@ -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,
};