efi_selftest.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * EFI application loader
  4. *
  5. * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
  6. */
  7. #ifndef _EFI_SELFTEST_H
  8. #define _EFI_SELFTEST_H
  9. #include <common.h>
  10. #include <efi.h>
  11. #include <efi_api.h>
  12. #include <efi_loader.h>
  13. #include <linker_lists.h>
  14. #define EFI_ST_SUCCESS 0
  15. #define EFI_ST_FAILURE 1
  16. #define EFI_ST_SUCCESS_STR L"SUCCESS"
  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_text_input_protocol *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. * efi_st_translate_char() - translate a unicode character to a string
  71. *
  72. * @code: unicode character
  73. * Return: string
  74. */
  75. u16 *efi_st_translate_char(u16 code);
  76. /**
  77. * efi_st_translate_code() - translate a scan code to a human readable string
  78. *
  79. * @code: unicode character
  80. * Return: string
  81. */
  82. u16 *efi_st_translate_code(u16 code);
  83. /*
  84. * Compare an u16 string to a char string.
  85. *
  86. * @buf1: u16 string
  87. * @buf2: char string
  88. * @return: 0 if both buffers contain the same bytes
  89. */
  90. int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2);
  91. /*
  92. * Reads an Unicode character from the input device.
  93. *
  94. * @return: Unicode character
  95. */
  96. u16 efi_st_get_key(void);
  97. /**
  98. * struct efi_unit_test - EFI unit test
  99. *
  100. * An efi_unit_test provides a interface to an EFI unit test.
  101. *
  102. * @name: name of unit test
  103. * @phase: specifies when setup and execute are executed
  104. * @setup: set up the unit test
  105. * @teardown: tear down the unit test
  106. * @execute: execute the unit test
  107. * @on_request: test is only executed on request
  108. */
  109. struct efi_unit_test {
  110. const char *name;
  111. const enum efi_test_phase phase;
  112. int (*setup)(const efi_handle_t handle,
  113. const struct efi_system_table *systable);
  114. int (*execute)(void);
  115. int (*teardown)(void);
  116. bool on_request;
  117. };
  118. /* Declare a new EFI unit test */
  119. #define EFI_UNIT_TEST(__name) \
  120. ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
  121. #endif /* _EFI_SELFTEST_H */