test.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2010 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_TEST_HEADER
  19. #define GRUB_TEST_HEADER
  20. #include <grub/dl.h>
  21. #include <grub/list.h>
  22. #include <grub/misc.h>
  23. #include <grub/types.h>
  24. #include <grub/symbol.h>
  25. #include <grub/video.h>
  26. #include <grub/video_fb.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. struct grub_test
  31. {
  32. /* The next test. */
  33. struct grub_test *next;
  34. struct grub_test **prev;
  35. /* The test name. */
  36. char *name;
  37. /* The test main function. */
  38. void (*main) (void);
  39. };
  40. typedef struct grub_test *grub_test_t;
  41. extern grub_test_t grub_test_list;
  42. void grub_test_register (const char *name, void (*test) (void));
  43. void grub_test_unregister (const char *name);
  44. /* Execute a test and print results. */
  45. int grub_test_run (grub_test_t test);
  46. /* Test `cond' for nonzero; log failure otherwise. */
  47. void grub_test_nonzero (int cond, const char *file,
  48. const char *func, grub_uint32_t line,
  49. const char *fmt, ...)
  50. __attribute__ ((format (GNU_PRINTF, 5, 6)));
  51. /* Macro to fill in location details and an optional error message. */
  52. void grub_test_assert_helper (int cond, const char *file,
  53. const char *func, grub_uint32_t line,
  54. const char *condstr, const char *fmt, ...)
  55. __attribute__ ((format (GNU_PRINTF, 6, 7)));
  56. #define grub_test_assert(cond, ...) \
  57. grub_test_assert_helper(cond, GRUB_FILE, __FUNCTION__, __LINE__, \
  58. #cond, ## __VA_ARGS__);
  59. void grub_unit_test_init (void);
  60. void grub_unit_test_fini (void);
  61. /* Macro to define a unit test. */
  62. #define GRUB_UNIT_TEST(name, funp) \
  63. void grub_unit_test_init (void) \
  64. { \
  65. grub_test_register (name, funp); \
  66. } \
  67. \
  68. void grub_unit_test_fini (void) \
  69. { \
  70. grub_test_unregister (name); \
  71. }
  72. /* Macro to define a functional test. */
  73. #define GRUB_FUNCTIONAL_TEST(name, funp) \
  74. GRUB_MOD_INIT(name) \
  75. { \
  76. grub_test_register (#name, funp); \
  77. } \
  78. \
  79. GRUB_MOD_FINI(name) \
  80. { \
  81. grub_test_unregister (#name); \
  82. }
  83. void
  84. grub_video_checksum (const char *basename_in);
  85. void
  86. grub_video_checksum_end (void);
  87. void
  88. grub_terminal_input_fake_sequence (int *seq_in, int nseq_in);
  89. void
  90. grub_terminal_input_fake_sequence_end (void);
  91. const char *
  92. grub_video_checksum_get_modename (void);
  93. #define GRUB_TEST_VIDEO_SMALL_N_MODES 7
  94. #define GRUB_TEST_VIDEO_ALL_N_MODES 31
  95. extern struct grub_video_mode_info grub_test_video_modes[GRUB_TEST_VIDEO_ALL_N_MODES];
  96. int
  97. grub_test_use_gfxterm (void);
  98. void grub_test_use_gfxterm_end (void);
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif /* ! GRUB_TEST_HEADER */