2 * EFI application loader
4 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 * SPDX-License-Identifier: GPL-2.0+
9 #ifndef _EFI_SELFTEST_H
10 #define _EFI_SELFTEST_H
15 #include <efi_loader.h>
16 #include <linker_lists.h>
18 #define EFI_ST_SUCCESS 0
19 #define EFI_ST_FAILURE 1
24 #define efi_st_printf(...) \
25 (efi_st_printc(-1, __VA_ARGS__))
28 * Prints an error message.
30 * @... format string followed by fields to print
32 #define efi_st_error(...) \
33 (efi_st_printc(EFI_LIGHTRED, "%s(%u):\nERROR: ", __FILE__, __LINE__), \
34 efi_st_printc(EFI_LIGHTRED, __VA_ARGS__))
37 * Prints a TODO message.
39 * @... format string followed by fields to print
41 #define efi_st_todo(...) \
42 (efi_st_printc(EFI_YELLOW, "%s(%u):\nTODO: ", __FILE__, __LINE__), \
43 efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \
46 * A test may be setup and executed at boottime,
47 * it may be setup at boottime and executed at runtime,
48 * or it may be setup and executed at runtime.
51 EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
52 EFI_SETUP_BEFORE_BOOTTIME_EXIT,
53 EFI_SETUP_AFTER_BOOTTIME_EXIT,
56 extern struct efi_simple_text_output_protocol *con_out;
57 extern struct efi_simple_input_interface *con_in;
60 * Exit the boot services.
62 * The size of the memory map is determined.
63 * Pool memory is allocated to copy the memory map.
64 * The memory amp is copied and the map key is obtained.
65 * The map key is used to exit the boot services.
67 void efi_st_exit_boot_services(void);
70 * Print a colored message
72 * @color color, see constants in efi_api.h, use -1 for no color
74 * @... arguments to be printed
75 * on return position of terminating zero word
77 void efi_st_printc(int color, const char *fmt, ...)
78 __attribute__ ((format (__printf__, 2, 3)));
82 * We cannot use lib/string.c due to different CFLAGS values.
85 * @buf2: second buffer
86 * @length: number of bytes to compare
87 * @return: 0 if both buffers contain the same bytes
89 int efi_st_memcmp(const void *buf1, const void *buf2, size_t length);
92 * Compare an u16 string to a char string.
96 * @return: 0 if both buffers contain the same bytes
98 int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2);
101 * Reads an Unicode character from the input device.
103 * @return: Unicode character
105 u16 efi_st_get_key(void);
108 * struct efi_unit_test - EFI unit test
110 * An efi_unit_test provides a interface to an EFI unit test.
112 * @name: name of unit test
113 * @phase: specifies when setup and execute are executed
114 * @setup: set up the unit test
115 * @teardown: tear down the unit test
116 * @execute: execute the unit test
117 * @on_request: test is only executed on request
119 struct efi_unit_test {
121 const enum efi_test_phase phase;
122 int (*setup)(const efi_handle_t handle,
123 const struct efi_system_table *systable);
124 int (*execute)(void);
125 int (*teardown)(void);
129 /* Declare a new EFI unit test */
130 #define EFI_UNIT_TEST(__name) \
131 ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
133 #endif /* _EFI_SELFTEST_H */