efi_selftest.h 3.3 KB

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