Blame view

include/efi_selftest.h 3.2 KB
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  /*
   *  EFI application loader
   *
   *  Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
   *
   *  SPDX-License-Identifier:     GPL-2.0+
   */
  
  #ifndef _EFI_SELFTEST_H
  #define _EFI_SELFTEST_H
  
  #include <common.h>
  #include <efi.h>
  #include <efi_api.h>
d78e40d65   Heinrich Schuchardt   efi_selftest: all...
15
  #include <efi_loader.h>
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
16
  #include <linker_lists.h>
e67e7249c   Heinrich Schuchardt   efi_selftest: mak...
17
18
  #define EFI_ST_SUCCESS 0
  #define EFI_ST_FAILURE 1
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
19
  /*
853540c84   Heinrich Schuchardt   efi_selftest: col...
20
21
22
23
24
25
   * Prints a message.
   */
  #define efi_st_printf(...) \
  	(efi_st_printc(-1, __VA_ARGS__))
  
  /*
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
26
27
28
29
30
   * Prints an error message.
   *
   * @...	format string followed by fields to print
   */
  #define efi_st_error(...) \
853540c84   Heinrich Schuchardt   efi_selftest: col...
31
32
33
  	(efi_st_printc(EFI_LIGHTRED, "%s(%u):
  ERROR: ", __FILE__, __LINE__), \
  	efi_st_printc(EFI_LIGHTRED, __VA_ARGS__))
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
34
35
  
  /*
927ca890b   Heinrich Schuchardt   efi_selftest: tes...
36
37
38
39
40
   * Prints a TODO message.
   *
   * @...	format string followed by fields to print
   */
  #define efi_st_todo(...) \
853540c84   Heinrich Schuchardt   efi_selftest: col...
41
42
43
  	(efi_st_printc(EFI_YELLOW, "%s(%u):
  TODO: ", __FILE__, __LINE__), \
  	efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \
927ca890b   Heinrich Schuchardt   efi_selftest: tes...
44
45
  
  /*
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
   * 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);
  
  /*
853540c84   Heinrich Schuchardt   efi_selftest: col...
70
   * Print a colored message
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
71
   *
853540c84   Heinrich Schuchardt   efi_selftest: col...
72
73
74
75
   * @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
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
76
   */
853540c84   Heinrich Schuchardt   efi_selftest: col...
77
78
  void efi_st_printc(int color, const char *fmt, ...)
  		 __attribute__ ((format (__printf__, 2, 3)));
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
79
80
  
  /*
5ca23ed5b   Heinrich Schuchardt   efi_loader: suppl...
81
82
83
84
85
86
87
88
89
90
91
   * 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);
  
  /*
d78e40d65   Heinrich Schuchardt   efi_selftest: all...
92
93
94
95
96
97
98
99
100
   * 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);
  
  /*
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
   * 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
d78e40d65   Heinrich Schuchardt   efi_selftest: all...
117
   * @on_request:	test is only executed on request
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
118
119
120
121
122
123
124
125
   */
  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);
d78e40d65   Heinrich Schuchardt   efi_selftest: all...
126
  	bool on_request;
623b3a579   Heinrich Schuchardt   efi_selftest: pro...
127
128
129
130
131
132
133
  };
  
  /* 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 */