16be903e1SDaniel Dunbar //===--- utils/unittest/UnitTestMain/TestMain.cpp - unittest driver -------===//
26be903e1SDaniel Dunbar //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66be903e1SDaniel Dunbar //
76be903e1SDaniel Dunbar //===----------------------------------------------------------------------===//
86be903e1SDaniel Dunbar
9946d219cSManuel Klimek #include "llvm/Support/CommandLine.h"
10447762daSMichael J. Spencer #include "llvm/Support/Signals.h"
11bf6a4e0bSChandler Carruth #include "gmock/gmock.h"
126be903e1SDaniel Dunbar #include "gtest/gtest.h"
13*3df88ec3SAndy Yankovsky #include <stdlib.h>
146be903e1SDaniel Dunbar
1500409fbeSNAKAMURA Takumi #if defined(_WIN32)
165a3ff5b5SNAKAMURA Takumi # include <windows.h>
17d8010d64SMichael J. Spencer # if defined(_MSC_VER)
18d8010d64SMichael J. Spencer # include <crtdbg.h>
19d8010d64SMichael J. Spencer # endif
20d8010d64SMichael J. Spencer #endif
21d8010d64SMichael J. Spencer
2295012aaaSReid Kleckner const char *TestMainArgv0;
2395012aaaSReid Kleckner
main(int argc,char ** argv)246be903e1SDaniel Dunbar int main(int argc, char **argv) {
25*3df88ec3SAndy Yankovsky // Skip setting up signal handlers for tests that need to test things without
26*3df88ec3SAndy Yankovsky // them configured.
27*3df88ec3SAndy Yankovsky if (!getenv("LLVM_PROGRAM_TEST_NO_STACKTRACE_HANDLER")) {
282ad6d48bSRichard Smith llvm::sys::PrintStackTraceOnErrorSignal(argv[0],
292ad6d48bSRichard Smith true /* Disable crash reporting */);
30*3df88ec3SAndy Yankovsky }
31bf6a4e0bSChandler Carruth
32bf6a4e0bSChandler Carruth // Initialize both gmock and gtest.
33bf6a4e0bSChandler Carruth testing::InitGoogleMock(&argc, argv);
34bf6a4e0bSChandler Carruth
35946d219cSManuel Klimek llvm::cl::ParseCommandLineOptions(argc, argv);
36d8010d64SMichael J. Spencer
3795012aaaSReid Kleckner // Make it easy for a test to re-execute itself by saving argv[0].
3895012aaaSReid Kleckner TestMainArgv0 = argv[0];
3995012aaaSReid Kleckner
4000409fbeSNAKAMURA Takumi # if defined(_WIN32)
41d8010d64SMichael J. Spencer // Disable all of the possible ways Windows conspires to make automated
42d8010d64SMichael J. Spencer // testing impossible.
43d8010d64SMichael J. Spencer ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
44d8010d64SMichael J. Spencer # if defined(_MSC_VER)
45d8010d64SMichael J. Spencer ::_set_error_mode(_OUT_TO_STDERR);
468cbc86e9SFrancois Pichet _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
478cbc86e9SFrancois Pichet _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
488cbc86e9SFrancois Pichet _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
498cbc86e9SFrancois Pichet _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
508cbc86e9SFrancois Pichet _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
518cbc86e9SFrancois Pichet _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
52d8010d64SMichael J. Spencer # endif
53d8010d64SMichael J. Spencer # endif
54d8010d64SMichael J. Spencer
556be903e1SDaniel Dunbar return RUN_ALL_TESTS();
566be903e1SDaniel Dunbar }
57