blob: be5ba4bfa91ccc0b8eca88cda6d06c42a3737f3f [file] [log] [blame]
Heinrich Schuchardt623b3a52017-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 Schuchardtd78e40d2017-10-18 18:13:13 +020015#include <efi_loader.h>
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020016#include <linker_lists.h>
17
Heinrich Schuchardte67e7242017-10-04 15:31:26 +020018#define EFI_ST_SUCCESS 0
19#define EFI_ST_FAILURE 1
20
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020021/*
22 * Prints an error message.
23 *
24 * @... format string followed by fields to print
25 */
26#define efi_st_error(...) \
Heinrich Schuchardt9820c2f2017-10-05 16:36:05 +020027 (efi_st_printf("%s(%u):\nERROR: ", __FILE__, __LINE__), \
28 efi_st_printf(__VA_ARGS__)) \
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020029
30/*
Heinrich Schuchardt927ca892017-11-06 21:17:43 +010031 * Prints a TODO message.
32 *
33 * @... format string followed by fields to print
34 */
35#define efi_st_todo(...) \
36 (efi_st_printf("%s(%u):\nTODO: ", __FILE__, __LINE__), \
37 efi_st_printf(__VA_ARGS__)) \
38
39/*
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020040 * A test may be setup and executed at boottime,
41 * it may be setup at boottime and executed at runtime,
42 * or it may be setup and executed at runtime.
43 */
44enum efi_test_phase {
45 EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
46 EFI_SETUP_BEFORE_BOOTTIME_EXIT,
47 EFI_SETUP_AFTER_BOOTTIME_EXIT,
48};
49
50extern struct efi_simple_text_output_protocol *con_out;
51extern struct efi_simple_input_interface *con_in;
52
53/*
54 * Exit the boot services.
55 *
56 * The size of the memory map is determined.
57 * Pool memory is allocated to copy the memory map.
58 * The memory amp is copied and the map key is obtained.
59 * The map key is used to exit the boot services.
60 */
61void efi_st_exit_boot_services(void);
62
63/*
64 * Print a pointer to an u16 string
65 *
66 * @pointer: pointer
67 * @buf: pointer to buffer address
68 * on return position of terminating zero word
69 */
70void efi_st_printf(const char *fmt, ...)
71 __attribute__ ((format (__printf__, 1, 2)));
72
73/*
Heinrich Schuchardt5ca23ed2017-10-05 16:36:07 +020074 * Compare memory.
75 * We cannot use lib/string.c due to different CFLAGS values.
76 *
77 * @buf1: first buffer
78 * @buf2: second buffer
79 * @length: number of bytes to compare
80 * @return: 0 if both buffers contain the same bytes
81 */
82int efi_st_memcmp(const void *buf1, const void *buf2, size_t length);
83
84/*
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +020085 * Compare an u16 string to a char string.
86 *
87 * @buf1: u16 string
88 * @buf2: char string
89 * @return: 0 if both buffers contain the same bytes
90 */
91int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2);
92
93/*
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +020094 * Reads an Unicode character from the input device.
95 *
96 * @return: Unicode character
97 */
98u16 efi_st_get_key(void);
99
100/**
101 * struct efi_unit_test - EFI unit test
102 *
103 * An efi_unit_test provides a interface to an EFI unit test.
104 *
105 * @name: name of unit test
106 * @phase: specifies when setup and execute are executed
107 * @setup: set up the unit test
108 * @teardown: tear down the unit test
109 * @execute: execute the unit test
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +0200110 * @on_request: test is only executed on request
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +0200111 */
112struct efi_unit_test {
113 const char *name;
114 const enum efi_test_phase phase;
115 int (*setup)(const efi_handle_t handle,
116 const struct efi_system_table *systable);
117 int (*execute)(void);
118 int (*teardown)(void);
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +0200119 bool on_request;
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +0200120};
121
122/* Declare a new EFI unit test */
123#define EFI_UNIT_TEST(__name) \
124 ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
125
126#endif /* _EFI_SELFTEST_H */