
This is a reland of 711a31aead9007e42dd73c302c8ec40f9e931619 Changes since original landing: Rename methods only used by tests, mainly via FakeClock, MessageQueueManager::ProcessAllMessageQueues --> ProcessAllMessageQueuesForTesting MessageQueue::IsProcessingMessages --> IsProcessingMessagesForTesting Fix the handling of null rtc::Thread::Current() in ProcessAllMessageQueuesInternal(). Add override Thread::IsProcessingMessagesForTesting() to return false for the wrapped main thread, unless it's also the current thread. In tests, the main thread is typically not processing any messages, but blocked in an Event::Wait(). Original change's description: > Explicitly wrap main thread in test_main.cc. > > Bug: webrtc:9714 > Change-Id: I6ee234f9a0b88b3656a683f2455c3e4b2acf0d54 > Reviewed-on: https://webrtc-review.googlesource.com/97683 > Reviewed-by: Tommi <tommi@webrtc.org> > Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> > Commit-Queue: Niels Moller <nisse@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#24560} Bug: webrtc:9714 Change-Id: I6f022d46aaf1e28f86f09f2d68c1803b69770126 Reviewed-on: https://webrtc-review.googlesource.com/98060 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24596}
119 lines
3.8 KiB
C++
119 lines
3.8 KiB
C++
/*
|
|
* Copyright (c) 2013 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.
|
|
*/
|
|
|
|
#include "rtc_base/flags.h"
|
|
#include "rtc_base/logging.h"
|
|
#include "rtc_base/thread.h"
|
|
#include "system_wrappers/include/field_trial_default.h"
|
|
#include "system_wrappers/include/metrics_default.h"
|
|
#include "test/field_trial.h"
|
|
#include "test/gmock.h"
|
|
#include "test/gtest.h"
|
|
#include "test/testsupport/fileutils.h"
|
|
#include "test/testsupport/perf_test.h"
|
|
|
|
#if defined(WEBRTC_IOS)
|
|
#include "test/ios/test_support.h"
|
|
|
|
DEFINE_string(NSTreatUnknownArgumentsAsOpen,
|
|
"",
|
|
"Intentionally ignored flag intended for iOS simulator.");
|
|
DEFINE_string(ApplePersistenceIgnoreState,
|
|
"",
|
|
"Intentionally ignored flag intended for iOS simulator.");
|
|
DEFINE_bool(
|
|
save_chartjson_result,
|
|
false,
|
|
"Store the perf results in Documents/perf_result.json in the format "
|
|
"described by "
|
|
"https://github.com/catapult-project/catapult/blob/master/dashboard/docs/"
|
|
"data-format.md.");
|
|
|
|
#else
|
|
|
|
DEFINE_string(isolated_script_test_output,
|
|
"",
|
|
"Intentionally ignored flag intended for Chromium.");
|
|
|
|
DEFINE_string(
|
|
isolated_script_test_perf_output,
|
|
"",
|
|
"Path where the perf results should be stored in the JSON format described "
|
|
"by "
|
|
"https://github.com/catapult-project/catapult/blob/master/dashboard/docs/"
|
|
"data-format.md.");
|
|
|
|
#endif
|
|
|
|
DEFINE_bool(logs, false, "print logs to stderr");
|
|
|
|
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.");
|
|
|
|
DEFINE_bool(help, false, "Print this message.");
|
|
|
|
int main(int argc, char* argv[]) {
|
|
::testing::InitGoogleMock(&argc, argv);
|
|
|
|
// Default to LS_INFO, even for release builds to provide better test logging.
|
|
// TODO(pbos): Consider adding a command-line override.
|
|
if (rtc::LogMessage::GetLogToDebug() > rtc::LS_INFO)
|
|
rtc::LogMessage::LogToDebug(rtc::LS_INFO);
|
|
|
|
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false)) {
|
|
return 1;
|
|
}
|
|
if (FLAG_help) {
|
|
rtc::FlagList::Print(nullptr, false);
|
|
return 0;
|
|
}
|
|
|
|
webrtc::test::SetExecutablePath(argv[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();
|
|
|
|
rtc::LogMessage::SetLogToStderr(FLAG_logs);
|
|
|
|
// 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
|
|
// have automatic thread wrapping, we need this to avoid that some other
|
|
// random thread (which one depending on which tests are run) gets
|
|
// automatically wrapped.
|
|
rtc::ThreadManager::Instance()->WrapCurrentThread();
|
|
RTC_CHECK(rtc::Thread::Current());
|
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
rtc::test::InitTestSuite(RUN_ALL_TESTS, argc, argv,
|
|
FLAG_save_chartjson_result);
|
|
rtc::test::RunTestsFromIOSApp();
|
|
|
|
#else
|
|
|
|
int exit_code = RUN_ALL_TESTS();
|
|
|
|
std::string chartjson_result_file = FLAG_isolated_script_test_perf_output;
|
|
if (!chartjson_result_file.empty()) {
|
|
webrtc::test::WritePerfResults(chartjson_result_file);
|
|
}
|
|
|
|
return exit_code;
|
|
|
|
#endif
|
|
}
|