From 04a3cc1ad9571111fa301071455fc2280ac0687c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Tue, 21 May 2019 13:01:58 +0200 Subject: [PATCH] Delete rtc_base/unittest_main.cc Usage replaced with test/test_main.cc. Bug: webrtc:5996 Change-Id: I65e7539f2072fb45255a3c1af0b10dd06e1701ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/137805 Reviewed-by: Mirko Bonadei Reviewed-by: Tommi Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#28010} --- BUILD.gn | 2 +- media/BUILD.gn | 3 +- pc/BUILD.gn | 4 +- rtc_base/BUILD.gn | 36 ++------ rtc_base/experiments/BUILD.gn | 3 +- rtc_base/synchronization/BUILD.gn | 2 +- rtc_base/unittest_main.cc | 149 ------------------------------ stats/BUILD.gn | 2 +- test/test_main_lib.cc | 6 ++ 9 files changed, 23 insertions(+), 184 deletions(-) delete mode 100644 rtc_base/unittest_main.cc diff --git a/BUILD.gn b/BUILD.gn index 95d7c30b98..4acda15c98 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -484,7 +484,6 @@ if (rtc_include_tests) { "p2p:libstunprober_unittests", "p2p:rtc_p2p_unittests", "rtc_base:rtc_base_approved_unittests", - "rtc_base:rtc_base_tests_main", "rtc_base:rtc_base_unittests", "rtc_base:rtc_json_unittests", "rtc_base:rtc_numerics_unittests", @@ -495,6 +494,7 @@ if (rtc_include_tests) { "rtc_base/synchronization:sequence_checker_unittests", "rtc_base/task_utils:to_queued_task_unittests", "sdk:sdk_tests", + "test:test_main", "test/scenario/network:network_emulation_unittests", ] diff --git a/media/BUILD.gn b/media/BUILD.gn index f28461e275..a5a37e67ca 100644 --- a/media/BUILD.gn +++ b/media/BUILD.gn @@ -545,18 +545,19 @@ if (rtc_include_tests) { "../rtc_base:checks", "../rtc_base:gunit_helpers", "../rtc_base:rtc_base_approved", - "../rtc_base:rtc_base_tests_main", "../rtc_base:rtc_base_tests_utils", "../rtc_base:rtc_task_queue", "../rtc_base:stringutils", "../rtc_base/third_party/sigslot", "../test:audio_codec_mocks", "../test:field_trial", + "../test:test_main", "../test:test_support", "../test:video_test_common", "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/types:optional", ] sources = [ "base/codec_unittest.cc", diff --git a/pc/BUILD.gn b/pc/BUILD.gn index dd9ca6be13..62a818609e 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -307,10 +307,10 @@ if (rtc_include_tests) { "../rtc_base:checks", "../rtc_base:gunit_helpers", "../rtc_base:rtc_base_approved", - "../rtc_base:rtc_base_tests_main", "../rtc_base:rtc_base_tests_utils", "../rtc_base/third_party/sigslot", "../system_wrappers:metrics", + "../test:test_main", "../test:test_support", "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/memory", @@ -571,10 +571,10 @@ if (rtc_include_tests) { "../pc:rtc_pc", "../rtc_base", "../rtc_base:rtc_base_approved", - "../rtc_base:rtc_base_tests_main", "../rtc_base:rtc_task_queue", "../rtc_base:safe_conversions", "../test:audio_codec_mocks", + "../test:test_main", "../test:test_support", "//third_party/abseil-cpp/absl/types:optional", ] diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 72b7229473..a3dd22eee1 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -1129,27 +1129,6 @@ if (rtc_include_tests) { ] } - rtc_source_set("rtc_base_tests_main") { - testonly = true - sources = [ - "unittest_main.cc", - ] - deps = [ - ":gunit_helpers", - ":rtc_base", - ":rtc_base_approved", - ":rtc_base_tests_utils", - "../system_wrappers:field_trial", - "../system_wrappers:metrics", - "../test:field_trial", - "../test:test_support", - ] - - public_deps = [ - "//testing/gtest", - ] - } - rtc_source_set("rtc_base_nonparallel_tests") { testonly = true @@ -1166,11 +1145,11 @@ if (rtc_include_tests) { ":checks", ":gunit_helpers", ":rtc_base", - ":rtc_base_tests_main", ":rtc_base_tests_utils", ":testclient", "../system_wrappers", "../test:fileutils", + "../test:test_main", "../test:test_support", "third_party/sigslot", "//testing/gtest", @@ -1235,7 +1214,6 @@ if (rtc_include_tests) { ":rate_limiter", ":rtc_base", ":rtc_base_approved", - ":rtc_base_tests_main", ":rtc_base_tests_utils", ":rtc_task_queue", ":safe_compare", @@ -1248,6 +1226,7 @@ if (rtc_include_tests) { "../api/units:time_delta", "../system_wrappers", "../test:fileutils", + "../test:test_main", "../test:test_support", "memory:unittests", "third_party/base64", @@ -1265,10 +1244,10 @@ if (rtc_include_tests) { deps = [ ":gunit_helpers", ":rtc_base_approved", - ":rtc_base_tests_main", ":rtc_base_tests_utils", ":rtc_task_queue", ":task_queue_for_test", + "../test:test_main", "../test:test_support", "//third_party/abseil-cpp/absl/memory", ] @@ -1283,11 +1262,11 @@ if (rtc_include_tests) { deps = [ ":gunit_helpers", ":rtc_base_approved", - ":rtc_base_tests_main", ":rtc_base_tests_utils", ":rtc_event", ":task_queue_for_test", ":weak_ptr", + "../test:test_main", "../test:test_support", "//third_party/abseil-cpp/absl/memory", ] @@ -1307,8 +1286,8 @@ if (rtc_include_tests) { ] deps = [ ":rtc_base_approved", - ":rtc_base_tests_main", ":rtc_numerics", + "../test:test_main", "../test:test_support", "//third_party/abseil-cpp/absl/algorithm:container", ] @@ -1322,9 +1301,9 @@ if (rtc_include_tests) { ] deps = [ ":gunit_helpers", - ":rtc_base_tests_main", ":rtc_base_tests_utils", ":rtc_json", + "../test:test_main", "../test:test_support", ] } @@ -1374,18 +1353,19 @@ if (rtc_include_tests) { deps = [ ":checks", ":gunit_helpers", - ":rtc_base_tests_main", ":rtc_base_tests_utils", ":stringutils", ":testclient", "../api:array_view", "../test:fileutils", + "../test:test_main", "../test:test_support", "memory:fifo_buffer", "synchronization:synchronization_unittests", "third_party/sigslot", "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] public_deps = [ diff --git a/rtc_base/experiments/BUILD.gn b/rtc_base/experiments/BUILD.gn index 2ea6ed074b..6daac42921 100644 --- a/rtc_base/experiments/BUILD.gn +++ b/rtc_base/experiments/BUILD.gn @@ -204,12 +204,13 @@ if (rtc_include_tests) { ":rate_control_settings", ":rtt_mult_experiment", "..:gunit_helpers", - "../:rtc_base_tests_main", "../:rtc_base_tests_utils", "../../api/video_codecs:video_codecs_api", "../../system_wrappers:field_trial", "../../test:field_trial", + "../../test:test_main", "../../test:test_support", + "//third_party/abseil-cpp/absl/types:optional", ] } } diff --git a/rtc_base/synchronization/BUILD.gn b/rtc_base/synchronization/BUILD.gn index 93a3fee8fd..ba44c79d62 100644 --- a/rtc_base/synchronization/BUILD.gn +++ b/rtc_base/synchronization/BUILD.gn @@ -83,9 +83,9 @@ if (rtc_include_tests) { ":sequence_checker", "..:checks", "..:rtc_base_approved", - "..:rtc_base_tests_main", "..:task_queue_for_test", "../../api:function_view", + "../../test:test_main", "../../test:test_support", "//third_party/abseil-cpp/absl/memory", ] diff --git a/rtc_base/unittest_main.cc b/rtc_base/unittest_main.cc deleted file mode 100644 index fe3e9e49db..0000000000 --- a/rtc_base/unittest_main.cc +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2007 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ -// -// A reuseable entry point for gunit tests. - -#if defined(WEBRTC_WIN) -#include -#endif - -#include "rtc_base/flags.h" -#include "rtc_base/logging.h" -#include "rtc_base/ssl_adapter.h" -#include "rtc_base/ssl_stream_adapter.h" -#include "system_wrappers/include/field_trial.h" -#include "system_wrappers/include/metrics.h" -#include "test/field_trial.h" -#include "test/gtest.h" - -#if defined(WEBRTC_WIN) -#include "rtc_base/win32_socket_init.h" -#endif - -#if defined(WEBRTC_IOS) -#include "test/ios/test_support.h" -#endif - -WEBRTC_DEFINE_bool(help, false, "prints this message"); -WEBRTC_DEFINE_string(log, "", "logging options to use"); -WEBRTC_DEFINE_string( - force_fieldtrials, - "", - "Field trials control experimental feature code which can be forced. " - "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/" - " will assign the group Enable to field trial WebRTC-FooFeature."); -#if defined(WEBRTC_WIN) -WEBRTC_DEFINE_int(crt_break_alloc, -1, "memory allocation to break on"); -WEBRTC_DEFINE_bool( - default_error_handlers, - false, - "leave the default exception/dbg handler functions in place"); - -void TestInvalidParameterHandler(const wchar_t* expression, - const wchar_t* function, - const wchar_t* file, - unsigned int line, - uintptr_t pReserved) { - // In order to log `expression`, `function`, and `file` here, we would have - // to convert them to const char*. std::wcsrtombs can do that, but it's - // locale dependent. - RTC_LOG(LS_ERROR) << "InvalidParameter Handler called. Exiting."; - exit(1); -} -void TestPureCallHandler() { - RTC_LOG(LS_ERROR) << "Purecall Handler called. Exiting."; - exit(1); -} -int TestCrtReportHandler(int report_type, char* msg, int* retval) { - RTC_LOG(LS_ERROR) << "CrtReport Handler called..."; - RTC_LOG(LS_ERROR) << msg; - if (report_type == _CRT_ASSERT) { - exit(1); - } else { - *retval = 0; - return TRUE; - } -} -#endif // WEBRTC_WIN - -int main(int argc, char* argv[]) { - ::testing::InitGoogleTest(&argc, argv); - rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false); - if (FLAG_help) { - rtc::FlagList::Print(nullptr, false); - return 0; - } - - webrtc::test::ValidateFieldTrialsStringOrDie(FLAG_force_fieldtrials); - // InitFieldTrialsFromString stores the char*, so the char array must outlive - // the application. - webrtc::field_trial::InitFieldTrialsFromString(FLAG_force_fieldtrials); - webrtc::metrics::Enable(); - -#if defined(WEBRTC_WIN) - rtc::WinsockInitializer winsock_init; - - if (!FLAG_default_error_handlers) { - // Make sure any errors don't throw dialogs hanging the test run. - _set_invalid_parameter_handler(TestInvalidParameterHandler); - _set_purecall_handler(TestPureCallHandler); - _CrtSetReportHook2(_CRT_RPTHOOK_INSTALL, TestCrtReportHandler); - } - -#if !defined(NDEBUG) // Turn on memory leak checking on Windows. - _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); - if (FLAG_crt_break_alloc >= 0) { - _crtBreakAlloc = FLAG_crt_break_alloc; - } -#endif -#endif // WEBRTC_WIN - - // By default, log timestamps. Allow overrides by used of a --log flag. - rtc::LogMessage::LogTimestamps(); - if (*FLAG_log != '\0') { - rtc::LogMessage::ConfigureLogging(FLAG_log); - } else if (rtc::LogMessage::GetLogToDebug() > rtc::LS_INFO) { - // Default to LS_INFO, even for release builds to provide better test - // logging. - rtc::LogMessage::LogToDebug(rtc::LS_INFO); - } - - // Initialize SSL which are used by several tests. - rtc::InitializeSSL(); - rtc::SSLStreamAdapter::EnableTimeCallbackForTesting(); - -#if defined(WEBRTC_IOS) - rtc::test::InitTestSuite(RUN_ALL_TESTS, argc, argv, false); - rtc::test::RunTestsFromIOSApp(); -#endif - const int res = RUN_ALL_TESTS(); - - rtc::CleanupSSL(); - - // clean up logging so we don't appear to leak memory. - rtc::LogMessage::ConfigureLogging(""); - -#if defined(WEBRTC_WIN) - // Unhook crt function so that we don't ever log after statics have been - // uninitialized. - if (!FLAG_default_error_handlers) - _CrtSetReportHook2(_CRT_RPTHOOK_REMOVE, TestCrtReportHandler); -#endif - -#if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ - defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ - defined(UNDEFINED_SANITIZER) - // We want the test flagged as failed only for sanitizer defects, - // in which case the sanitizer will override exit code with 66. - return 0; -#endif - - return res; -} diff --git a/stats/BUILD.gn b/stats/BUILD.gn index 85fe091df9..b3a9d9eb31 100644 --- a/stats/BUILD.gn +++ b/stats/BUILD.gn @@ -61,8 +61,8 @@ if (rtc_include_tests) { "../rtc_base:checks", "../rtc_base:gunit_helpers", "../rtc_base:rtc_base_approved", - "../rtc_base:rtc_base_tests_main", "../rtc_base:rtc_json", + "../test:test_main", "../test:test_support", ] diff --git a/test/test_main_lib.cc b/test/test_main_lib.cc index 515285ebb5..dcc074986e 100644 --- a/test/test_main_lib.cc +++ b/test/test_main_lib.cc @@ -17,6 +17,8 @@ #include "rtc_base/checks.h" #include "rtc_base/flags.h" #include "rtc_base/logging.h" +#include "rtc_base/ssl_adapter.h" +#include "rtc_base/ssl_stream_adapter.h" #include "rtc_base/thread.h" #include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/metrics.h" @@ -120,6 +122,10 @@ class TestMainImpl : public TestMain { winsock_init_ = absl::make_unique(); #endif + // Initialize SSL which are used by several tests. + rtc::InitializeSSL(); + rtc::SSLStreamAdapter::EnableTimeCallbackForTesting(); + // Ensure that main thread gets wrapped as an rtc::Thread. // TODO(bugs.webrt.org/9714): It might be better to avoid wrapping the main // thread, or leave it to individual tests that need it. But as long as we