test-runner.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright © 2012 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the
  13. * next paragraph) shall be included in all copies or substantial
  14. * portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. */
  25. #ifndef _TEST_RUNNER_H_
  26. #define _TEST_RUNNER_H_
  27. #ifdef NDEBUG
  28. #error "Tests must not be built with NDEBUG defined, they rely on assert()."
  29. #endif
  30. #include <unistd.h>
  31. struct test {
  32. const char *name;
  33. void (*run)(void);
  34. int must_fail;
  35. } __attribute__ ((aligned (16)));
  36. #define TEST(name) \
  37. static void name(void); \
  38. \
  39. const struct test test##name \
  40. __attribute__ ((used, section ("test_section"))) = { \
  41. #name, name, 0 \
  42. }; \
  43. \
  44. static void name(void)
  45. #define FAIL_TEST(name) \
  46. static void name(void); \
  47. \
  48. const struct test test##name \
  49. __attribute__ ((used, section ("test_section"))) = { \
  50. #name, name, 1 \
  51. }; \
  52. \
  53. static void name(void)
  54. int
  55. count_open_fds(void);
  56. void
  57. exec_fd_leak_check(int nr_expected_fds); /* never returns */
  58. void
  59. check_fd_leaks(int supposed_fds);
  60. /*
  61. * set/reset the timeout in seconds. The timeout starts
  62. * at the point of invoking this function
  63. */
  64. void
  65. test_set_timeout(unsigned int);
  66. /* test-runner uses alarm() and SIGALRM, so we can not
  67. * use usleep and sleep functions in tests (see 'man usleep'
  68. * or 'man sleep', respectively). Following functions are safe
  69. * to use in tests */
  70. void
  71. test_usleep(useconds_t);
  72. void
  73. test_sleep(unsigned int);
  74. void
  75. test_disable_coredumps(void);
  76. #define DISABLE_LEAK_CHECKS \
  77. do { \
  78. extern int fd_leak_check_enabled; \
  79. fd_leak_check_enabled = 0; \
  80. } while (0);
  81. #endif