pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 1 | /* |
| 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 Prypin | 135aad0 | 2018-09-21 13:56:26 +0200 | [diff] [blame] | 11 | #include <fstream> |
| 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "rtc_base/flags.h" |
| 14 | #include "rtc_base/logging.h" |
Niels Möller | 8909a63 | 2018-09-06 08:42:44 +0200 | [diff] [blame] | 15 | #include "rtc_base/thread.h" |
Mirko Bonadei | 17f4878 | 2018-09-28 08:51:10 +0200 | [diff] [blame] | 16 | #include "system_wrappers/include/field_trial.h" |
| 17 | #include "system_wrappers/include/metrics.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "test/field_trial.h" |
| 19 | #include "test/gmock.h" |
| 20 | #include "test/gtest.h" |
| 21 | #include "test/testsupport/fileutils.h" |
Edward Lemur | ab63bb5 | 2017-12-04 15:56:21 +0100 | [diff] [blame] | 22 | #include "test/testsupport/perf_test.h" |
ehmaldonado | 26bddb9 | 2016-11-30 06:12:01 -0800 | [diff] [blame] | 23 | |
Mirko Bonadei | ba5eaee | 2018-09-17 12:20:10 +0200 | [diff] [blame] | 24 | #if defined(WEBRTC_WIN) |
| 25 | #include "rtc_base/win32socketinit.h" |
| 26 | #endif |
| 27 | |
Kári Tristan Helgason | e2baffb | 2017-06-09 10:31:58 +0200 | [diff] [blame] | 28 | #if defined(WEBRTC_IOS) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "test/ios/test_support.h" |
oprypin | 51d49b4 | 2017-08-22 10:55:47 -0700 | [diff] [blame] | 30 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 31 | DEFINE_string(NSTreatUnknownArgumentsAsOpen, |
| 32 | "", |
| 33 | "Intentionally ignored flag intended for iOS simulator."); |
| 34 | DEFINE_string(ApplePersistenceIgnoreState, |
| 35 | "", |
| 36 | "Intentionally ignored flag intended for iOS simulator."); |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 37 | DEFINE_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 Prypin | 135aad0 | 2018-09-21 13:56:26 +0200 | [diff] [blame] | 47 | DEFINE_string( |
| 48 | isolated_script_test_output, |
| 49 | "", |
| 50 | "Path to output an empty JSON file which Chromium infra requires."); |
Edward Lemur | 0c15a09 | 2018-02-08 20:16:41 +0100 | [diff] [blame] | 51 | |
| 52 | DEFINE_string( |
| 53 | isolated_script_test_perf_output, |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 54 | "", |
| 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 Helgason | e2baffb | 2017-06-09 10:31:58 +0200 | [diff] [blame] | 60 | #endif |
| 61 | |
ehmaldonado | 26bddb9 | 2016-11-30 06:12:01 -0800 | [diff] [blame] | 62 | DEFINE_bool(logs, false, "print logs to stderr"); |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 63 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 64 | DEFINE_string( |
| 65 | force_fieldtrials, |
| 66 | "", |
andresp@webrtc.org | 60015d2 | 2014-05-16 09:39:51 +0000 | [diff] [blame] | 67 | "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 | |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 71 | DEFINE_bool(help, false, "Print this message."); |
| 72 | |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 73 | int main(int argc, char* argv[]) { |
ehmaldonado | 26bddb9 | 2016-11-30 06:12:01 -0800 | [diff] [blame] | 74 | ::testing::InitGoogleMock(&argc, argv); |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 75 | |
Peter Boström | def5820 | 2015-11-27 17:53:22 +0100 | [diff] [blame] | 76 | // 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 | |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 81 | 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.org | 60015d2 | 2014-05-16 09:39:51 +0000 | [diff] [blame] | 88 | |
Patrik Höglund | 7730193 | 2018-10-09 15:09:51 +0200 | [diff] [blame] | 89 | // 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 Terelius | edab301 | 2018-01-31 17:23:40 +0100 | [diff] [blame] | 96 | 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); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 100 | webrtc::metrics::Enable(); |
ehmaldonado | 26bddb9 | 2016-11-30 06:12:01 -0800 | [diff] [blame] | 101 | |
Mirko Bonadei | ba5eaee | 2018-09-17 12:20:10 +0200 | [diff] [blame] | 102 | #if defined(WEBRTC_WIN) |
| 103 | rtc::WinsockInitializer winsock_init; |
| 104 | #endif |
| 105 | |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 106 | rtc::LogMessage::SetLogToStderr(FLAG_logs); |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 107 | |
Niels Möller | 8909a63 | 2018-09-06 08:42:44 +0200 | [diff] [blame] | 108 | // 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 Helgason | e2baffb | 2017-06-09 10:31:58 +0200 | [diff] [blame] | 117 | #if defined(WEBRTC_IOS) |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 118 | |
| 119 | rtc::test::InitTestSuite(RUN_ALL_TESTS, argc, argv, |
| 120 | FLAG_save_chartjson_result); |
Kári Tristan Helgason | e2baffb | 2017-06-09 10:31:58 +0200 | [diff] [blame] | 121 | rtc::test::RunTestsFromIOSApp(); |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 122 | |
| 123 | #else |
ehmaldonado | 26bddb9 | 2016-11-30 06:12:01 -0800 | [diff] [blame] | 124 | |
Edward Lemur | ab63bb5 | 2017-12-04 15:56:21 +0100 | [diff] [blame] | 125 | int exit_code = RUN_ALL_TESTS(); |
| 126 | |
Edward Lemur | 0c15a09 | 2018-02-08 20:16:41 +0100 | [diff] [blame] | 127 | std::string chartjson_result_file = FLAG_isolated_script_test_perf_output; |
Edward Lemur | 3460fa6 | 2018-01-08 15:52:14 +0100 | [diff] [blame] | 128 | if (!chartjson_result_file.empty()) { |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 129 | webrtc::test::WritePerfResults(chartjson_result_file); |
Edward Lemur | ab63bb5 | 2017-12-04 15:56:21 +0100 | [diff] [blame] | 130 | } |
| 131 | |
Oleh Prypin | 135aad0 | 2018-09-21 13:56:26 +0200 | [diff] [blame] | 132 | 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 Lemur | ab63bb5 | 2017-12-04 15:56:21 +0100 | [diff] [blame] | 139 | return exit_code; |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 140 | |
| 141 | #endif |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 142 | } |