run_test.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2010-2024 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
  4. */
  5. #define CATCH_CONFIG_RUNNER
  6. #include "test.h"
  7. #include <bx/string.h>
  8. #include <bx/file.h>
  9. #include <bx/simd_t.h>
  10. bool testAssertHandler(const bx::Location& _location, const char* _format, va_list _argList)
  11. {
  12. bx::printf("%s(%d): ", _location.filePath, _location.line);
  13. bx::vprintf(_format, _argList);
  14. bx::printf("\n");
  15. uintptr_t stack[32];
  16. const uint32_t num = bx::getCallStack(2 /* skip self */, BX_COUNTOF(stack), stack);
  17. bx::writeCallstack(bx::getStdOut(), stack, num, bx::ErrorIgnore{});
  18. // Throwing exceptions is required for testing asserts being trigged.
  19. // Use REQUIRE_ASSERTS to test asserts.
  20. throw std::exception();
  21. return true;
  22. }
  23. int runAllTests(int32_t _argc, const char* _argv[])
  24. {
  25. bx::setAssertHandler(testAssertHandler);
  26. bx::printf(
  27. "\nCompiler: " BX_COMPILER_NAME
  28. ", CPU: " BX_CPU_NAME
  29. ", Arch: " BX_ARCH_NAME
  30. ", OS: " BX_PLATFORM_NAME
  31. ", CRT: " BX_CRT_NAME
  32. ", Features: " BX_CPP_NAME
  33. #if BX_SIMD_SUPPORTED
  34. ", SIMD"
  35. # if BX_SIMD_AVX
  36. ", AVX"
  37. # endif // BX_SIMD_AVX
  38. # if BX_SIMD_LANGEXT
  39. ", LangExt"
  40. # endif // BX_SIMD_LANGEXT
  41. # if BX_SIMD_NEON
  42. ", Neon"
  43. # endif // BX_SIMD_NEON
  44. # if BX_SIMD_SSE
  45. ", SSE"
  46. # endif // BX_SIMD_SSE
  47. #endif // BX_SIMD_SUPPORTED
  48. ", Date: " __DATE__
  49. ", Time: " __TIME__
  50. "\n\n"
  51. );
  52. bx::printf("Args:\n");
  53. for (int32_t ii = 0; ii < _argc; ++ii)
  54. {
  55. bx::printf("\t%2d: \"%s\"", ii, _argv[ii]);
  56. }
  57. bx::printf("\n\n");
  58. using namespace Catch;
  59. Session session;
  60. ConfigData config;
  61. config.defaultColourMode = BX_PLATFORM_EMSCRIPTEN
  62. ? ColourMode::None
  63. : ColourMode::PlatformDefault
  64. ;
  65. config.showDurations = ShowDurations::Always;
  66. session.useConfigData(config);
  67. return session.run(_argc, _argv);
  68. }