efi_selftest.h 3.0 KB

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