blob: 5023ae65587a11ea04fb74bfe3fee7e05c257ebf [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
Mirko Bonadei7284e8a2017-12-14 15:05:18 +000011#include "rtc_base/file.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020012#include "rtc_base/flags.h"
13#include "rtc_base/logging.h"
14#include "system_wrappers/include/metrics_default.h"
15#include "test/field_trial.h"
16#include "test/gmock.h"
17#include "test/gtest.h"
18#include "test/testsupport/fileutils.h"
Edward Lemurab63bb52017-12-04 15:56:21 +010019#include "test/testsupport/perf_test.h"
ehmaldonado26bddb92016-11-30 06:12:01 -080020
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +020021#if defined(WEBRTC_IOS)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "test/ios/test_support.h"
oprypin51d49b42017-08-22 10:55:47 -070023
24DEFINE_string(NSTreatUnknownArgumentsAsOpen, "",
25 "Intentionally ignored flag intended for iOS simulator.");
26DEFINE_string(ApplePersistenceIgnoreState, "",
27 "Intentionally ignored flag intended for iOS simulator.");
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +020028#endif
29
ehmaldonado26bddb92016-11-30 06:12:01 -080030DEFINE_bool(logs, false, "print logs to stderr");
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000031
andresp@webrtc.org60015d22014-05-16 09:39:51 +000032DEFINE_string(force_fieldtrials, "",
33 "Field trials control experimental feature code which can be forced. "
34 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
35 " will assign the group Enable to field trial WebRTC-FooFeature.");
36
Mirko Bonadei712989d2017-12-14 12:51:07 +000037DEFINE_string(
Mirko Bonadei7284e8a2017-12-14 15:05:18 +000038 perf_results_json_path,
Mirko Bonadei712989d2017-12-14 12:51:07 +000039 "",
40 "Path where the perf results should be stored it the JSON format described "
41 "by "
42 "https://github.com/catapult-project/catapult/blob/master/dashboard/docs/"
43 "data-format.md.");
Edward Lemurab63bb52017-12-04 15:56:21 +010044
oprypin9b2f20c2017-08-29 05:51:57 -070045DEFINE_bool(help, false, "Print this message.");
46
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000047int main(int argc, char* argv[]) {
ehmaldonado26bddb92016-11-30 06:12:01 -080048 ::testing::InitGoogleMock(&argc, argv);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000049
Peter Boströmdef58202015-11-27 17:53:22 +010050 // Default to LS_INFO, even for release builds to provide better test logging.
51 // TODO(pbos): Consider adding a command-line override.
52 if (rtc::LogMessage::GetLogToDebug() > rtc::LS_INFO)
53 rtc::LogMessage::LogToDebug(rtc::LS_INFO);
54
oprypin9b2f20c2017-08-29 05:51:57 -070055 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false)) {
56 return 1;
57 }
58 if (FLAG_help) {
59 rtc::FlagList::Print(nullptr, false);
60 return 0;
61 }
andresp@webrtc.org60015d22014-05-16 09:39:51 +000062
63 webrtc::test::SetExecutablePath(argv[0]);
oprypin9b2f20c2017-08-29 05:51:57 -070064 std::string fieldtrials = FLAG_force_fieldtrials;
65 webrtc::test::InitFieldTrialsFromString(fieldtrials);
asapersson01d70a32016-05-20 06:29:46 -070066 webrtc::metrics::Enable();
ehmaldonado26bddb92016-11-30 06:12:01 -080067
oprypin9b2f20c2017-08-29 05:51:57 -070068 rtc::LogMessage::SetLogToStderr(FLAG_logs);
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +020069#if defined(WEBRTC_IOS)
Mirko Bonadei712989d2017-12-14 12:51:07 +000070 rtc::test::InitTestSuite(RUN_ALL_TESTS, argc, argv);
Kári Tristan Helgasone2baffb2017-06-09 10:31:58 +020071 rtc::test::RunTestsFromIOSApp();
Mirko Bonadei712989d2017-12-14 12:51:07 +000072#endif
ehmaldonado26bddb92016-11-30 06:12:01 -080073
Edward Lemurab63bb52017-12-04 15:56:21 +010074 int exit_code = RUN_ALL_TESTS();
75
Mirko Bonadei7284e8a2017-12-14 15:05:18 +000076 std::string perf_results_json_path = FLAG_perf_results_json_path;
77 if (perf_results_json_path != "") {
Mirko Bonadei712989d2017-12-14 12:51:07 +000078 std::string json_results = webrtc::test::GetPerfResultsJSON();
Mirko Bonadei7284e8a2017-12-14 15:05:18 +000079 rtc::File json_file = rtc::File::Open(perf_results_json_path);
80 json_file.Write(reinterpret_cast<const uint8_t*>(json_results.c_str()),
81 json_results.size());
82 json_file.Close();
Edward Lemurab63bb52017-12-04 15:56:21 +010083 }
84
85 return exit_code;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000086}