blob: 46a7de6b2219b42037a256576c89ddcb0aeb5432 [file] [log] [blame]
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_base/flags.h"
12#include "rtc_base/logging.h"
Niels Möller8909a632018-09-06 08:42:44 +020013#include "rtc_base/thread.h"
Bjorn Tereliusedab3012018-01-31 17:23:40 +010014#include "system_wrappers/include/field_trial_default.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "system_wrappers/include/metrics_default.h"
16#include "test/field_trial.h"
17#include "test/gmock.h"
18#include "test/gtest.h"
19#include "test/testsupport/fileutils.h"
Edward Lemurab63bb52017-12-04 15:56:21 +010020#include "test/testsupport/perf_test.h"
ehmaldonado26bddb92016-11-30 06:12:01 -080021
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +020022#if defined(WEBRTC_IOS)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "test/ios/test_support.h"
oprypin51d49b42017-08-22 10:55:47 -070024
Yves Gerey665174f2018-06-19 15:03:05 +020025DEFINE_string(NSTreatUnknownArgumentsAsOpen,
26 "",
27 "Intentionally ignored flag intended for iOS simulator.");
28DEFINE_string(ApplePersistenceIgnoreState,
29 "",
30 "Intentionally ignored flag intended for iOS simulator.");
Edward Lemure66572b2018-01-05 15:34:09 +010031DEFINE_bool(
32 save_chartjson_result,
33 false,
34 "Store the perf results in Documents/perf_result.json in the format "
35 "described by "
36 "https://github.com/catapult-project/catapult/blob/master/dashboard/docs/"
37 "data-format.md.");
38
39#else
40
Yves Gerey665174f2018-06-19 15:03:05 +020041DEFINE_string(isolated_script_test_output,
42 "",
43 "Intentionally ignored flag intended for Chromium.");
Edward Lemur0c15a092018-02-08 20:16:41 +010044
45DEFINE_string(
46 isolated_script_test_perf_output,
Edward Lemure66572b2018-01-05 15:34:09 +010047 "",
48 "Path where the perf results should be stored in the JSON format described "
49 "by "
50 "https://github.com/catapult-project/catapult/blob/master/dashboard/docs/"
51 "data-format.md.");
52
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +020053#endif
54
ehmaldonado26bddb92016-11-30 06:12:01 -080055DEFINE_bool(logs, false, "print logs to stderr");
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000056
Yves Gerey665174f2018-06-19 15:03:05 +020057DEFINE_string(
58 force_fieldtrials,
59 "",
andresp@webrtc.org60015d22014-05-16 09:39:51 +000060 "Field trials control experimental feature code which can be forced. "
61 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
62 " will assign the group Enable to field trial WebRTC-FooFeature.");
63
oprypin9b2f20c2017-08-29 05:51:57 -070064DEFINE_bool(help, false, "Print this message.");
65
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000066int main(int argc, char* argv[]) {
ehmaldonado26bddb92016-11-30 06:12:01 -080067 ::testing::InitGoogleMock(&argc, argv);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000068
Peter Boströmdef58202015-11-27 17:53:22 +010069 // Default to LS_INFO, even for release builds to provide better test logging.
70 // TODO(pbos): Consider adding a command-line override.
71 if (rtc::LogMessage::GetLogToDebug() > rtc::LS_INFO)
72 rtc::LogMessage::LogToDebug(rtc::LS_INFO);
73
oprypin9b2f20c2017-08-29 05:51:57 -070074 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false)) {
75 return 1;
76 }
77 if (FLAG_help) {
78 rtc::FlagList::Print(nullptr, false);
79 return 0;
80 }
andresp@webrtc.org60015d22014-05-16 09:39:51 +000081
82 webrtc::test::SetExecutablePath(argv[0]);
Bjorn Tereliusedab3012018-01-31 17:23:40 +010083 webrtc::test::ValidateFieldTrialsStringOrDie(FLAG_force_fieldtrials);
84 // InitFieldTrialsFromString stores the char*, so the char array must outlive
85 // the application.
86 webrtc::field_trial::InitFieldTrialsFromString(FLAG_force_fieldtrials);
asapersson01d70a32016-05-20 06:29:46 -070087 webrtc::metrics::Enable();
ehmaldonado26bddb92016-11-30 06:12:01 -080088
oprypin9b2f20c2017-08-29 05:51:57 -070089 rtc::LogMessage::SetLogToStderr(FLAG_logs);
Edward Lemure66572b2018-01-05 15:34:09 +010090
Niels Möller8909a632018-09-06 08:42:44 +020091 // Ensure that main thread gets wrapped as an rtc::Thread.
92 // TODO(bugs.webrt.org/9714): It might be better to avoid wrapping the main
93 // thread, or leave it to individual tests that need it. But as long as we
94 // have automatic thread wrapping, we need this to avoid that some other
95 // random thread (which one depending on which tests are run) gets
96 // automatically wrapped.
97 rtc::ThreadManager::Instance()->WrapCurrentThread();
98 RTC_CHECK(rtc::Thread::Current());
99
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +0200100#if defined(WEBRTC_IOS)
Edward Lemure66572b2018-01-05 15:34:09 +0100101
102 rtc::test::InitTestSuite(RUN_ALL_TESTS, argc, argv,
103 FLAG_save_chartjson_result);
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +0200104 rtc::test::RunTestsFromIOSApp();
Edward Lemure66572b2018-01-05 15:34:09 +0100105
106#else
ehmaldonado26bddb92016-11-30 06:12:01 -0800107
Edward Lemurab63bb52017-12-04 15:56:21 +0100108 int exit_code = RUN_ALL_TESTS();
109
Edward Lemur0c15a092018-02-08 20:16:41 +0100110 std::string chartjson_result_file = FLAG_isolated_script_test_perf_output;
Edward Lemur3460fa62018-01-08 15:52:14 +0100111 if (!chartjson_result_file.empty()) {
Edward Lemure66572b2018-01-05 15:34:09 +0100112 webrtc::test::WritePerfResults(chartjson_result_file);
Edward Lemurab63bb52017-12-04 15:56:21 +0100113 }
114
115 return exit_code;
Edward Lemure66572b2018-01-05 15:34:09 +0100116
117#endif
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000118}