Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(903)

Side by Side Diff: chrome/test/test_launcher/test_runner.cc

Issue 197045: Implement a way to run each interactive UI test isolated (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/test_launcher/test_runner.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/browser/browser_test_runner.h" 5 #include "chrome/test/test_launcher/test_runner.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/process_util.h" 11 #include "base/process_util.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 14
15 namespace { 15 namespace {
16 16
17 const wchar_t* const kGTestListTestsFlag = L"gtest_list_tests"; 17 const wchar_t* const kGTestListTestsFlag = L"gtest_list_tests";
18 const wchar_t* const kGTestRunDisabledTestsFlag = 18 const wchar_t* const kGTestRunDisabledTestsFlag =
19 L"gtest_also_run_disabled_tests"; 19 L"gtest_also_run_disabled_tests";
20 20
21 // Retrieves the list of tests to run by running gtest with the 21 // Retrieves the list of tests to run by running gtest with the
22 // --gtest_list_tests flag in a forked process and parsing its output. 22 // --gtest_list_tests flag in a forked process and parsing its output.
23 // |command_line| should contain the command line used to start the browser 23 // |command_line| should contain the command line used to start the browser
24 // test launcher, it is expected that it does not contain the 24 // test launcher, it is expected that it does not contain the
25 // --gtest_list_tests flag already. 25 // --gtest_list_tests flag already.
26 // Note: we cannot implement this in-process for InProcessBrowserTestRunner as 26 // Note: we cannot implement this in-process for InProcessTestRunner as GTest
27 // GTest prints to the stdout and there are no good way of temporarily 27 // prints to the stdout and there are no good way of temporarily redirecting
28 // redirecting outputs. 28 // outputs.
29 bool GetTestList(const CommandLine& command_line, 29 bool GetTestList(const CommandLine& command_line,
30 std::vector<std::string>* test_list) { 30 std::vector<std::string>* test_list) {
31 DCHECK(!command_line.HasSwitch(kGTestListTestsFlag)); 31 DCHECK(!command_line.HasSwitch(kGTestListTestsFlag));
32 32
33 // Run ourselves with the --gtest_list_tests option and read the output. 33 // Run ourselves with the --gtest_list_tests option and read the output.
34 CommandLine new_command_line(command_line); 34 CommandLine new_command_line(command_line);
35 new_command_line.AppendSwitch(kGTestListTestsFlag); 35 new_command_line.AppendSwitch(kGTestListTestsFlag);
36 std::string output; 36 std::string output;
37 if (!base::GetAppOutput(new_command_line, &output)) 37 if (!base::GetAppOutput(new_command_line, &output))
38 return false; 38 return false;
(...skipping 26 matching lines...) Expand all
65 continue; // Skip disabled tests. 65 continue; // Skip disabled tests.
66 66
67 // We are dealing with a test. 67 // We are dealing with a test.
68 test_list->push_back(test_case + line); 68 test_list->push_back(test_case + line);
69 } 69 }
70 return true; 70 return true;
71 } 71 }
72 72
73 } // namespace 73 } // namespace
74 74
75 namespace browser_tests { 75 namespace tests {
76 76
77 BrowserTestRunner::BrowserTestRunner() { 77 TestRunner::TestRunner() {
78 } 78 }
79 79
80 BrowserTestRunner::~BrowserTestRunner() { 80 TestRunner::~TestRunner() {
81 } 81 }
82 82
83 bool RunTests(const BrowserTestRunnerFactory& browser_test_runner_factory) { 83 bool RunTests(const TestRunnerFactory& test_runner_factory) {
84 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 84 const CommandLine* command_line = CommandLine::ForCurrentProcess();
85 85
86 DCHECK(!command_line->HasSwitch(kGTestListTestsFlag)); 86 DCHECK(!command_line->HasSwitch(kGTestListTestsFlag));
87 87
88 // First let's get the list of tests we need to run. 88 // First let's get the list of tests we need to run.
89 std::vector<std::string> test_list; 89 std::vector<std::string> test_list;
90 if (!GetTestList(*command_line, &test_list)) { 90 if (!GetTestList(*command_line, &test_list)) {
91 printf("Failed to retrieve the tests to run.\n"); 91 printf("Failed to retrieve the tests to run.\n");
92 return false; 92 return false;
93 } 93 }
94 94
95 if (test_list.empty()) { 95 if (test_list.empty()) {
96 printf("No tests to run.\n"); 96 printf("No tests to run.\n");
97 return false; 97 return false;
98 } 98 }
99 99
100 int test_run_count = 0; 100 int test_run_count = 0;
101 std::vector<std::string> failed_tests; 101 std::vector<std::string> failed_tests;
102 for (std::vector<std::string>::const_iterator iter = test_list.begin(); 102 for (std::vector<std::string>::const_iterator iter = test_list.begin();
103 iter != test_list.end(); ++iter) { 103 iter != test_list.end(); ++iter) {
104 std::string test_name = *iter; 104 std::string test_name = *iter;
105 scoped_ptr<BrowserTestRunner> test_runner( 105 scoped_ptr<TestRunner> test_runner(test_runner_factory.CreateTestRunner());
106 browser_test_runner_factory.CreateBrowserTestRunner());
107 if (!test_runner.get() || !test_runner->Init()) 106 if (!test_runner.get() || !test_runner->Init())
108 return false; 107 return false;
109 test_run_count++; 108 test_run_count++;
110 if (!test_runner->RunTest(test_name.c_str())) { 109 if (!test_runner->RunTest(test_name.c_str())) {
111 if (std::find(failed_tests.begin(), failed_tests.end(), test_name) == 110 if (std::find(failed_tests.begin(), failed_tests.end(), test_name) ==
112 failed_tests.end()) { 111 failed_tests.end()) {
113 failed_tests.push_back(*iter); 112 failed_tests.push_back(*iter);
114 } 113 }
115 } 114 }
116 } 115 }
117 116
118 printf("%d test%s run\n", test_run_count, test_run_count > 1 ? "s" : ""); 117 printf("%d test%s run\n", test_run_count, test_run_count > 1 ? "s" : "");
119 printf("%d test%s failed\n", static_cast<int>(failed_tests.size()), 118 printf("%d test%s failed\n", static_cast<int>(failed_tests.size()),
120 failed_tests.size() > 1 ? "s" : ""); 119 failed_tests.size() > 1 ? "s" : "");
121 if (failed_tests.empty()) 120 if (failed_tests.empty())
122 return true; 121 return true;
123 122
124 printf("Failing tests:\n"); 123 printf("Failing tests:\n");
125 for (std::vector<std::string>::const_iterator iter = failed_tests.begin(); 124 for (std::vector<std::string>::const_iterator iter = failed_tests.begin();
126 iter != failed_tests.end(); ++iter) { 125 iter != failed_tests.end(); ++iter) {
127 printf("%s\n", iter->c_str()); 126 printf("%s\n", iter->c_str());
128 } 127 }
129 128
130 return false; 129 return false;
131 } 130 }
132 131
133 } // namespace 132 } // namespace
OLDNEW
« no previous file with comments | « chrome/test/test_launcher/test_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698