blob: c23bc24bed0f5d0935c84bc26c199598606e52d8 [file] [log] [blame]
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +02001/*
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>
Heinrich Schuchardt02efd5d2017-10-18 18:13:13 +020015#include <efi_loader.h>
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020016#include <linker_lists.h>
17
Heinrich Schuchardt1afe5f72017-10-04 15:31:26 +020018#define EFI_ST_SUCCESS 0
19#define EFI_ST_FAILURE 1
20
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020021/*
Heinrich Schuchardt9137df82018-01-11 08:15:54 +010022 * Prints a message.
23 */
24#define efi_st_printf(...) \
25 (efi_st_printc(-1, __VA_ARGS__))
26
27/*
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020028 * Prints an error message.
29 *
30 * @... format string followed by fields to print
31 */
32#define efi_st_error(...) \
Heinrich Schuchardt9137df82018-01-11 08:15:54 +010033 (efi_st_printc(EFI_LIGHTRED, "%s(%u):\nERROR: ", __FILE__, __LINE__), \
34 efi_st_printc(EFI_LIGHTRED, __VA_ARGS__))
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020035
36/*
Heinrich Schuchardtc53591c2017-11-06 21:17:43 +010037 * Prints a TODO message.
38 *
39 * @... format string followed by fields to print
40 */
41#define efi_st_todo(...) \
Heinrich Schuchardt9137df82018-01-11 08:15:54 +010042 (efi_st_printc(EFI_YELLOW, "%s(%u):\nTODO: ", __FILE__, __LINE__), \
43 efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \
Heinrich Schuchardtc53591c2017-11-06 21:17:43 +010044
45/*
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020046 * 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.
49 */
50enum efi_test_phase {
51 EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
52 EFI_SETUP_BEFORE_BOOTTIME_EXIT,
53 EFI_SETUP_AFTER_BOOTTIME_EXIT,
54};
55
56extern struct efi_simple_text_output_protocol *con_out;
57extern struct efi_simple_input_interface *con_in;
58
59/*
60 * Exit the boot services.
61 *
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.
66 */
67void efi_st_exit_boot_services(void);
68
69/*
Heinrich Schuchardt9137df82018-01-11 08:15:54 +010070 * Print a colored message
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020071 *
Heinrich Schuchardt9137df82018-01-11 08:15:54 +010072 * @color color, see constants in efi_api.h, use -1 for no color
73 * @fmt printf format
74 * @... arguments to be printed
75 * on return position of terminating zero word
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020076 */
Heinrich Schuchardt9137df82018-01-11 08:15:54 +010077void efi_st_printc(int color, const char *fmt, ...)
78 __attribute__ ((format (__printf__, 2, 3)));
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +020079
80/*
Heinrich Schuchardt2a6daf72017-10-05 16:36:07 +020081 * Compare memory.
82 * We cannot use lib/string.c due to different CFLAGS values.
83 *
84 * @buf1: first buffer
85 * @buf2: second buffer
86 * @length: number of bytes to compare
87 * @return: 0 if both buffers contain the same bytes
88 */
89int efi_st_memcmp(const void *buf1, const void *buf2, size_t length);
90
91/*
Heinrich Schuchardt02efd5d2017-10-18 18:13:13 +020092 * Compare an u16 string to a char string.
93 *
94 * @buf1: u16 string
95 * @buf2: char string
96 * @return: 0 if both buffers contain the same bytes
97 */
98int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2);
99
100/*
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +0200101 * Reads an Unicode character from the input device.
102 *
103 * @return: Unicode character
104 */
105u16 efi_st_get_key(void);
106
107/**
108 * struct efi_unit_test - EFI unit test
109 *
110 * An efi_unit_test provides a interface to an EFI unit test.
111 *
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
Heinrich Schuchardta9d22602018-04-16 07:59:03 +0200117 * @setup_ok: setup was successful (set at runtime)
Heinrich Schuchardt02efd5d2017-10-18 18:13:13 +0200118 * @on_request: test is only executed on request
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +0200119 */
120struct efi_unit_test {
121 const char *name;
122 const enum efi_test_phase phase;
123 int (*setup)(const efi_handle_t handle,
124 const struct efi_system_table *systable);
125 int (*execute)(void);
126 int (*teardown)(void);
Heinrich Schuchardta9d22602018-04-16 07:59:03 +0200127 int setup_ok;
Heinrich Schuchardt02efd5d2017-10-18 18:13:13 +0200128 bool on_request;
Heinrich Schuchardtd33ae3e2017-09-15 10:06:11 +0200129};
130
131/* Declare a new EFI unit test */
132#define EFI_UNIT_TEST(__name) \
133 ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
134
135#endif /* _EFI_SELFTEST_H */