1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * EFI application loader
5 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
8 #ifndef _EFI_SELFTEST_H
9 #define _EFI_SELFTEST_H
14 #include <efi_loader.h>
15 #include <linker_lists.h>
17 #define EFI_ST_SUCCESS 0
18 #define EFI_ST_FAILURE 1
19 #define EFI_ST_SUCCESS_STR u"SUCCESS"
21 extern const struct efi_system_table *st_systable;
22 extern const struct efi_boot_services *st_boottime;
25 * efi_st_printf() - print a message
27 * @...: format string followed by fields to print
29 #define efi_st_printf(...) \
30 (efi_st_printc(-1, __VA_ARGS__))
33 * efi_st_error() - prints an error message
35 * @...: format string followed by fields to print
37 #define efi_st_error(...) \
38 (efi_st_printc(EFI_LIGHTRED, "%s(%u):\nERROR: ", __FILE__, __LINE__), \
39 efi_st_printc(EFI_LIGHTRED, __VA_ARGS__))
42 * efi_st_todo() - prints a TODO message
44 * @...: format string followed by fields to print
46 #define efi_st_todo(...) \
47 (efi_st_printc(EFI_YELLOW, "%s(%u):\nTODO: ", __FILE__, __LINE__), \
48 efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \
51 * enum efi_test_phase - phase when test will be executed
53 * A test may be setup and executed at boottime,
54 * it may be setup at boottime and executed at runtime,
55 * or it may be setup and executed at runtime.
59 * @EFI_EXECUTE_BEFORE_BOOTTIME_EXIT:
61 * Setup, execute, and teardown are executed before ExitBootServices().
63 EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
65 * @EFI_SETUP_BEFORE_BOOTTIME_EXIT:
67 * Setup is executed before ExitBootServices() while execute, and
68 * teardown are executed after ExitBootServices().
70 EFI_SETUP_BEFORE_BOOTTIME_EXIT,
72 * @EFI_SETTING_VIRTUAL_ADDRESS_MAP:
74 * Execute calls SetVirtualAddressMap(). Setup is executed before
75 * ExitBootServices() while execute is executed after
76 * ExitBootServices(), and after the execute of tests marked as
77 * @EFI_SETUP_BEFORE_BOOTTIME_EXIT. Teardown is executed thereafter.
79 EFI_SETTING_VIRTUAL_ADDRESS_MAP,
82 extern struct efi_simple_text_output_protocol *con_out;
83 extern struct efi_simple_text_input_protocol *con_in;
86 * efi_st_exit_boot_services() - exit the boot services
88 * * The size of the memory map is determined.
89 * * Pool memory is allocated to copy the memory map.
90 * * The memory map is copied and the map key is obtained.
91 * * The map key is used to exit the boot services.
93 void efi_st_exit_boot_services(void);
96 * efi_st_printc() - print a colored message
98 * @color: color, see constants in efi_api.h, use -1 for no color
99 * @fmt: printf style format string
100 * @...: arguments to be printed
102 void efi_st_printc(int color, const char *fmt, ...)
103 __attribute__ ((format (__printf__, 2, 3)));
106 * efi_st_translate_char() - translate a Unicode character to a string
108 * @code: Unicode character
111 u16 *efi_st_translate_char(u16 code);
114 * efi_st_translate_code() - translate a scan code to a human readable string
116 * This function translates the scan code returned by the simple text input
117 * protocol to a human readable string, e.g. 0x04 is translated to u"Left".
120 * Return: Unicode string
122 u16 *efi_st_translate_code(u16 code);
125 * efi_st_strcmp_16_8() - compare an u16 string to a char string
127 * This function compares each u16 value to the char value at the same
128 * position. This function is only useful for ANSI strings.
132 * Return: 0 if both buffers contain equivalent strings
134 int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2);
137 * efi_st_get_config_table() - get configuration table
139 * @guid: GUID of the configuration table
140 * Return: pointer to configuration table or NULL
142 void *efi_st_get_config_table(const efi_guid_t *guid);
145 * efi_st_get_key() - reads an Unicode character from the input device
147 * Return: Unicode character
149 u16 efi_st_get_key(void);
152 * struct efi_unit_test - EFI unit test
154 * The &struct efi_unit_test structure provides a interface to an EFI unit test.
156 * @name: name of the unit test used in the user interface
157 * @phase: specifies when setup and execute are executed
158 * @setup: set up function of the unit test
159 * @execute: execute function of the unit test
160 * @teardown: tear down function of the unit test
161 * @on_request: flag indicating that the test shall only be executed on request
163 struct efi_unit_test {
165 const enum efi_test_phase phase;
166 int (*setup)(const efi_handle_t handle,
167 const struct efi_system_table *systable);
168 int (*execute)(void);
169 int (*teardown)(void);
174 * EFI_UNIT_TEST() - macro to declare a new EFI unit test
176 * The macro EFI_UNIT_TEST() declares an EFI unit test using the &struct
177 * efi_unit_test structure. The test is added to a linker generated list which
178 * is evaluated by the 'bootefi selftest' command.
180 * @__name: string identifying the unit test in the linker generated list
182 #define EFI_UNIT_TEST(__name) \
183 ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
185 #endif /* _EFI_SELFTEST_H */