chromium/base/test/test_suite.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "base/test/test_suite.h"

#include <signal.h>

#include <algorithm>
#include <memory>
#include <string>
#include <string_view>
#include <vector>

#include "base/at_exit.h"
#include "base/base_paths.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/debug/asan_service.h"
#include "base/debug/debugger.h"
#include "base/debug/profiler.h"
#include "base/debug/stack_trace.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/i18n/icu_util.h"
#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/statistics_recorder.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/process/memory.h"
#include "base/process/process.h"
#include "base/process/process_handle.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/fuzztest_init_helper.h"
#include "base/test/gtest_xml_unittest_result_printer.h"
#include "base/test/gtest_xml_util.h"
#include "base/test/icu_test_util.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/mock_entropy_provider.h"
#include "base/test/multiprocess_test.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/scoped_run_loop_timeout.h"
#include "base/test/test_suite_helper.h"
#include "base/test/test_switches.h"
#include "base/test/test_timeouts.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/tracing_buildflags.h"
#include "build/build_config.h"
#include "partition_alloc/buildflags.h"
#include "partition_alloc/tagging.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"

#if BUILDFLAG(IS_APPLE)
#include "base/apple/scoped_nsautorelease_pool.h"
#endif  // BUILDFLAG(IS_APPLE)

#if BUILDFLAG(IS_IOS)
#include "base/test/test_listener_ios.h"
#include "base/test/test_support_ios.h"
#else
#include "base/strings/string_util.h"
#include "third_party/icu/source/common/unicode/uloc.h"
#endif

#if BUILDFLAG(IS_ANDROID)
#include "base/test/test_support_android.h"
#endif

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "third_party/test_fonts/fontconfig/fontconfig_util_linux.h"
#endif

#if BUILDFLAG(IS_FUCHSIA)
#include "base/fuchsia/system_info.h"
#endif

#if BUILDFLAG(IS_WIN)
#if defined(_DEBUG)
#include <crtdbg.h>
#endif  // _DEBUG
#include <windows.h>

#include "base/debug/handle_hooks_win.h"
#endif  // BUILDFLAG(IS_WIN)

#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
#include "base/allocator/partition_alloc_support.h"
#endif  // PA_BUILDFLAG(USE_PARTITION_ALLOC)

#if GTEST_HAS_DEATH_TEST
#include "base/gtest_prod_util.h"
#endif

namespace base {

namespace {

// Returns true if the test is marked as "MAYBE_".
// When using different prefixes depending on platform, we use MAYBE_ and
// preprocessor directives to replace MAYBE_ with the target prefix.
bool IsMarkedMaybe(const testing::TestInfo& test) {}

class DisableMaybeTests : public testing::EmptyTestEventListener {};

class ResetCommandLineBetweenTests : public testing::EmptyTestEventListener {};

// Initializes a base::test::ScopedFeatureList for each individual test, which
// involves a FeatureList and a FieldTrialList, such that unit test don't need
// to initialize them manually.
class FeatureListScopedToEachTest : public testing::EmptyTestEventListener {};

class CheckForLeakedGlobals : public testing::EmptyTestEventListener {};

// iOS: base::Process is not available.
// macOS: Tests may run at background priority locally (crbug.com/1358639#c6) or
// on bots (crbug.com/931721#c7).
#if !BUILDFLAG(IS_APPLE)
class CheckProcessPriority : public testing::EmptyTestEventListener {};
#endif  // !BUILDFLAG(IS_APPLE)

const std::string& GetProfileName() {}

void InitializeLogging() {}

#if BUILDFLAG(IS_WIN)
// Handlers for invalid parameter, pure call, and abort. They generate a
// breakpoint to ensure that we get a call stack on these failures.
// These functions should be written to be unique in order to avoid confusing
// call stacks from /OPT:ICF function folding. Printing a unique message or
// returning a unique value will do this. Note that for best results they need
// to be unique from *all* functions in Chrome.
void InvalidParameter(const wchar_t* expression,
                      const wchar_t* function,
                      const wchar_t* file,
                      unsigned int line,
                      uintptr_t reserved) {
  // CRT printed message is sufficient.
  __debugbreak();
  _exit(1);
}

void PureCall() {
  fprintf(stderr, "Pure-virtual function call. Terminating.\n");
  __debugbreak();
  _exit(1);
}

void AbortHandler(int signal) {
  // Print EOL after the CRT abort message.
  fprintf(stderr, "\n");
  __debugbreak();
}
#endif

#if GTEST_HAS_DEATH_TEST
// Returns a friendly message to tell developers how to see the stack traces for
// unexpected crashes in death test child processes. Since death tests generate
// stack traces as a consequence of their expected crashes and stack traces are
// expensive to compute, stack traces in death test child processes are
// suppressed unless `--with-stack-traces` is on the command line.
std::string GetStackTraceMessage() {}
#endif  // GTEST_HAS_DEATH_TEST

}  // namespace

int RunUnitTestsUsingBaseTestSuite(int argc, char** argv) {}

TestSuite::TestSuite(int argc, char** argv) :{}

#if BUILDFLAG(IS_WIN)
TestSuite::TestSuite(int argc, wchar_t** argv) : argc_(argc) {
  argv_as_strings_.reserve(argc);
  argv_as_pointers_.reserve(argc + 1);
  std::for_each(argv, argv + argc, [this](wchar_t* arg) {
    argv_as_strings_.push_back(WideToUTF8(arg));
    // Have to use .data() here to get a mutable pointer.
    argv_as_pointers_.push_back(argv_as_strings_.back().data());
  });
  // `argv` is specified as containing `argc + 1` pointers, of which the last is
  // null.
  argv_as_pointers_.push_back(nullptr);
  argv_ = argv_as_pointers_.data();
  PreInitialize();
}
#endif  // BUILDFLAG(IS_WIN)

TestSuite::~TestSuite() {}

// Don't add additional code to this method.  Instead add it to
// Initialize().  See bug 6436.
int TestSuite::Run() {}

void TestSuite::DisableCheckForThreadAndProcessPriority() {}

void TestSuite::DisableCheckForLeakedGlobals() {}

void TestSuite::UnitTestAssertHandler(const char* file,
                                      int line,
                                      const std::string_view summary,
                                      const std::string_view stack_trace) {}

void TestSuite::SuppressErrorDialogs() {}

void TestSuite::Initialize() {}

void TestSuite::InitializeFromCommandLine(int* argc, char** argv) {}

int TestSuite::RunAllTests() {}

void TestSuite::Shutdown() {}

void TestSuite::PreInitialize() {}

void TestSuite::AddTestLauncherResultPrinter() {}

}  // namespace base