1 //===--- utils/unittest/UnitTestMain/TestMain.cpp - unittest driver -------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/Support/CommandLine.h" 11 #include "llvm/Support/Signals.h" 12 #include "gtest/gtest.h" 13 14 15 #if defined(_WIN32) 16 # include <windows.h> 17 # if defined(_MSC_VER) 18 # include <crtdbg.h> 19 # endif 20 #endif 21 22 const char *TestMainArgv0; 23 24 int main(int argc, char **argv) { 25 llvm::sys::PrintStackTraceOnErrorSignal(true /* Disable crash reporting */); 26 testing::InitGoogleTest(&argc, argv); 27 llvm::cl::ParseCommandLineOptions(argc, argv); 28 29 // Make it easy for a test to re-execute itself by saving argv[0]. 30 TestMainArgv0 = argv[0]; 31 32 # if defined(_WIN32) 33 // Disable all of the possible ways Windows conspires to make automated 34 // testing impossible. 35 ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); 36 # if defined(_MSC_VER) 37 ::_set_error_mode(_OUT_TO_STDERR); 38 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); 39 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); 40 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); 41 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); 42 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); 43 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); 44 # endif 45 # endif 46 47 return RUN_ALL_TESTS(); 48 } 49