efi_selftest.h 3.3 KB

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