2023-01-28 04:54:20 +00:00
|
|
|
|
// Copyright 2017 The Crashpad Authors
|
2022-04-02 01:21:55 +00:00
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
|
#include "build/build_config.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include "test/main_arguments.h"
|
|
|
|
|
#include "test/multiprocess_exec.h"
|
|
|
|
|
|
|
|
|
|
#if defined(CRASHPAD_TEST_LAUNCHER_GOOGLEMOCK)
|
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
|
#endif // CRASHPAD_TEST_LAUNCHER_GOOGLEMOCK
|
|
|
|
|
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
#include "util/linux/initial_signal_dispositions.h"
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#if BUILDFLAG(IS_IOS)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
#include "test/ios/google_test_setup.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
#include "test/win/win_child_process.h"
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
|
|
|
|
|
#if defined(CRASHPAD_IS_IN_CHROMIUM)
|
2023-02-16 02:08:10 +00:00
|
|
|
|
#include "base/functional/bind.h"
|
2022-04-02 01:21:55 +00:00
|
|
|
|
#include "base/test/launcher/unit_test_launcher.h"
|
|
|
|
|
#include "base/test/test_suite.h"
|
|
|
|
|
#endif // CRASHPAD_IS_IN_CHROMIUM
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#if !BUILDFLAG(IS_IOS)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
bool GetChildTestFunctionName(std::string* child_func_name) {
|
|
|
|
|
constexpr size_t arg_length =
|
|
|
|
|
sizeof(crashpad::test::internal::kChildTestFunction) - 1;
|
|
|
|
|
for (const auto& it : crashpad::test::GetMainArguments()) {
|
|
|
|
|
if (it.compare(
|
|
|
|
|
0, arg_length, crashpad::test::internal::kChildTestFunction) == 0) {
|
|
|
|
|
*child_func_name = it.substr(arg_length);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#endif // !BUILDFLAG(IS_IOS)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
crashpad::InitializeSignalDispositions();
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
|
|
|
|
|
crashpad::test::InitializeMainArguments(argc, argv);
|
|
|
|
|
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#if !BUILDFLAG(IS_IOS)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
std::string child_func_name;
|
|
|
|
|
if (GetChildTestFunctionName(&child_func_name)) {
|
|
|
|
|
return crashpad::test::internal::CheckedInvokeMultiprocessChild(
|
|
|
|
|
child_func_name);
|
|
|
|
|
}
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#endif // !BUILDFLAG(IS_IOS)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
|
|
|
|
|
#if defined(CRASHPAD_IS_IN_CHROMIUM)
|
|
|
|
|
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
// Chromium’s test launcher interferes with WinMultiprocess-based tests. Allow
|
|
|
|
|
// their child processes to be launched by the standard Google Test-based test
|
|
|
|
|
// runner.
|
|
|
|
|
const bool use_chromium_test_launcher =
|
|
|
|
|
!crashpad::test::WinChildProcess::IsChildProcess();
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#elif BUILDFLAG(IS_ANDROID)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
constexpr bool use_chromium_test_launcher = false;
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#else // BUILDFLAG(IS_WIN)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
constexpr bool use_chromium_test_launcher = true;
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
|
|
|
|
|
if (use_chromium_test_launcher) {
|
|
|
|
|
// This supports --test-launcher-summary-output, which writes a JSON file
|
|
|
|
|
// containing test details needed by Swarming.
|
|
|
|
|
base::TestSuite test_suite(argc, argv);
|
|
|
|
|
return base::LaunchUnitTests(
|
|
|
|
|
argc,
|
|
|
|
|
argv,
|
|
|
|
|
base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // CRASHPAD_IS_IN_CHROMIUM
|
|
|
|
|
|
|
|
|
|
// base::TestSuite initializes logging when using Chromium's test launcher.
|
|
|
|
|
logging::LoggingSettings settings;
|
|
|
|
|
settings.logging_dest =
|
|
|
|
|
logging::LOG_TO_STDERR | logging::LOG_TO_SYSTEM_DEBUG_LOG;
|
|
|
|
|
logging::InitLogging(settings);
|
|
|
|
|
|
|
|
|
|
#if defined(CRASHPAD_TEST_LAUNCHER_GOOGLEMOCK)
|
|
|
|
|
testing::InitGoogleMock(&argc, argv);
|
|
|
|
|
#elif defined(CRASHPAD_TEST_LAUNCHER_GOOGLETEST)
|
|
|
|
|
testing::InitGoogleTest(&argc, argv);
|
|
|
|
|
#else // CRASHPAD_TEST_LAUNCHER_GOOGLEMOCK
|
|
|
|
|
#error #define CRASHPAD_TEST_LAUNCHER_GOOGLETEST or \
|
|
|
|
|
CRASHPAD_TEST_LAUNCHER_GOOGLEMOCK
|
|
|
|
|
#endif // CRASHPAD_TEST_LAUNCHER_GOOGLEMOCK
|
|
|
|
|
|
2022-08-16 00:48:53 +00:00
|
|
|
|
#if BUILDFLAG(IS_IOS)
|
2022-04-02 01:21:55 +00:00
|
|
|
|
// iOS needs to run tests within the context of an app, so call a helper that
|
|
|
|
|
// invokes UIApplicationMain(). The application delegate will call
|
|
|
|
|
// RUN_ALL_TESTS() and exit before returning control to this function.
|
|
|
|
|
crashpad::test::IOSLaunchApplicationAndRunTests(argc, argv);
|
|
|
|
|
#else
|
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
|
#endif
|
|
|
|
|
}
|