run_test.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 2010-2025 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. BX_PRAGMA_DIAGNOSTIC_PUSH();
  11. BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4702); // warning C4702: unreachable code
  12. bool testAssertHandler(const bx::Location& _location, uint32_t _skip, const char* _format, va_list _argList)
  13. {
  14. bx::printf("%s(%d): ", _location.filePath, _location.line);
  15. bx::vprintf(_format, _argList);
  16. bx::printf("\n");
  17. uintptr_t stack[32];
  18. const uint32_t num = bx::getCallStackExact(2 /* skip self */ + _skip, BX_COUNTOF(stack), stack);
  19. bx::writeCallstack(bx::getStdOut(), stack, num, bx::ErrorIgnore{});
  20. // Throwing exceptions is required for testing asserts being trigged.
  21. // Use REQUIRE_ASSERTS to test asserts.
  22. throw std::exception();
  23. return true;
  24. }
  25. BX_PRAGMA_DIAGNOSTIC_POP();
  26. int runAllTests(int32_t _argc, const char* _argv[])
  27. {
  28. bx::setAssertHandler(testAssertHandler);
  29. bx::printf(
  30. "\nCompiler: " BX_COMPILER_NAME
  31. ", CPU: " BX_CPU_NAME
  32. ", Arch: " BX_ARCH_NAME
  33. ", OS: " BX_PLATFORM_NAME
  34. ", CRT: " BX_CRT_NAME
  35. ", Features: " BX_CPP_NAME
  36. #if BX_SIMD_SUPPORTED
  37. ", SIMD"
  38. # if BX_SIMD_AVX
  39. ", AVX"
  40. # endif // BX_SIMD_AVX
  41. # if BX_SIMD_LANGEXT
  42. ", LangExt"
  43. # endif // BX_SIMD_LANGEXT
  44. # if BX_SIMD_NEON
  45. ", Neon"
  46. # endif // BX_SIMD_NEON
  47. # if BX_SIMD_SSE
  48. ", SSE"
  49. # endif // BX_SIMD_SSE
  50. #endif // BX_SIMD_SUPPORTED
  51. ", Date: " __DATE__
  52. ", Time: " __TIME__
  53. "\n\n"
  54. );
  55. bx::printf("Args:\n");
  56. for (int32_t ii = 0; ii < _argc; ++ii)
  57. {
  58. bx::printf("\t%2d: \"%s\"\n", ii, _argv[ii]);
  59. }
  60. bx::printf("\n");
  61. using namespace Catch;
  62. Session session;
  63. ConfigData config;
  64. config.defaultColourMode = BX_PLATFORM_EMSCRIPTEN
  65. ? ColourMode::None
  66. : ColourMode::PlatformDefault
  67. ;
  68. config.showDurations = ShowDurations::Always;
  69. session.useConfigData(config);
  70. return session.run(_argc, _argv);
  71. }