main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include "test.h"
  4. void test_assert_h(void);
  5. void test_complex_h(void);
  6. void test_ctype_h(void);
  7. void test_errno_h(void);
  8. void test_fenv_h(void);
  9. void test_float_h(void);
  10. void test_inttypes_h(void);
  11. void test_iso646_h(void);
  12. void test_limits_h(void);
  13. void test_locale_h(void);
  14. void test_math_h(void);
  15. void test_setjmp_h(void);
  16. void test_signal_h(void);
  17. void test_stdalign_h(void);
  18. void test_stdarg_h(void);
  19. void test_stdatomic_h(void);
  20. void test_stdbool_h(void);
  21. void test_stddef_h(void);
  22. void test_stdint_h(void);
  23. void test_stdio_h(void);
  24. void test_stdlib_h(void);
  25. void test_stdnoreturn_h(void);
  26. void test_string_h(void);
  27. void test_tgmath_h(void);
  28. void test_threads_h(void);
  29. void test_time_h(void);
  30. void test_uchar_h(void);
  31. void test_wchar_h(void);
  32. void test_wctype_h(void);
  33. static struct {
  34. char *name;
  35. void (*fn)(void);
  36. int run;
  37. } tests[] = {
  38. { "assert", test_assert_h, 0 },
  39. { "complex", test_complex_h, 1 },
  40. { "ctype", test_ctype_h, 1 },
  41. { "errno", test_errno_h, 1 },
  42. { "fenv", test_fenv_h, 1 },
  43. { "float", test_float_h, 1 },
  44. { "inttypes", test_inttypes_h, 1 },
  45. { "iso646", test_iso646_h, 1 },
  46. { "limits", test_limits_h, 1 },
  47. { "locale", test_locale_h, 1 },
  48. { "math", test_math_h, 1 },
  49. { "setjmp", test_setjmp_h, 1 },
  50. { "signal", test_signal_h, 1 },
  51. { "stdalign", test_stdalign_h, 1 },
  52. { "stdarg", test_stdarg_h, 1 },
  53. { "stdatomic", test_stdatomic_h, 1 },
  54. { "stdbool", test_stdbool_h, 1 },
  55. { "stddef", test_stddef_h, 1 },
  56. { "stdint", test_stdint_h, 1 },
  57. { "stdio", test_stdio_h, 1 },
  58. { "stdlib", test_stdlib_h, 1 },
  59. { "stdnoreturn",test_stdnoreturn_h, 1 },
  60. { "string", test_string_h, 1 },
  61. { "tgmath", test_tgmath_h, 1 },
  62. { "threads", test_threads_h, 1 },
  63. { "time", test_time_h, 1 },
  64. { "uchar", test_uchar_h, 1 },
  65. { "wchar", test_wchar_h, 1 },
  66. { "wctype", test_wctype_h, 1 },
  67. };
  68. void show_tests(void)
  69. {
  70. size_t i;
  71. printf("Valid tests: %s", tests[0].name);
  72. for (i = 1; i < sizeof(tests) / sizeof(tests[0]); i++) {
  73. printf(", %s", tests[i].name);
  74. }
  75. printf("\n");
  76. }
  77. void usage(const char *argv0)
  78. {
  79. printf("Usage: %s [-v] [test...]\n", argv0);
  80. show_tests();
  81. }
  82. int main(int argc, char *argv[])
  83. {
  84. int torun = 1;
  85. int a;
  86. size_t i, j;
  87. for (a = 1; a < argc; a++) {
  88. int ok = 0;
  89. if (!strcmp("-v", argv[a])) {
  90. verbose = 1;
  91. ok = 1;
  92. }
  93. for (j = 0; j < sizeof(tests) / sizeof(tests[0]); j++) {
  94. if (!strcmp(tests[j].name, argv[a])) {
  95. torun = 2;
  96. tests[j].run = 2;
  97. ok = 1;
  98. }
  99. }
  100. if (!ok) {
  101. usage(argv[0]);
  102. return 1;
  103. }
  104. }
  105. if (argc == 2) {
  106. if (!strcmp(argv[1], "assert")) {
  107. test_assert_h();
  108. }
  109. }
  110. for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
  111. if (tests[i].run == torun) {
  112. tests[i].fn();
  113. }
  114. }
  115. printf("Total: %u passed, %u failed\n", total_passed, total_failed);
  116. return 0;
  117. }