1*7330f729Sjoerg //===--- utils/unittest/UnitTestMain/TestMain.cpp - unittest driver -------===//
2*7330f729Sjoerg //
3*7330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*7330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
5*7330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*7330f729Sjoerg //
7*7330f729Sjoerg //===----------------------------------------------------------------------===//
8*7330f729Sjoerg
9*7330f729Sjoerg #include "llvm/Support/CommandLine.h"
10*7330f729Sjoerg #include "llvm/Support/Signals.h"
11*7330f729Sjoerg #include "gmock/gmock.h"
12*7330f729Sjoerg #include "gtest/gtest.h"
13*7330f729Sjoerg
14*7330f729Sjoerg #if defined(_WIN32)
15*7330f729Sjoerg # include <windows.h>
16*7330f729Sjoerg # if defined(_MSC_VER)
17*7330f729Sjoerg # include <crtdbg.h>
18*7330f729Sjoerg # endif
19*7330f729Sjoerg #endif
20*7330f729Sjoerg
21*7330f729Sjoerg const char *TestMainArgv0;
22*7330f729Sjoerg
main(int argc,char ** argv)23*7330f729Sjoerg int main(int argc, char **argv) {
24*7330f729Sjoerg llvm::sys::PrintStackTraceOnErrorSignal(argv[0],
25*7330f729Sjoerg true /* Disable crash reporting */);
26*7330f729Sjoerg
27*7330f729Sjoerg // Initialize both gmock and gtest.
28*7330f729Sjoerg testing::InitGoogleMock(&argc, argv);
29*7330f729Sjoerg
30*7330f729Sjoerg llvm::cl::ParseCommandLineOptions(argc, argv);
31*7330f729Sjoerg
32*7330f729Sjoerg // Make it easy for a test to re-execute itself by saving argv[0].
33*7330f729Sjoerg TestMainArgv0 = argv[0];
34*7330f729Sjoerg
35*7330f729Sjoerg # if defined(_WIN32)
36*7330f729Sjoerg // Disable all of the possible ways Windows conspires to make automated
37*7330f729Sjoerg // testing impossible.
38*7330f729Sjoerg ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
39*7330f729Sjoerg # if defined(_MSC_VER)
40*7330f729Sjoerg ::_set_error_mode(_OUT_TO_STDERR);
41*7330f729Sjoerg _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
42*7330f729Sjoerg _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
43*7330f729Sjoerg _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
44*7330f729Sjoerg _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
45*7330f729Sjoerg _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
46*7330f729Sjoerg _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
47*7330f729Sjoerg # endif
48*7330f729Sjoerg # endif
49*7330f729Sjoerg
50*7330f729Sjoerg return RUN_ALL_TESTS();
51*7330f729Sjoerg }
52