blob: 8091b3fb74e2bc416056156005dfd59678a71c2c [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"
Bjorn Tereliusedab3012018-01-31 17:23:40 +010016#include "system_wrappers/include/field_trial_default.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "system_wrappers/include/metrics_default.h"
18#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
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +020024#if defined(WEBRTC_IOS)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "test/ios/test_support.h"
oprypin51d49b42017-08-22 10:55:47 -070026
Yves Gerey665174f2018-06-19 15:03:05 +020027DEFINE_string(NSTreatUnknownArgumentsAsOpen,
28 "",
29 "Intentionally ignored flag intended for iOS simulator.");
30DEFINE_string(ApplePersistenceIgnoreState,
31 "",
32 "Intentionally ignored flag intended for iOS simulator.");
Edward Lemure66572b2018-01-05 15:34:09 +010033DEFINE_bool(
34 save_chartjson_result,
35 false,
36 "Store the perf results in Documents/perf_result.json in the format "
37 "described by "
38 "https://github.com/catapult-project/catapult/blob/master/dashboard/docs/"
39 "data-format.md.");
40
41#else
42
Oleh Prypin135aad02018-09-21 13:56:26 +020043DEFINE_string(
44 isolated_script_test_output,
45 "",
46 "Path to output an empty JSON file which Chromium infra requires.");
Edward Lemur0c15a092018-02-08 20:16:41 +010047
48DEFINE_string(
49 isolated_script_test_perf_output,
Edward Lemure66572b2018-01-05 15:34:09 +010050 "",
51 "Path where the perf results should be stored in the JSON format described "
52 "by "
53 "https://github.com/catapult-project/catapult/blob/master/dashboard/docs/"
54 "data-format.md.");
55
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +020056#endif
57
ehmaldonado26bddb92016-11-30 06:12:01 -080058DEFINE_bool(logs, false, "print logs to stderr");
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000059
Yves Gerey665174f2018-06-19 15:03:05 +020060DEFINE_string(
61 force_fieldtrials,
62 "",
andresp@webrtc.org60015d22014-05-16 09:39:51 +000063 "Field trials control experimental feature code which can be forced. "
64 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
65 " will assign the group Enable to field trial WebRTC-FooFeature.");
66
oprypin9b2f20c2017-08-29 05:51:57 -070067DEFINE_bool(help, false, "Print this message.");
68
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000069int main(int argc, char* argv[]) {
ehmaldonado26bddb92016-11-30 06:12:01 -080070 ::testing::InitGoogleMock(&argc, argv);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000071
Peter Boströmdef58202015-11-27 17:53:22 +010072 // Default to LS_INFO, even for release builds to provide better test logging.
73 // TODO(pbos): Consider adding a command-line override.
74 if (rtc::LogMessage::GetLogToDebug() > rtc::LS_INFO)
75 rtc::LogMessage::LogToDebug(rtc::LS_INFO);
76
oprypin9b2f20c2017-08-29 05:51:57 -070077 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false)) {
78 return 1;
79 }
80 if (FLAG_help) {
81 rtc::FlagList::Print(nullptr, false);
82 return 0;
83 }
andresp@webrtc.org60015d22014-05-16 09:39:51 +000084
85 webrtc::test::SetExecutablePath(argv[0]);
Bjorn Tereliusedab3012018-01-31 17:23:40 +010086 webrtc::test::ValidateFieldTrialsStringOrDie(FLAG_force_fieldtrials);
87 // InitFieldTrialsFromString stores the char*, so the char array must outlive
88 // the application.
89 webrtc::field_trial::InitFieldTrialsFromString(FLAG_force_fieldtrials);
asapersson01d70a32016-05-20 06:29:46 -070090 webrtc::metrics::Enable();
ehmaldonado26bddb92016-11-30 06:12:01 -080091
oprypin9b2f20c2017-08-29 05:51:57 -070092 rtc::LogMessage::SetLogToStderr(FLAG_logs);
Edward Lemure66572b2018-01-05 15:34:09 +010093
Niels Möller8909a632018-09-06 08:42:44 +020094 // Ensure that main thread gets wrapped as an rtc::Thread.
95 // TODO(bugs.webrt.org/9714): It might be better to avoid wrapping the main
96 // thread, or leave it to individual tests that need it. But as long as we
97 // have automatic thread wrapping, we need this to avoid that some other
98 // random thread (which one depending on which tests are run) gets
99 // automatically wrapped.
100 rtc::ThreadManager::Instance()->WrapCurrentThread();
101 RTC_CHECK(rtc::Thread::Current());
102
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +0200103#if defined(WEBRTC_IOS)
Edward Lemure66572b2018-01-05 15:34:09 +0100104
105 rtc::test::InitTestSuite(RUN_ALL_TESTS, argc, argv,
106 FLAG_save_chartjson_result);
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +0200107 rtc::test::RunTestsFromIOSApp();
Edward Lemure66572b2018-01-05 15:34:09 +0100108
109#else
ehmaldonado26bddb92016-11-30 06:12:01 -0800110
Edward Lemurab63bb52017-12-04 15:56:21 +0100111 int exit_code = RUN_ALL_TESTS();
112
Edward Lemur0c15a092018-02-08 20:16:41 +0100113 std::string chartjson_result_file = FLAG_isolated_script_test_perf_output;
Edward Lemur3460fa62018-01-08 15:52:14 +0100114 if (!chartjson_result_file.empty()) {
Edward Lemure66572b2018-01-05 15:34:09 +0100115 webrtc::test::WritePerfResults(chartjson_result_file);
Edward Lemurab63bb52017-12-04 15:56:21 +0100116 }
117
Oleh Prypin135aad02018-09-21 13:56:26 +0200118 std::string result_filename = FLAG_isolated_script_test_output;
119 if (!result_filename.empty()) {
120 std::ofstream result_file(result_filename);
121 result_file << "{\"version\": 3}";
122 result_file.close();
123 }
124
Edward Lemurab63bb52017-12-04 15:56:21 +0100125 return exit_code;
Edward Lemure66572b2018-01-05 15:34:09 +0100126
127#endif
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000128}