2018-05-07 21:02:21 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2017-09-15 08:06:11 +00:00
|
|
|
/*
|
|
|
|
* EFI application loader
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _EFI_SELFTEST_H
|
|
|
|
#define _EFI_SELFTEST_H
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <efi.h>
|
|
|
|
#include <efi_api.h>
|
2017-10-18 16:13:13 +00:00
|
|
|
#include <efi_loader.h>
|
2017-09-15 08:06:11 +00:00
|
|
|
#include <linker_lists.h>
|
|
|
|
|
2017-10-04 13:31:26 +00:00
|
|
|
#define EFI_ST_SUCCESS 0
|
|
|
|
#define EFI_ST_FAILURE 1
|
|
|
|
|
2018-01-11 07:15:54 +00:00
|
|
|
/*
|
|
|
|
* Prints a message.
|
|
|
|
*/
|
|
|
|
#define efi_st_printf(...) \
|
|
|
|
(efi_st_printc(-1, __VA_ARGS__))
|
|
|
|
|
2017-09-15 08:06:11 +00:00
|
|
|
/*
|
|
|
|
* Prints an error message.
|
|
|
|
*
|
|
|
|
* @... format string followed by fields to print
|
|
|
|
*/
|
|
|
|
#define efi_st_error(...) \
|
2018-01-11 07:15:54 +00:00
|
|
|
(efi_st_printc(EFI_LIGHTRED, "%s(%u):\nERROR: ", __FILE__, __LINE__), \
|
|
|
|
efi_st_printc(EFI_LIGHTRED, __VA_ARGS__))
|
2017-09-15 08:06:11 +00:00
|
|
|
|
2017-11-06 20:17:43 +00:00
|
|
|
/*
|
|
|
|
* Prints a TODO message.
|
|
|
|
*
|
|
|
|
* @... format string followed by fields to print
|
|
|
|
*/
|
|
|
|
#define efi_st_todo(...) \
|
2018-01-11 07:15:54 +00:00
|
|
|
(efi_st_printc(EFI_YELLOW, "%s(%u):\nTODO: ", __FILE__, __LINE__), \
|
|
|
|
efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \
|
2017-11-06 20:17:43 +00:00
|
|
|
|
2017-09-15 08:06:11 +00:00
|
|
|
/*
|
|
|
|
* A test may be setup and executed at boottime,
|
|
|
|
* it may be setup at boottime and executed at runtime,
|
|
|
|
* or it may be setup and executed at runtime.
|
|
|
|
*/
|
|
|
|
enum efi_test_phase {
|
|
|
|
EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
|
|
|
|
EFI_SETUP_BEFORE_BOOTTIME_EXIT,
|
|
|
|
EFI_SETUP_AFTER_BOOTTIME_EXIT,
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct efi_simple_text_output_protocol *con_out;
|
|
|
|
extern struct efi_simple_input_interface *con_in;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Exit the boot services.
|
|
|
|
*
|
|
|
|
* The size of the memory map is determined.
|
|
|
|
* Pool memory is allocated to copy the memory map.
|
|
|
|
* The memory amp is copied and the map key is obtained.
|
|
|
|
* The map key is used to exit the boot services.
|
|
|
|
*/
|
|
|
|
void efi_st_exit_boot_services(void);
|
|
|
|
|
|
|
|
/*
|
2018-01-11 07:15:54 +00:00
|
|
|
* Print a colored message
|
2017-09-15 08:06:11 +00:00
|
|
|
*
|
2018-01-11 07:15:54 +00:00
|
|
|
* @color color, see constants in efi_api.h, use -1 for no color
|
|
|
|
* @fmt printf format
|
|
|
|
* @... arguments to be printed
|
|
|
|
* on return position of terminating zero word
|
2017-09-15 08:06:11 +00:00
|
|
|
*/
|
2018-01-11 07:15:54 +00:00
|
|
|
void efi_st_printc(int color, const char *fmt, ...)
|
|
|
|
__attribute__ ((format (__printf__, 2, 3)));
|
2017-09-15 08:06:11 +00:00
|
|
|
|
2017-10-05 14:36:07 +00:00
|
|
|
/*
|
|
|
|
* Compare memory.
|
|
|
|
* We cannot use lib/string.c due to different CFLAGS values.
|
|
|
|
*
|
|
|
|
* @buf1: first buffer
|
|
|
|
* @buf2: second buffer
|
|
|
|
* @length: number of bytes to compare
|
|
|
|
* @return: 0 if both buffers contain the same bytes
|
|
|
|
*/
|
|
|
|
int efi_st_memcmp(const void *buf1, const void *buf2, size_t length);
|
|
|
|
|
2017-10-18 16:13:13 +00:00
|
|
|
/*
|
|
|
|
* Compare an u16 string to a char string.
|
|
|
|
*
|
|
|
|
* @buf1: u16 string
|
|
|
|
* @buf2: char string
|
|
|
|
* @return: 0 if both buffers contain the same bytes
|
|
|
|
*/
|
|
|
|
int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2);
|
|
|
|
|
2017-09-15 08:06:11 +00:00
|
|
|
/*
|
|
|
|
* Reads an Unicode character from the input device.
|
|
|
|
*
|
|
|
|
* @return: Unicode character
|
|
|
|
*/
|
|
|
|
u16 efi_st_get_key(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct efi_unit_test - EFI unit test
|
|
|
|
*
|
|
|
|
* An efi_unit_test provides a interface to an EFI unit test.
|
|
|
|
*
|
|
|
|
* @name: name of unit test
|
|
|
|
* @phase: specifies when setup and execute are executed
|
|
|
|
* @setup: set up the unit test
|
|
|
|
* @teardown: tear down the unit test
|
|
|
|
* @execute: execute the unit test
|
2018-04-16 05:59:03 +00:00
|
|
|
* @setup_ok: setup was successful (set at runtime)
|
2017-10-18 16:13:13 +00:00
|
|
|
* @on_request: test is only executed on request
|
2017-09-15 08:06:11 +00:00
|
|
|
*/
|
|
|
|
struct efi_unit_test {
|
|
|
|
const char *name;
|
|
|
|
const enum efi_test_phase phase;
|
|
|
|
int (*setup)(const efi_handle_t handle,
|
|
|
|
const struct efi_system_table *systable);
|
|
|
|
int (*execute)(void);
|
|
|
|
int (*teardown)(void);
|
2018-04-16 05:59:03 +00:00
|
|
|
int setup_ok;
|
2017-10-18 16:13:13 +00:00
|
|
|
bool on_request;
|
2017-09-15 08:06:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Declare a new EFI unit test */
|
|
|
|
#define EFI_UNIT_TEST(__name) \
|
|
|
|
ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
|
|
|
|
|
|
|
|
#endif /* _EFI_SELFTEST_H */
|