blob: c8d0b1b584e6a75c95f076a6df75a7c309e065cf [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
89 webrtc::test::SetExecutablePath(argv[0]);
Bjorn Tereliusedab3012018-01-31 17:23:40 +010090 webrtc::test::ValidateFieldTrialsStringOrDie(FLAG_force_fieldtrials);
91 // InitFieldTrialsFromString stores the char*, so the char array must outlive
92 // the application.
93 webrtc::field_trial::InitFieldTrialsFromString(FLAG_force_fieldtrials);
asapersson01d70a32016-05-20 06:29:46 -070094 webrtc::metrics::Enable();
ehmaldonado26bddb92016-11-30 06:12:01 -080095
Mirko Bonadeiba5eaee2018-09-17 12:20:10 +020096#if defined(WEBRTC_WIN)
97 rtc::WinsockInitializer winsock_init;
98#endif
99
oprypin9b2f20c2017-08-29 05:51:57 -0700100 rtc::LogMessage::SetLogToStderr(FLAG_logs);
Edward Lemure66572b2018-01-05 15:34:09 +0100101
Niels Möller8909a632018-09-06 08:42:44 +0200102 // Ensure that main thread gets wrapped as an rtc::Thread.
103 // TODO(bugs.webrt.org/9714): It might be better to avoid wrapping the main
104 // thread, or leave it to individual tests that need it. But as long as we
105 // have automatic thread wrapping, we need this to avoid that some other
106 // random thread (which one depending on which tests are run) gets
107 // automatically wrapped.
108 rtc::ThreadManager::Instance()->WrapCurrentThread();
109 RTC_CHECK(rtc::Thread::Current());
110
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +0200111#if defined(WEBRTC_IOS)
Edward Lemure66572b2018-01-05 15:34:09 +0100112
113 rtc::test::InitTestSuite(RUN_ALL_TESTS, argc, argv,
114 FLAG_save_chartjson_result);
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +0200115 rtc::test::RunTestsFromIOSApp();
Edward Lemure66572b2018-01-05 15:34:09 +0100116
117#else
ehmaldonado26bddb92016-11-30 06:12:01 -0800118
Edward Lemurab63bb52017-12-04 15:56:21 +0100119 int exit_code = RUN_ALL_TESTS();
120
Edward Lemur0c15a092018-02-08 20:16:41 +0100121 std::string chartjson_result_file = FLAG_isolated_script_test_perf_output;
Edward Lemur3460fa62018-01-08 15:52:14 +0100122 if (!chartjson_result_file.empty()) {
Edward Lemure66572b2018-01-05 15:34:09 +0100123 webrtc::test::WritePerfResults(chartjson_result_file);
Edward Lemurab63bb52017-12-04 15:56:21 +0100124 }
125
Oleh Prypin135aad02018-09-21 13:56:26 +0200126 std::string result_filename = FLAG_isolated_script_test_output;
127 if (!result_filename.empty()) {
128 std::ofstream result_file(result_filename);
129 result_file << "{\"version\": 3}";
130 result_file.close();
131 }
132
Edward Lemurab63bb52017-12-04 15:56:21 +0100133 return exit_code;
Edward Lemure66572b2018-01-05 15:34:09 +0100134
135#endif
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000136}