1 // SPDX-License-Identifier: GPL-2.0+
3 * efi_selftest_textinput
7 * Provides a unit test for the EFI_SIMPLE_TEXT_INPUT_PROTOCOL.
8 * The Unicode character and the scan code are printed for text
9 * input. To run the test:
11 * setenv efi_selftest text input
15 #include <efi_selftest.h>
17 static struct efi_boot_services *boottime;
22 * @handle: handle of the loaded image
23 * @systable: system table
24 * @return: EFI_ST_SUCCESS for success
26 static int setup(const efi_handle_t handle,
27 const struct efi_system_table *systable)
29 boottime = systable->boottime;
31 return EFI_ST_SUCCESS;
37 * @return: EFI_ST_SUCCESS for success
39 static int execute(void)
41 struct efi_input_key input_key = {0};
45 /* Drain the console input */
46 ret = con_in->reset(con_in, true);
47 if (ret != EFI_SUCCESS) {
48 efi_st_error("Reset failed\n");
49 return EFI_ST_FAILURE;
51 ret = con_in->read_key_stroke(con_in, &input_key);
52 if (ret != EFI_NOT_READY) {
53 efi_st_error("Empty buffer not reported\n");
54 return EFI_ST_FAILURE;
57 efi_st_printf("Waiting for your input\n");
58 efi_st_printf("To terminate type 'x'\n");
61 /* Wait for next key */
62 ret = boottime->wait_for_event(1, &con_in->wait_for_key,
64 if (ret != EFI_ST_SUCCESS) {
65 efi_st_error("WaitForEvent failed\n");
66 return EFI_ST_FAILURE;
68 ret = con_in->read_key_stroke(con_in, &input_key);
69 if (ret != EFI_SUCCESS) {
70 efi_st_error("ReadKeyStroke failed\n");
71 return EFI_ST_FAILURE;
74 /* Allow 5 minutes until time out */
75 boottime->set_watchdog_timer(300, 0, 0, NULL);
77 efi_st_printf("Unicode char %u (%ps), scan code %u (%ps)\n",
78 (unsigned int)input_key.unicode_char,
79 efi_st_translate_char(input_key.unicode_char),
80 (unsigned int)input_key.scan_code,
81 efi_st_translate_code(input_key.scan_code));
83 switch (input_key.unicode_char) {
86 return EFI_ST_SUCCESS;
91 EFI_UNIT_TEST(textinput) = {
93 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,