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