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 L"SUCCESS"
23 #define efi_st_printf(...) \
24 (efi_st_printc(-1, __VA_ARGS__))
27 * Prints an error message.
29 * @... format string followed by fields to print
31 #define efi_st_error(...) \
32 (efi_st_printc(EFI_LIGHTRED, "%s(%u):\nERROR: ", __FILE__, __LINE__), \
33 efi_st_printc(EFI_LIGHTRED, __VA_ARGS__))
36 * Prints a TODO message.
38 * @... format string followed by fields to print
40 #define efi_st_todo(...) \
41 (efi_st_printc(EFI_YELLOW, "%s(%u):\nTODO: ", __FILE__, __LINE__), \
42 efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \
45 * A test may be setup and executed at boottime,
46 * it may be setup at boottime and executed at runtime,
47 * or it may be setup and executed at runtime.
50 EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
51 EFI_SETUP_BEFORE_BOOTTIME_EXIT,
52 EFI_SETUP_AFTER_BOOTTIME_EXIT,
55 extern struct efi_simple_text_output_protocol *con_out;
56 extern struct efi_simple_text_input_protocol *con_in;
59 * Exit the boot services.
61 * The size of the memory map is determined.
62 * Pool memory is allocated to copy the memory map.
63 * The memory amp is copied and the map key is obtained.
64 * The map key is used to exit the boot services.
66 void efi_st_exit_boot_services(void);
69 * Print a colored message
71 * @color color, see constants in efi_api.h, use -1 for no color
73 * @... arguments to be printed
74 * on return position of terminating zero word
76 void efi_st_printc(int color, const char *fmt, ...)
77 __attribute__ ((format (__printf__, 2, 3)));
80 * efi_st_translate_char() - translate a unicode character to a string
82 * @code: unicode character
85 u16 *efi_st_translate_char(u16 code);
88 * efi_st_translate_code() - translate a scan code to a human readable string
90 * @code: unicode character
93 u16 *efi_st_translate_code(u16 code);
96 * Compare an u16 string to a char string.
100 * @return: 0 if both buffers contain the same bytes
102 int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2);
105 * Reads an Unicode character from the input device.
107 * @return: Unicode character
109 u16 efi_st_get_key(void);
112 * struct efi_unit_test - EFI unit test
114 * An efi_unit_test provides a interface to an EFI unit test.
116 * @name: name of unit test
117 * @phase: specifies when setup and execute are executed
118 * @setup: set up the unit test
119 * @teardown: tear down the unit test
120 * @execute: execute the unit test
121 * @on_request: test is only executed on request
123 struct efi_unit_test {
125 const enum efi_test_phase phase;
126 int (*setup)(const efi_handle_t handle,
127 const struct efi_system_table *systable);
128 int (*execute)(void);
129 int (*teardown)(void);
133 /* Declare a new EFI unit test */
134 #define EFI_UNIT_TEST(__name) \
135 ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
137 #endif /* _EFI_SELFTEST_H */