blob: ec32f2d3839a3a1b7e6656417c2af290c8780bf5 [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
Oleh Prypin135aad02018-09-21 13:56:26 +020011#include <fstream>
12
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "rtc_base/flags.h"
14#include "rtc_base/logging.h"
Niels Möller8909a632018-09-06 08:42:44 +020015#include "rtc_base/thread.h"
Mirko Bonadei17f48782018-09-28 08:51:10 +020016#include "system_wrappers/include/field_trial.h"
17#include "system_wrappers/include/metrics.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "test/field_trial.h"
19#include "test/gmock.h"
20#include "test/gtest.h"
21#include "test/testsupport/fileutils.h"
Edward Lemurab63bb52017-12-04 15:56:21 +010022#include "test/testsupport/perf_test.h"
ehmaldonado26bddb92016-11-30 06:12:01 -080023
Mirko Bonadeiba5eaee2018-09-17 12:20:10 +020024#if defined(WEBRTC_WIN)
25#include "rtc_base/win32socketinit.h"
26#endif
27
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +020028#if defined(WEBRTC_IOS)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "test/ios/test_support.h"
oprypin51d49b42017-08-22 10:55:47 -070030
Yves Gerey665174f2018-06-19 15:03:05 +020031DEFINE_string(NSTreatUnknownArgumentsAsOpen,
32 "",
33 "Intentionally ignored flag intended for iOS simulator.");
34DEFINE_string(ApplePersistenceIgnoreState,
35 "",
36 "Intentionally ignored flag intended for iOS simulator.");
Edward Lemure66572b2018-01-05 15:34:09 +010037DEFINE_bool(
38 save_chartjson_result,
39 false,
40 "Store the perf results in Documents/perf_result.json in the format "
41 "described by "
42 "https://github.com/catapult-project/catapult/blob/master/dashboard/docs/"
43 "data-format.md.");
44
45#else
46
Oleh Prypin135aad02018-09-21 13:56:26 +020047DEFINE_string(
48 isolated_script_test_output,
49 "",
50 "Path to output an empty JSON file which Chromium infra requires.");
Edward Lemur0c15a092018-02-08 20:16:41 +010051
52DEFINE_string(
53 isolated_script_test_perf_output,
Edward Lemure66572b2018-01-05 15:34:09 +010054 "",
55 "Path where the perf results should be stored in the JSON format described "
56 "by "
57 "https://github.com/catapult-project/catapult/blob/master/dashboard/docs/"
58 "data-format.md.");
59
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +020060#endif
61
ehmaldonado26bddb92016-11-30 06:12:01 -080062DEFINE_bool(logs, false, "print logs to stderr");
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000063
Yves Gerey665174f2018-06-19 15:03:05 +020064DEFINE_string(
65 force_fieldtrials,
66 "",
andresp@webrtc.org60015d22014-05-16 09:39:51 +000067 "Field trials control experimental feature code which can be forced. "
68 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
69 " will assign the group Enable to field trial WebRTC-FooFeature.");
70
oprypin9b2f20c2017-08-29 05:51:57 -070071DEFINE_bool(help, false, "Print this message.");
72
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000073int main(int argc, char* argv[]) {
ehmaldonado26bddb92016-11-30 06:12:01 -080074 ::testing::InitGoogleMock(&argc, argv);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000075
Peter Boströmdef58202015-11-27 17:53:22 +010076 // Default to LS_INFO, even for release builds to provide better test logging.
77 // TODO(pbos): Consider adding a command-line override.
78 if (rtc::LogMessage::GetLogToDebug() > rtc::LS_INFO)
79 rtc::LogMessage::LogToDebug(rtc::LS_INFO);
80
oprypin9b2f20c2017-08-29 05:51:57 -070081 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false)) {
82 return 1;
83 }
84 if (FLAG_help) {
85 rtc::FlagList::Print(nullptr, false);
86 return 0;
87 }
andresp@webrtc.org60015d22014-05-16 09:39:51 +000088
Patrik Höglund77301932018-10-09 15:09:51 +020089 // TODO(bugs.webrtc.org/9792): we need to reference something from fileutils.h
90 // so that our downstream hack where we replace fileutils.cc works. Otherwise
91 // the downstream flag implementation will take over and botch the flag
92 // introduced by the hack. Remove this awful thing once the downstream
93 // implementation has been eliminated.
94 (void)webrtc::test::JoinFilename("horrible", "hack");
95
Bjorn Tereliusedab3012018-01-31 17:23:40 +010096 webrtc::test::ValidateFieldTrialsStringOrDie(FLAG_force_fieldtrials);
97 // InitFieldTrialsFromString stores the char*, so the char array must outlive
98 // the application.
99 webrtc::field_trial::InitFieldTrialsFromString(FLAG_force_fieldtrials);
asapersson01d70a32016-05-20 06:29:46 -0700100 webrtc::metrics::Enable();
ehmaldonado26bddb92016-11-30 06:12:01 -0800101
Mirko Bonadeiba5eaee2018-09-17 12:20:10 +0200102#if defined(WEBRTC_WIN)
103 rtc::WinsockInitializer winsock_init;
104#endif
105
oprypin9b2f20c2017-08-29 05:51:57 -0700106 rtc::LogMessage::SetLogToStderr(FLAG_logs);
Edward Lemure66572b2018-01-05 15:34:09 +0100107
Niels Möller8909a632018-09-06 08:42:44 +0200108 // Ensure that main thread gets wrapped as an rtc::Thread.
109 // TODO(bugs.webrt.org/9714): It might be better to avoid wrapping the main
110 // thread, or leave it to individual tests that need it. But as long as we
111 // have automatic thread wrapping, we need this to avoid that some other
112 // random thread (which one depending on which tests are run) gets
113 // automatically wrapped.
114 rtc::ThreadManager::Instance()->WrapCurrentThread();
115 RTC_CHECK(rtc::Thread::Current());
116
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +0200117#if defined(WEBRTC_IOS)
Edward Lemure66572b2018-01-05 15:34:09 +0100118
119 rtc::test::InitTestSuite(RUN_ALL_TESTS, argc, argv,
120 FLAG_save_chartjson_result);
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +0200121 rtc::test::RunTestsFromIOSApp();
Edward Lemure66572b2018-01-05 15:34:09 +0100122
123#else
ehmaldonado26bddb92016-11-30 06:12:01 -0800124
Edward Lemurab63bb52017-12-04 15:56:21 +0100125 int exit_code = RUN_ALL_TESTS();
126
Edward Lemur0c15a092018-02-08 20:16:41 +0100127 std::string chartjson_result_file = FLAG_isolated_script_test_perf_output;
Edward Lemur3460fa62018-01-08 15:52:14 +0100128 if (!chartjson_result_file.empty()) {
Edward Lemure66572b2018-01-05 15:34:09 +0100129 webrtc::test::WritePerfResults(chartjson_result_file);
Edward Lemurab63bb52017-12-04 15:56:21 +0100130 }
131
Oleh Prypin135aad02018-09-21 13:56:26 +0200132 std::string result_filename = FLAG_isolated_script_test_output;
133 if (!result_filename.empty()) {
134 std::ofstream result_file(result_filename);
135 result_file << "{\"version\": 3}";
136 result_file.close();
137 }
138
Edward Lemurab63bb52017-12-04 15:56:21 +0100139 return exit_code;
Edward Lemure66572b2018-01-05 15:34:09 +0100140
141#endif
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000142}