blob: fb2b0f16ee3f298fe6788dbdd9bb380cce050ec9 [file] [log] [blame]
Daniel Dunbar6be903e2009-09-13 21:31:21 +00001//===--- utils/unittest/UnitTestMain/TestMain.cpp - unittest driver -------===//
Misha Brukmanbcf15382009-01-01 02:24:48 +00002//
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
Manuel Klimek946d2192013-01-18 10:18:50 +000010#include "llvm/Support/CommandLine.h"
Michael J. Spencer447762d2010-11-29 18:16:10 +000011#include "llvm/Support/Signals.h"
Misha Brukmanbcf15382009-01-01 02:24:48 +000012#include "gtest/gtest.h"
13
Michael J. Spencerd8010d62010-09-24 09:01:34 +000014
NAKAMURA Takumi00409fb2015-07-06 23:51:40 +000015#if defined(_WIN32)
NAKAMURA Takumi5a3ff5b2011-02-04 12:53:04 +000016# include <windows.h>
Michael J. Spencerd8010d62010-09-24 09:01:34 +000017# if defined(_MSC_VER)
18# include <crtdbg.h>
19# endif
20#endif
21
Reid Kleckner95012aa2013-04-30 04:30:41 +000022const char *TestMainArgv0;
23
Misha Brukmanbcf15382009-01-01 02:24:48 +000024int main(int argc, char **argv) {
Pete Cooper6bea2f42015-04-07 20:43:23 +000025 llvm::sys::PrintStackTraceOnErrorSignal(true /* Disable crash reporting */);
Misha Brukmanbcf15382009-01-01 02:24:48 +000026 testing::InitGoogleTest(&argc, argv);
Manuel Klimek946d2192013-01-18 10:18:50 +000027 llvm::cl::ParseCommandLineOptions(argc, argv);
Michael J. Spencerd8010d62010-09-24 09:01:34 +000028
Reid Kleckner95012aa2013-04-30 04:30:41 +000029 // Make it easy for a test to re-execute itself by saving argv[0].
30 TestMainArgv0 = argv[0];
31
NAKAMURA Takumi00409fb2015-07-06 23:51:40 +000032# if defined(_WIN32)
Michael J. Spencerd8010d62010-09-24 09:01:34 +000033 // 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);
Francois Pichet8cbc86e2010-10-02 03:26:54 +000038 _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);
Michael J. Spencerd8010d62010-09-24 09:01:34 +000044# endif
45# endif
46
Misha Brukmanbcf15382009-01-01 02:24:48 +000047 return RUN_ALL_TESTS();
48}