2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #include "webrtc/video_engine/test/auto_test/interface/vie_autotest_main.h"
13 #include "gflags/gflags.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webrtc/test/field_trial.h"
17 #include "webrtc/test/testsupport/fileutils.h"
18 #include "webrtc/video_engine/test/auto_test/interface/vie_autotest.h"
19 #include "webrtc/video_engine/test/auto_test/interface/vie_autotest_window_manager_interface.h"
20 #include "webrtc/video_engine/test/auto_test/interface/vie_window_creator.h"
22 DEFINE_bool(automated, false, "Run Video engine tests in noninteractive mode.");
23 DEFINE_bool(auto_custom_call, false, "Run custom call directly.");
24 DEFINE_string(force_fieldtrials, "",
25 "Field trials control experimental feature code which can be forced. "
26 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/"
27 " will assign the group Enable to field trial WebRTC-FooFeature.");
29 static const std::string kStandardTest = "ViEStandardIntegrationTest";
30 static const std::string kExtendedTest = "ViEExtendedIntegrationTest";
31 static const std::string kApiTest = "ViEApiIntegrationTest";
33 ViEAutoTestMain::ViEAutoTestMain() {
34 index_to_test_method_map_[1] = "RunsBaseTestWithoutErrors";
35 index_to_test_method_map_[2] = "RunsCaptureTestWithoutErrors";
36 index_to_test_method_map_[3] = "RunsCodecTestWithoutErrors";
37 index_to_test_method_map_[4] = "[unused]";
38 index_to_test_method_map_[5] = "RunsImageProcessTestWithoutErrors";
39 index_to_test_method_map_[6] = "RunsNetworkTestWithoutErrors";
40 index_to_test_method_map_[7] = "RunsRenderTestWithoutErrors";
41 index_to_test_method_map_[8] = "RunsRtpRtcpTestWithoutErrors";
44 int ViEAutoTestMain::RunTests(int argc, char** argv) {
45 // Initialize logging.
47 // Initialize WebRTC testing framework so paths to resources can be resolved.
48 webrtc::test::SetExecutablePath(argv[0]);
49 // Initialize the testing framework.
50 testing::InitGoogleTest(&argc, argv);
51 // AllowCommandLineParsing allows us to ignore flags passed on to us by
52 // Chromium build bots without having to explicitly disable them.
53 google::AllowCommandLineReparsing();
54 // Parse remaining flags:
55 google::ParseCommandLineFlags(&argc, &argv, true);
56 // Initialize field trial
57 webrtc::test::InitFieldTrialsFromString(FLAGS_force_fieldtrials);
60 if (FLAGS_automated) {
61 // Run in automated mode.
62 #if defined(WEBRTC_LINUX)
63 // All window-related tests are disabled on Linux for now.
64 // See https://code.google.com/p/chromium/issues/detail?id=318760
67 result = RUN_ALL_TESTS();
68 } else if (FLAGS_auto_custom_call) {
69 // Run automated custom call.
70 result = RunSpecialTestCase(8);
72 // Run in interactive mode.
73 result = RunInteractiveMode();
80 int ViEAutoTestMain::AskUserForTestCase() {
85 ViETest::Log("\nSpecific tests:");
86 ViETest::Log("\t 0. Go back to previous menu.");
88 // Print all test method choices. Assumes that map sorts on its key.
89 int last_valid_choice = 0;
90 std::map<int, std::string>::const_iterator iterator;
91 for (iterator = index_to_test_method_map_.begin();
92 iterator != index_to_test_method_map_.end();
94 ViETest::Log("\t %d. %s", iterator->first, iterator->second.c_str());
95 last_valid_choice = iterator->first;
98 ViETest::Log("Choose specific test:");
99 choice = AskUserForNumber(0, last_valid_choice);
100 } while (choice == kInvalidChoice);
105 int ViEAutoTestMain::AskUserForNumber(int min_allowed, int max_allowed) {
107 if (scanf("%d", &result) <= 0) {
108 ViETest::Log("\nPlease enter a number instead, then hit enter.");
110 return kInvalidChoice;
112 getc(stdin); // Consume enter key.
114 if (result < min_allowed || result > max_allowed) {
115 ViETest::Log("%d-%d are valid choices. Please try again.", min_allowed,
117 return kInvalidChoice;
123 int ViEAutoTestMain::RunTestMatching(const std::string test_case,
124 const std::string test_method) {
125 testing::FLAGS_gtest_filter = test_case + "." + test_method;
126 return RUN_ALL_TESTS();
129 int ViEAutoTestMain::RunSpecificTestCaseIn(const std::string test_case_name)
131 // If user says 0, it means don't run anything.
132 int specific_choice = AskUserForTestCase();
133 if (specific_choice != 0){
134 return RunTestMatching(test_case_name,
135 index_to_test_method_map_[specific_choice]);
140 int ViEAutoTestMain::RunSpecialTestCase(int choice) {
141 // 7-10 don't run in GTest and need to initialize by themselves.
142 assert(choice >= 7 && choice <= 10);
144 // Create the windows
145 ViEWindowCreator windowCreator;
146 ViEAutoTestWindowManagerInterface* windowManager =
147 windowCreator.CreateTwoWindows();
149 // Create the test cases
150 ViEAutoTest vieAutoTest(windowManager->GetWindow1(),
151 windowManager->GetWindow2());
155 case 7: errors = vieAutoTest.ViELoopbackCall(); break;
156 case 8: errors = vieAutoTest.ViECustomCall(); break;
157 case 9: errors = vieAutoTest.ViESimulcastCall(); break;
158 case 10: errors = vieAutoTest.ViERecordCall(); break;
161 windowCreator.TerminateWindows();
165 int ViEAutoTestMain::RunInteractiveMode() {
166 ViETest::Log(" ============================== ");
167 ViETest::Log(" WebRTC ViE 3.x Autotest ");
168 ViETest::Log(" ============================== \n");
173 ViETest::Log("Test types: ");
174 ViETest::Log("\t 0. Quit");
175 ViETest::Log("\t 1. All standard tests (delivery test)");
176 ViETest::Log("\t 2. All API tests");
177 ViETest::Log("\t 3. All extended test");
178 ViETest::Log("\t 4. Specific standard test");
179 ViETest::Log("\t 5. Specific API test");
180 ViETest::Log("\t 6. Specific extended test");
181 ViETest::Log("\t 7. Simple loopback call");
182 ViETest::Log("\t 8. Custom configure a call");
183 ViETest::Log("\t 9. Simulcast in loopback");
184 ViETest::Log("\t 10. Record");
185 ViETest::Log("Select type of test:");
187 choice = AskUserForNumber(0, 10);
188 if (choice == kInvalidChoice) {
193 case 1: errors = RunTestMatching(kStandardTest, "*"); break;
194 case 2: errors = RunTestMatching(kApiTest, "*"); break;
195 case 3: errors = RunTestMatching(kExtendedTest, "*"); break;
196 case 4: errors = RunSpecificTestCaseIn(kStandardTest); break;
197 case 5: errors = RunSpecificTestCaseIn(kApiTest); break;
198 case 6: errors = RunSpecificTestCaseIn(kExtendedTest); break;
199 default: errors = RunSpecialTestCase(choice); break;
201 } while (choice != 0);
204 ViETest::Log("Test done with errors, see ViEAutotestLog.txt for test "
208 ViETest::Log("Test done without errors, see ViEAutotestLog.txt for "