runner.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c), Recep Aslantas.
  3. *
  4. * MIT License (MIT), http://opensource.org/licenses/MIT
  5. * Full license can be found in the LICENSE file
  6. */
  7. #include "include/common.h"
  8. #include "tests.h"
  9. #include <stdlib.h>
  10. #include <time.h>
  11. #include <string.h>
  12. int
  13. main(int argc, const char * argv[]) {
  14. test_entry_t *entry;
  15. test_status_t st;
  16. int32_t i, count, passed, failed, maxlen;
  17. double start, end, elapsed, total;
  18. (void)argc;
  19. (void)argv;
  20. passed = failed = maxlen = 0;
  21. total = 0.0;
  22. count = sizeof(tests) / sizeof(tests[0]);
  23. fprintf(stderr, CYAN "\nWelcome to cglm tests ( " RESET);
  24. glm_arch_print(stderr);
  25. fprintf(stderr, CYAN " )\n\n" RESET);
  26. srand((unsigned int)time(NULL));
  27. for (i = 0; i < count; i++) {
  28. int32_t len;
  29. entry = tests + i;
  30. len = (int32_t)strlen(entry->name);
  31. maxlen = GLM_MAX(maxlen, len);
  32. }
  33. maxlen += 5;
  34. fprintf(stderr,
  35. BOLDWHITE " %-*s %-*s\n",
  36. maxlen, "Test Name", maxlen, "Elapsed Time");
  37. for (i = 0; i < count; i++) {
  38. entry = tests + i;
  39. start = clock();
  40. st = entry->entry();
  41. end = clock();
  42. elapsed = (end - start) / CLOCKS_PER_SEC;
  43. total += elapsed;
  44. if (!st.status) {
  45. fprintf(stderr,
  46. BOLDRED " " FAIL_TEXT BOLDWHITE " %s " RESET, entry->name);
  47. if (st.msg) {
  48. fprintf(stderr,
  49. YELLOW "- %s" RESET,
  50. st.msg);
  51. }
  52. fprintf(stderr, "\n");
  53. failed++;
  54. } else {
  55. fprintf(stderr, GREEN " " OK_TEXT RESET " %-*s ", maxlen, entry->name);
  56. if (elapsed > 0.01)
  57. fprintf(stderr, YELLOW "%.2fs", elapsed);
  58. else
  59. fprintf(stderr, "0");
  60. fprintf(stderr, "\n" RESET);
  61. passed++;
  62. }
  63. }
  64. if (failed == 0) {
  65. fprintf(stderr,
  66. BOLDGREEN "\n All tests passed " FINAL_TEXT "\n" RESET);
  67. }
  68. fprintf(stderr,
  69. CYAN "\ncglm test results (%0.2fs):\n" RESET
  70. "--------------------------\n"
  71. MAGENTA "%d" RESET " tests ran, "
  72. GREEN "%d" RESET " passed, "
  73. RED "%d" RESET " failed\n\n" RESET,
  74. total,
  75. count,
  76. passed,
  77. failed);
  78. return failed;
  79. }