#include "base/test/launcher/test_launcher.h"
#include <stddef.h>
#include <optional>
#include "base/base64.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/i18n/time_formatting.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/process/launch.h"
#include "base/strings/strcat.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/test/gtest_xml_util.h"
#include "base/test/launcher/test_launcher_test_utils.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/multiprocess_test.h"
#include "base/test/scoped_logging_settings.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
namespace base {
namespace {
_;
DoAll;
Invoke;
InvokeWithoutArgs;
Return;
ReturnPointee;
TestResult GenerateTestResult(const std::string& test_name,
TestResult::Status status,
TimeDelta elapsed_td = Milliseconds(30),
const std::string& output_snippet = "output") { … }
TestResultPart GenerateTestResultPart(TestResultPart::Type type,
const std::string& file_name,
int line_number,
const std::string& summary,
const std::string& message) { … }
class MockTestLauncher : public TestLauncher { … };
class MockTestLauncherDelegate : public TestLauncherDelegate { … };
class MockResultWatcher : public ResultWatcher { … };
class TestLauncherTest : public testing::Test { … };
class ResultWatcherTest : public testing::Test { … };
ACTION_P3(OnTestResult, launcher, full_name, status) { … }
ACTION_P2(OnTestResult, launcher, result) { … }
TEST_F(TestLauncherTest, TestNameSharedWithDisabledTest) { … }
TEST_F(TestLauncherTest, TestNameSharedWithDisabledTestCase) { … }
TEST_F(TestLauncherTest, OrphanePreTest) { … }
TEST_F(TestLauncherTest, EmptyTestSetPasses) { … }
TEST_F(TestLauncherTest, FilterDisabledTestByDefault) { … }
TEST_F(TestLauncherTest, ReorderPreTests) { … }
TEST_F(TestLauncherTest, UsingCommandLineFilter) { … }
TEST_F(TestLauncherTest, FilterIncludePreTest) { … }
TEST_F(TestLauncherTest, FilterIncludeExclude) { … }
TEST_F(TestLauncherTest, RepeatTest) { … }
TEST_F(TestLauncherTest, RunningMultipleIterationsUntilFailure) { … }
TEST_F(TestLauncherTest, SuccessOnRetryTests) { … }
TEST_F(TestLauncherTest, FailOnRetryTests) { … }
TEST_F(TestLauncherTest, RetryPreTests) { … }
TEST_F(TestLauncherTest, PreTestFailure) { … }
TEST_F(TestLauncherTest, RunDisabledTests) { … }
TEST_F(TestLauncherTest, DoesRunFilteredTests) { … }
TEST_F(TestLauncherTest, RunDisabledTestsWithFilteredTests) { … }
TEST_F(TestLauncherTest, DisablePreTests) { … }
TEST_F(TestLauncherTest, EnforceRunTestsInExactPositiveFilter) { … }
TEST_F(TestLauncherTest,
EnforceRunTestsInExactPositiveFailWithGtestFilterFlag) { … }
TEST_F(TestLauncherTest, EnforceRunTestsInExactPositiveFailWithNegativeFilter) { … }
TEST_F(TestLauncherTest,
EnforceRunTestsInExactPositiveFailWithWildcardPositiveFilter) { … }
TEST_F(TestLauncherTest, ExcessiveOutput) { … }
TEST_F(TestLauncherTest, OutputLimitSwitch) { … }
TEST_F(TestLauncherTest, FaultyShardSetup) { … }
TEST_F(TestLauncherTest, RedirectStdio) { … }
TEST_F(TestLauncherTest, StableSharding) { … }
bool ValidateTestResultObject(const Value::Dict& iteration_data,
TestResult& test_result) { … }
bool ValidateStringList(const std::optional<Value::Dict>& root,
const std::string& key,
std::vector<const char*> values) { … }
TEST_F(TestLauncherTest, JsonSummary) { … }
TEST_F(TestLauncherTest, JsonSummaryWithDisabledTests) { … }
MATCHER(DirectoryIsParentOf, "") { … }
TEST_F(TestLauncherTest, TestChildTempDir) { … }
#if BUILDFLAG(IS_FUCHSIA)
TEST_F(TestLauncherTest, ProvidesDataCacheAndTmpDirs) {
EXPECT_TRUE(base::DirectoryExists(base::FilePath("/data")));
EXPECT_TRUE(base::DirectoryExists(base::FilePath("/cache")));
EXPECT_TRUE(base::DirectoryExists(base::FilePath("/tmp")));
}
#endif
class UnitTestLauncherDelegateTester : public testing::Test { … };
TEST_F(UnitTestLauncherDelegateTester, GetCommandLine) { … }
TEST_F(ResultWatcherTest, PollCompletesQuickly) { … }
TEST_F(ResultWatcherTest, PollCompletesSlowly) { … }
TEST_F(ResultWatcherTest, PollTimeout) { … }
TEST_F(ResultWatcherTest, RetryIncompleteResultRead) { … }
TEST_F(ResultWatcherTest, PollWithClockJumpBackward) { … }
TEST_F(ResultWatcherTest, PollWithClockJumpForward) { … }
TEST_F(UnitTestLauncherDelegateTester, BatchSize) { … }
TEST(MockUnitTests, DISABLED_PassTest) { … }
TEST(MockUnitTests, DISABLED_FailTest) { … }
TEST(MockUnitTests, DISABLED_CrashTest) { … }
TEST(MockUnitTests, DISABLED_NoRunTest) { … }
TEST_F(UnitTestLauncherDelegateTester, RunMockTests) { … }
TEST(ProcessGTestOutputTest, RunMockTests) { … }
#if !BUILDFLAG(IS_FUCHSIA)
TEST(ProcessGTestOutputTest, FoundTestCaseNotEnforced) { … }
#endif
#if BUILDFLAG(IS_FUCHSIA)
MULTIPROCESS_TEST_MAIN(LeakChildProcess) {
while (true)
PlatformThread::Sleep(base::Seconds(1));
}
TEST(LeakedChildProcessTest, DISABLED_LeakChildProcess) {
Process child_process = SpawnMultiProcessTestChild(
"LeakChildProcess", GetMultiProcessTestChildBaseCommandLine(),
LaunchOptions());
ASSERT_TRUE(child_process.IsValid());
}
TEST_F(UnitTestLauncherDelegateTester, LeakedChildProcess) {
CommandLine command_line(CommandLine::ForCurrentProcess()->GetProgram());
command_line.AppendSwitchASCII(
"gtest_filter", "LeakedChildProcessTest.DISABLED_LeakChildProcess");
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath path = dir.GetPath().AppendASCII("SaveSummaryResult.json");
command_line.AppendSwitchPath("test-launcher-summary-output", path);
command_line.AppendSwitch("gtest_also_run_disabled_tests");
command_line.AppendSwitchASCII("test-launcher-retry-limit", "0");
std::string output;
int exit_code = 0;
GetAppOutputWithExitCode(command_line, &output, &exit_code);
std::optional<Value::Dict> root = test_launcher_utils::ReadSummary(path);
ASSERT_TRUE(root);
Value::Dict* dict = root->FindDict("test_locations");
ASSERT_TRUE(dict);
EXPECT_EQ(1u, dict->size());
EXPECT_TRUE(test_launcher_utils::ValidateTestLocations(
*dict, "LeakedChildProcessTest"));
EXPECT_EQ(exit_code, 1);
}
#endif
TEST(TestLauncherTools, GetTestOutputSnippetTest) { … }
MATCHER(CheckTruncationPreservesMessage, "") { … }
void MatchesFatalMessagesTest() { … }
TEST(TestLauncherTools, TruncateSnippetFocusedMatchesFatalMessagesTest) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST(TestLauncherTools, TruncateSnippetFocusedMatchesFatalMessagesCrosAshTest) {
logging::ScopedLoggingSettings scoped_logging_settings;
scoped_logging_settings.SetLogFormat(logging::LogFormat::LOG_FORMAT_CHROME);
MatchesFatalMessagesTest();
}
#endif
TEST(TestLauncherTools, TruncateSnippetFocusedTest) { … }
}
}