9 # include <vcl_msvc_warnings.h> 17 LONG WINAPI vxl_exception_filter(
struct _EXCEPTION_POINTERS *ExceptionInfo )
20 PVOID ExceptionAddress = ExceptionInfo->ExceptionRecord->ExceptionAddress;
21 DWORD ExceptionCode = ExceptionInfo->ExceptionRecord->ExceptionCode;
22 DWORD* ExceptionInformation = (DWORD*)ExceptionInfo->ExceptionRecord->ExceptionInformation;
24 std::fprintf(stderr,
"\nTOP-LEVEL EXCEPTION HANDLER\n");
25 switch (ExceptionCode)
27 case EXCEPTION_ACCESS_VIOLATION:
28 std::fprintf(stderr,
"The instruction at \"0x%.8p\" failed to %s memory at \"0x%.8x\".\n\n",
29 ExceptionAddress, ExceptionInformation[0] ?
"write to" :
"read",
30 ExceptionInformation[1]);
33 case EXCEPTION_INT_DIVIDE_BY_ZERO:
34 std::fprintf(stderr,
"The instruction at \"0x%.8p\" caused an exception of integer devision by zero.\n\n",
38 std::fprintf(stderr,
"The instruction at \"0x%.8p\" caused an unknown exception (exception code: \"0x%.8x\").\n\n",
44 std::printf(
"Execution aborted!\n");
45 return EXCEPTION_EXECUTE_HANDLER;
47 #endif // defined(_WIN32) 49 static std::vector<TestMainFunction> testlib_test_func_;
50 static std::vector<std::string> testlib_test_name_;
55 ostr <<
"The registered test names are:\n";
56 for (
const auto & i : testlib_test_name_)
57 ostr <<
" " << i <<
'\n';
58 ostr <<
"\nOmitting a test name, or specifying the name \"all\" will run all the tests.\n";
66 char * env_var1 = std::getenv(
"DART_TEST_FROM_DART");
67 char * env_var2 = std::getenv(
"DASHBOARD_TEST_FROM_CTEST");
68 if ( env_var1 || env_var2 ) {
73 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
74 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
77 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
78 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
82 SetUnhandledExceptionFilter( vxl_exception_filter );
83 #endif //defined(_MSC_VER) 91 char * env_var1 = std::getenv(
"DART_TEST_FROM_DART");
92 char * env_var2 = std::getenv(
"DASHBOARD_TEST_FROM_CTEST");
93 if ( env_var1 || env_var2 ) {
95 return testlib_test_func_[i]( argc, argv );
97 catch (
const std::exception &e)
99 std::cerr <<
"\nTOP-LEVEL EXCEPTION HANDLER **FAILED**\n" 100 << e.what() <<
"\n\n";
104 return testlib_test_func_[i]( argc, argv );
118 typedef std::vector<std::string>::size_type vec_size_t;
121 if ( testlib_test_func_.size() != testlib_test_name_.size() ) {
122 std::cerr <<
"Error: " << testlib_test_func_.size() <<
" test functions are registered, but " 123 << testlib_test_name_.size() <<
" test names are registered.\n";
133 bool test_name_given = argc >= 2;
135 if ( test_name_given && std::string(
"all") == argv[1] )
137 --argc; ++argv; test_name_given =
false;
139 if ( test_name_given )
141 for ( vec_size_t i = 0; i < testlib_test_name_.size(); ++i )
142 if ( testlib_test_name_[i] == argv[1] )
146 std::cerr <<
"Test " << argv[1] <<
" not registered.\n";
151 std::cout <<
"No test name provided. Attempting to run all tests.\n";
153 std::cout <<
"If you want to run a single test, specify one of the above on the command line.\n\n" << std::flush;
155 bool all_pass =
true;
156 for ( vec_size_t i = 0; i < testlib_test_name_.size(); ++i )
158 std::cout <<
"----------------------------------------\n" 159 <<
"Running: " << testlib_test_name_[i] <<
'\n' 160 <<
"----------------------------------------\n" << std::flush;
164 std::cout <<
"----------------------------------------\n" 165 << testlib_test_name_[i] <<
" returned " << result <<
' ' 166 << ( result==0 ?
"(PASS)" :
"(FAIL)" ) <<
'\n' 167 <<
"----------------------------------------\n" << std::flush;
168 all_pass &= (result == 0);
171 std::cout <<
"\n\nCombined result of " << testlib_test_name_.size() <<
" tests: " 172 << ( all_pass ?
"PASS" :
"FAIL" ) << std::endl;
173 return all_pass ? 0 : 1;
181 testlib_test_func_.push_back(func);
182 testlib_test_name_.push_back(name);
188 testlib_test_func_.clear();
189 testlib_test_func_.clear();
void testlib_enter_stealth_mode()
Macros for registering the tests with the driver.
void testlib_register_test(const std::string &name, TestMainFunction func)
int testlib_run_test_unit(std::vector< std::string >::size_type i, int argc, char *argv[])
void list_test_names(std::ostream &ostr)
int testlib_main(int argc, char *argv[])
int(* TestMainFunction)(int, char *[])