#include "base/test/launcher/unit_test_launcher.h"
#include <map>
#include <memory>
#include <string_view>
#include <utility>
#include "base/base_paths.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/debug/debugger.h"
#include "base/files/file_util.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/i18n/icu_util.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/message_loop/message_pump_type.h"
#include "base/sequence_checker.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/system/sys_info.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/allow_check_is_test_for_testing.h"
#include "base/test/fuzztest_init_helper.h"
#include "base/test/launcher/test_launcher.h"
#include "base/test/scoped_block_tests_writing_to_special_dirs.h"
#include "base/test/test_switches.h"
#include "base/test/test_timeouts.h"
#include "base/threading/thread_checker.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_POSIX)
#include "base/files/file_descriptor_watcher_posix.h"
#endif
#if BUILDFLAG(IS_IOS)
#include "base/test/test_support_ios.h"
#endif
namespace base {
namespace {
const size_t kDefaultTestBatchLimit = …100;
#else
10;
#endif
#if !BUILDFLAG(IS_ANDROID)
void PrintUsage() { … }
bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { … }
int RunTestSuite(RunTestSuiteCallback run_test_suite,
size_t parallel_jobs,
int default_batch_limit,
size_t retry_limit,
bool use_job_objects,
RepeatingClosure timeout_callback,
OnceClosure gtest_init) { … }
#endif
int LaunchUnitTestsInternal(RunTestSuiteCallback run_test_suite,
size_t parallel_jobs,
int default_batch_limit,
size_t retry_limit,
bool use_job_objects,
RepeatingClosure timeout_callback,
OnceClosure gtest_init) { … }
void InitGoogleTestChar(int* argc, char** argv) { … }
#if BUILDFLAG(IS_WIN)
UNSAFE_BUFFER_USAGE void InitGoogleTestWChar(int* argc, wchar_t** argv) {
testing::InitGoogleTest(argc, argv);
CHECK(*argc >= 0);
base::span<wchar_t*> wide_command_line =
UNSAFE_BUFFERS(base::make_span(argv, static_cast<size_t>(*argc)));
std::vector<std::string> narrow_command_line;
std::vector<char*> narrow_command_line_pointers;
narrow_command_line.reserve(*argc);
narrow_command_line_pointers.reserve(*argc);
for (int i = 0; i < *argc; i++) {
narrow_command_line.push_back(WideToUTF8(wide_command_line[i]));
narrow_command_line_pointers.push_back(narrow_command_line[i].data());
}
MaybeInitFuzztest(*argc, narrow_command_line_pointers.data());
}
#endif
}
MergeTestFilterSwitchHandler::~MergeTestFilterSwitchHandler() = default;
void MergeTestFilterSwitchHandler::ResolveDuplicate(
std::string_view key,
CommandLine::StringViewType new_value,
CommandLine::StringType& out_value) { … }
int LaunchUnitTests(int argc,
char** argv,
RunTestSuiteCallback run_test_suite,
size_t retry_limit) { … }
int LaunchUnitTestsSerially(int argc,
char** argv,
RunTestSuiteCallback run_test_suite) { … }
int LaunchUnitTestsWithOptions(int argc,
char** argv,
size_t parallel_jobs,
int default_batch_limit,
bool use_job_objects,
RepeatingClosure timeout_callback,
RunTestSuiteCallback run_test_suite) { … }
#if BUILDFLAG(IS_WIN)
int LaunchUnitTests(int argc,
wchar_t** argv,
bool use_job_objects,
RunTestSuiteCallback run_test_suite) {
CommandLine::Init(argc, NULL);
size_t parallel_jobs = NumParallelJobs(1);
if (parallel_jobs == 0U) {
return 1;
}
return LaunchUnitTestsInternal(std::move(run_test_suite), parallel_jobs,
kDefaultTestBatchLimit, 1U, use_job_objects,
DoNothing(),
BindOnce(&InitGoogleTestWChar, &argc, argv));
}
#endif
DefaultUnitTestPlatformDelegate::DefaultUnitTestPlatformDelegate() = default;
bool DefaultUnitTestPlatformDelegate::GetTests(
std::vector<TestIdentifier>* output) { … }
bool DefaultUnitTestPlatformDelegate::CreateResultsFile(
const base::FilePath& temp_dir,
base::FilePath* path) { … }
bool DefaultUnitTestPlatformDelegate::CreateTemporaryFile(
const base::FilePath& temp_dir,
base::FilePath* path) { … }
CommandLine DefaultUnitTestPlatformDelegate::GetCommandLineForChildGTestProcess(
const std::vector<std::string>& test_names,
const base::FilePath& output_file,
const base::FilePath& flag_file) { … }
std::string DefaultUnitTestPlatformDelegate::GetWrapperForChildGTestProcess() { … }
UnitTestLauncherDelegate::UnitTestLauncherDelegate(
UnitTestPlatformDelegate* platform_delegate,
size_t batch_limit,
bool use_job_objects,
RepeatingClosure timeout_callback)
: … { … }
UnitTestLauncherDelegate::~UnitTestLauncherDelegate() { … }
bool UnitTestLauncherDelegate::GetTests(std::vector<TestIdentifier>* output) { … }
CommandLine UnitTestLauncherDelegate::GetCommandLine(
const std::vector<std::string>& test_names,
const FilePath& temp_dir,
FilePath* output_file) { … }
std::string UnitTestLauncherDelegate::GetWrapper() { … }
int UnitTestLauncherDelegate::GetLaunchOptions() { … }
TimeDelta UnitTestLauncherDelegate::GetTimeout() { … }
size_t UnitTestLauncherDelegate::GetBatchSize() { … }
void UnitTestLauncherDelegate::OnTestTimedOut(const CommandLine& cmd_line) { … }
}