efi_selftest.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <linker_lists.h>
  14. #define EFI_ST_SUCCESS 0
  15. #define EFI_ST_FAILURE 1
  16. /*
  17. * Prints an error message.
  18. *
  19. * @... format string followed by fields to print
  20. */
  21. #define efi_st_error(...) \
  22. (efi_st_printf("%s(%u):\nERROR: ", __FILE__, __LINE__), \
  23. efi_st_printf(__VA_ARGS__)) \
  24. /*
  25. * A test may be setup and executed at boottime,
  26. * it may be setup at boottime and executed at runtime,
  27. * or it may be setup and executed at runtime.
  28. */
  29. enum efi_test_phase {
  30. EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
  31. EFI_SETUP_BEFORE_BOOTTIME_EXIT,
  32. EFI_SETUP_AFTER_BOOTTIME_EXIT,
  33. };
  34. extern struct efi_simple_text_output_protocol *con_out;
  35. extern struct efi_simple_input_interface *con_in;
  36. /*
  37. * Exit the boot services.
  38. *
  39. * The size of the memory map is determined.
  40. * Pool memory is allocated to copy the memory map.
  41. * The memory amp is copied and the map key is obtained.
  42. * The map key is used to exit the boot services.
  43. */
  44. void efi_st_exit_boot_services(void);
  45. /*
  46. * Print a pointer to an u16 string
  47. *
  48. * @pointer: pointer
  49. * @buf: pointer to buffer address
  50. * on return position of terminating zero word
  51. */
  52. void efi_st_printf(const char *fmt, ...)
  53. __attribute__ ((format (__printf__, 1, 2)));
  54. /*
  55. * Reads an Unicode character from the input device.
  56. *
  57. * @return: Unicode character
  58. */
  59. u16 efi_st_get_key(void);
  60. /**
  61. * struct efi_unit_test - EFI unit test
  62. *
  63. * An efi_unit_test provides a interface to an EFI unit test.
  64. *
  65. * @name: name of unit test
  66. * @phase: specifies when setup and execute are executed
  67. * @setup: set up the unit test
  68. * @teardown: tear down the unit test
  69. * @execute: execute the unit test
  70. */
  71. struct efi_unit_test {
  72. const char *name;
  73. const enum efi_test_phase phase;
  74. int (*setup)(const efi_handle_t handle,
  75. const struct efi_system_table *systable);
  76. int (*execute)(void);
  77. int (*teardown)(void);
  78. };
  79. /* Declare a new EFI unit test */
  80. #define EFI_UNIT_TEST(__name) \
  81. ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
  82. #endif /* _EFI_SELFTEST_H */