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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "rtc_base/flags.h" |
| 12 | #include "rtc_base/logging.h" |
Niels Möller | 8909a63 | 2018-09-06 08:42:44 +0200 | [diff] [blame^] | 13 | #include "rtc_base/thread.h" |
Bjorn Terelius | edab301 | 2018-01-31 17:23:40 +0100 | [diff] [blame] | 14 | #include "system_wrappers/include/field_trial_default.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #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 Lemur | ab63bb5 | 2017-12-04 15:56:21 +0100 | [diff] [blame] | 20 | #include "test/testsupport/perf_test.h" |
ehmaldonado | 26bddb9 | 2016-11-30 06:12:01 -0800 | [diff] [blame] | 21 | |
Kári Tristan Helgason | e2baffb | 2017-06-09 10:31:58 +0200 | [diff] [blame] | 22 | #if defined(WEBRTC_IOS) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "test/ios/test_support.h" |
oprypin | 51d49b4 | 2017-08-22 10:55:47 -0700 | [diff] [blame] | 24 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 25 | DEFINE_string(NSTreatUnknownArgumentsAsOpen, |
| 26 | "", |
| 27 | "Intentionally ignored flag intended for iOS simulator."); |
| 28 | DEFINE_string(ApplePersistenceIgnoreState, |
| 29 | "", |
| 30 | "Intentionally ignored flag intended for iOS simulator."); |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 31 | DEFINE_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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 41 | DEFINE_string(isolated_script_test_output, |
| 42 | "", |
| 43 | "Intentionally ignored flag intended for Chromium."); |
Edward Lemur | 0c15a09 | 2018-02-08 20:16:41 +0100 | [diff] [blame] | 44 | |
| 45 | DEFINE_string( |
| 46 | isolated_script_test_perf_output, |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 47 | "", |
| 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 Helgason | e2baffb | 2017-06-09 10:31:58 +0200 | [diff] [blame] | 53 | #endif |
| 54 | |
ehmaldonado | 26bddb9 | 2016-11-30 06:12:01 -0800 | [diff] [blame] | 55 | DEFINE_bool(logs, false, "print logs to stderr"); |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 56 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 57 | DEFINE_string( |
| 58 | force_fieldtrials, |
| 59 | "", |
andresp@webrtc.org | 60015d2 | 2014-05-16 09:39:51 +0000 | [diff] [blame] | 60 | "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 | |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 64 | DEFINE_bool(help, false, "Print this message."); |
| 65 | |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 66 | int main(int argc, char* argv[]) { |
ehmaldonado | 26bddb9 | 2016-11-30 06:12:01 -0800 | [diff] [blame] | 67 | ::testing::InitGoogleMock(&argc, argv); |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 68 | |
Peter Boström | def5820 | 2015-11-27 17:53:22 +0100 | [diff] [blame] | 69 | // 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 | |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 74 | 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.org | 60015d2 | 2014-05-16 09:39:51 +0000 | [diff] [blame] | 81 | |
| 82 | webrtc::test::SetExecutablePath(argv[0]); |
Bjorn Terelius | edab301 | 2018-01-31 17:23:40 +0100 | [diff] [blame] | 83 | 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); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 87 | webrtc::metrics::Enable(); |
ehmaldonado | 26bddb9 | 2016-11-30 06:12:01 -0800 | [diff] [blame] | 88 | |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 89 | rtc::LogMessage::SetLogToStderr(FLAG_logs); |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 90 | |
Niels Möller | 8909a63 | 2018-09-06 08:42:44 +0200 | [diff] [blame^] | 91 | // 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 Helgason | e2baffb | 2017-06-09 10:31:58 +0200 | [diff] [blame] | 100 | #if defined(WEBRTC_IOS) |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 101 | |
| 102 | rtc::test::InitTestSuite(RUN_ALL_TESTS, argc, argv, |
| 103 | FLAG_save_chartjson_result); |
Kári Tristan Helgason | e2baffb | 2017-06-09 10:31:58 +0200 | [diff] [blame] | 104 | rtc::test::RunTestsFromIOSApp(); |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 105 | |
| 106 | #else |
ehmaldonado | 26bddb9 | 2016-11-30 06:12:01 -0800 | [diff] [blame] | 107 | |
Edward Lemur | ab63bb5 | 2017-12-04 15:56:21 +0100 | [diff] [blame] | 108 | int exit_code = RUN_ALL_TESTS(); |
| 109 | |
Edward Lemur | 0c15a09 | 2018-02-08 20:16:41 +0100 | [diff] [blame] | 110 | std::string chartjson_result_file = FLAG_isolated_script_test_perf_output; |
Edward Lemur | 3460fa6 | 2018-01-08 15:52:14 +0100 | [diff] [blame] | 111 | if (!chartjson_result_file.empty()) { |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 112 | webrtc::test::WritePerfResults(chartjson_result_file); |
Edward Lemur | ab63bb5 | 2017-12-04 15:56:21 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | return exit_code; |
Edward Lemur | e66572b | 2018-01-05 15:34:09 +0100 | [diff] [blame] | 116 | |
| 117 | #endif |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 118 | } |