efi_selftest: allow to select a single test for execution
[oweals/u-boot.git] / include / efi_selftest.h
1 /*
2  *  EFI application loader
3  *
4  *  Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
5  *
6  *  SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #ifndef _EFI_SELFTEST_H
10 #define _EFI_SELFTEST_H
11
12 #include <common.h>
13 #include <efi.h>
14 #include <efi_api.h>
15 #include <efi_loader.h>
16 #include <linker_lists.h>
17
18 #define EFI_ST_SUCCESS 0
19 #define EFI_ST_FAILURE 1
20
21 /*
22  * Prints an error message.
23  *
24  * @... format string followed by fields to print
25  */
26 #define efi_st_error(...) \
27         (efi_st_printf("%s(%u):\nERROR: ", __FILE__, __LINE__), \
28         efi_st_printf(__VA_ARGS__)) \
29
30 /*
31  * A test may be setup and executed at boottime,
32  * it may be setup at boottime and executed at runtime,
33  * or it may be setup and executed at runtime.
34  */
35 enum efi_test_phase {
36         EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
37         EFI_SETUP_BEFORE_BOOTTIME_EXIT,
38         EFI_SETUP_AFTER_BOOTTIME_EXIT,
39 };
40
41 extern struct efi_simple_text_output_protocol *con_out;
42 extern struct efi_simple_input_interface *con_in;
43
44 /*
45  * Exit the boot services.
46  *
47  * The size of the memory map is determined.
48  * Pool memory is allocated to copy the memory map.
49  * The memory amp is copied and the map key is obtained.
50  * The map key is used to exit the boot services.
51  */
52 void efi_st_exit_boot_services(void);
53
54 /*
55  * Print a pointer to an u16 string
56  *
57  * @pointer: pointer
58  * @buf: pointer to buffer address
59  * on return position of terminating zero word
60  */
61 void efi_st_printf(const char *fmt, ...)
62                  __attribute__ ((format (__printf__, 1, 2)));
63
64 /*
65  * Compare memory.
66  * We cannot use lib/string.c due to different CFLAGS values.
67  *
68  * @buf1:       first buffer
69  * @buf2:       second buffer
70  * @length:     number of bytes to compare
71  * @return:     0 if both buffers contain the same bytes
72  */
73 int efi_st_memcmp(const void *buf1, const void *buf2, size_t length);
74
75 /*
76  * Compare an u16 string to a char string.
77  *
78  * @buf1:       u16 string
79  * @buf2:       char string
80  * @return:     0 if both buffers contain the same bytes
81  */
82 int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2);
83
84 /*
85  * Reads an Unicode character from the input device.
86  *
87  * @return: Unicode character
88  */
89 u16 efi_st_get_key(void);
90
91 /**
92  * struct efi_unit_test - EFI unit test
93  *
94  * An efi_unit_test provides a interface to an EFI unit test.
95  *
96  * @name:       name of unit test
97  * @phase:      specifies when setup and execute are executed
98  * @setup:      set up the unit test
99  * @teardown:   tear down the unit test
100  * @execute:    execute the unit test
101  * @on_request: test is only executed on request
102  */
103 struct efi_unit_test {
104         const char *name;
105         const enum efi_test_phase phase;
106         int (*setup)(const efi_handle_t handle,
107                      const struct efi_system_table *systable);
108         int (*execute)(void);
109         int (*teardown)(void);
110         bool on_request;
111 };
112
113 /* Declare a new EFI unit test */
114 #define EFI_UNIT_TEST(__name)                                           \
115         ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
116
117 #endif /* _EFI_SELFTEST_H */