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

Side by Side Diff: base/test/test_launcher.cc

Issue 23450018: test launcher: Fix running a single test using filter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | « no previous file | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/test/test_launcher.h" 5 #include "base/test/test_launcher.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // Called when test named |name| is scheduled to be started. 121 // Called when test named |name| is scheduled to be started.
122 void OnTestStarted(const std::string& name); 122 void OnTestStarted(const std::string& name);
123 123
124 // Called when all tests that were to be started have been scheduled 124 // Called when all tests that were to be started have been scheduled
125 // to be started. 125 // to be started.
126 void OnAllTestsStarted(); 126 void OnAllTestsStarted();
127 127
128 // Adds |result| to the stored test results. 128 // Adds |result| to the stored test results.
129 void AddTestResult(const TestResult& result); 129 void AddTestResult(const TestResult& result);
130 130
131 WeakPtr<ResultsPrinter> GetWeakPtr();
132
131 private: 133 private:
132 // Prints a list of tests that finished with |status|. 134 // Prints a list of tests that finished with |status|.
133 void PrintTestsByStatus(TestResult::Status status, 135 void PrintTestsByStatus(TestResult::Status status,
134 const std::string& description); 136 const std::string& description);
135 137
136 // Test results grouped by test case name. 138 // Test results grouped by test case name.
137 typedef std::map<std::string, std::vector<TestResult> > ResultsMap; 139 typedef std::map<std::string, std::vector<TestResult> > ResultsMap;
138 ResultsMap results_; 140 ResultsMap results_;
139 141
140 // List of full names of failed tests. 142 // List of full names of failed tests.
141 typedef std::map<TestResult::Status, std::vector<std::string> > StatusMap; 143 typedef std::map<TestResult::Status, std::vector<std::string> > StatusMap;
142 StatusMap tests_by_status_; 144 StatusMap tests_by_status_;
143 145
144 size_t test_started_count_; 146 size_t test_started_count_;
145 147
146 // Total number of tests run. 148 // Total number of tests run.
147 size_t test_run_count_; 149 size_t test_run_count_;
148 150
149 // File handle of output file (can be NULL if no file). 151 // File handle of output file (can be NULL if no file).
150 FILE* out_; 152 FILE* out_;
151 153
152 RunTestsCallback callback_; 154 RunTestsCallback callback_;
153 155
154 ThreadChecker thread_checker_; 156 ThreadChecker thread_checker_;
155 157
158 WeakPtrFactory<ResultsPrinter> weak_ptr_;
159
156 DISALLOW_COPY_AND_ASSIGN(ResultsPrinter); 160 DISALLOW_COPY_AND_ASSIGN(ResultsPrinter);
157 }; 161 };
158 162
159 ResultsPrinter::ResultsPrinter(const CommandLine& command_line, 163 ResultsPrinter::ResultsPrinter(const CommandLine& command_line,
160 const RunTestsCallback& callback) 164 const RunTestsCallback& callback)
161 : test_started_count_(0), 165 : test_started_count_(0),
162 test_run_count_(0), 166 test_run_count_(0),
163 out_(NULL), 167 out_(NULL),
164 callback_(callback) { 168 callback_(callback),
169 weak_ptr_(this) {
165 if (!command_line.HasSwitch(kGTestOutputFlag)) 170 if (!command_line.HasSwitch(kGTestOutputFlag))
166 return; 171 return;
167 std::string flag = command_line.GetSwitchValueASCII(kGTestOutputFlag); 172 std::string flag = command_line.GetSwitchValueASCII(kGTestOutputFlag);
168 size_t colon_pos = flag.find(':'); 173 size_t colon_pos = flag.find(':');
169 FilePath path; 174 FilePath path;
170 if (colon_pos != std::string::npos) { 175 if (colon_pos != std::string::npos) {
171 FilePath flag_path = 176 FilePath flag_path =
172 command_line.GetSwitchValuePath(kGTestOutputFlag); 177 command_line.GetSwitchValuePath(kGTestOutputFlag);
173 FilePath::StringType path_string = flag_path.value(); 178 FilePath::StringType path_string = flag_path.value();
174 path = FilePath(path_string.substr(colon_pos + 1)); 179 path = FilePath(path_string.substr(colon_pos + 1));
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 PrintTestsByStatus(TestResult::TEST_CRASH, "crashed"); 289 PrintTestsByStatus(TestResult::TEST_CRASH, "crashed");
285 PrintTestsByStatus(TestResult::TEST_UNKNOWN, "had unknown result"); 290 PrintTestsByStatus(TestResult::TEST_UNKNOWN, "had unknown result");
286 291
287 callback_.Run( 292 callback_.Run(
288 tests_by_status_[TestResult::TEST_SUCCESS].size() == test_run_count_); 293 tests_by_status_[TestResult::TEST_SUCCESS].size() == test_run_count_);
289 294
290 delete this; 295 delete this;
291 } 296 }
292 } 297 }
293 298
299 WeakPtr<ResultsPrinter> ResultsPrinter::GetWeakPtr() {
300 return weak_ptr_.GetWeakPtr();
301 }
302
294 void ResultsPrinter::PrintTestsByStatus(TestResult::Status status, 303 void ResultsPrinter::PrintTestsByStatus(TestResult::Status status,
295 const std::string& description) { 304 const std::string& description) {
296 DCHECK(thread_checker_.CalledOnValidThread()); 305 DCHECK(thread_checker_.CalledOnValidThread());
297 306
298 const std::vector<std::string>& tests = tests_by_status_[status]; 307 const std::vector<std::string>& tests = tests_by_status_[status];
299 if (tests.empty()) 308 if (tests.empty())
300 return; 309 return;
301 fprintf(stdout, 310 fprintf(stdout,
302 "%" PRIuS " test%s %s:\n", 311 "%" PRIuS " test%s %s:\n",
303 tests.size(), 312 tests.size(),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if (!should_run) 415 if (!should_run)
407 continue; 416 continue;
408 417
409 printer->OnTestStarted(test_name); 418 printer->OnTestStarted(test_name);
410 MessageLoop::current()->PostTask( 419 MessageLoop::current()->PostTask(
411 FROM_HERE, 420 FROM_HERE,
412 Bind(&TestLauncherDelegate::RunTest, 421 Bind(&TestLauncherDelegate::RunTest,
413 Unretained(launcher_delegate), 422 Unretained(launcher_delegate),
414 test_case, 423 test_case,
415 test_info, 424 test_info,
416 Bind(&ResultsPrinter::AddTestResult, Unretained(printer)))); 425 Bind(&ResultsPrinter::AddTestResult, printer->GetWeakPtr())));
Paweł Hajdan Jr. 2013/09/04 21:41:39 This shouldn't be a weak pointer and should crash
sadrul 2013/09/04 21:46:36 Reverted this change.
417 } 426 }
418 } 427 }
419 428
420 MessageLoop::current()->PostTask( 429 MessageLoop::current()->PostTask(
421 FROM_HERE, 430 FROM_HERE,
422 Bind(&TestLauncherDelegate::RunRemainingTests, 431 Bind(&TestLauncherDelegate::RunRemainingTests,
423 Unretained(launcher_delegate))); 432 Unretained(launcher_delegate)));
424 433
425 MessageLoop::current()->PostTask( 434 MessageLoop::current()->PostTask(
426 FROM_HERE, 435 FROM_HERE,
427 Bind(&ResultsPrinter::OnAllTestsStarted, Unretained(printer))); 436 Bind(&ResultsPrinter::OnAllTestsStarted,
437 printer->GetWeakPtr()));
Paweł Hajdan Jr. 2013/09/04 21:41:39 nit: Does this fit on the previous line?
sadrul 2013/09/04 21:46:36 Yep. Done.
428 } 438 }
429 439
430 void RunTestIteration(TestLauncherDelegate* launcher_delegate, 440 void RunTestIteration(TestLauncherDelegate* launcher_delegate,
431 int32 total_shards, 441 int32 total_shards,
432 int32 shard_index, 442 int32 shard_index,
433 int cycles, 443 int cycles,
434 int* exit_code, 444 int* exit_code,
435 bool run_tests_success) { 445 bool run_tests_success) {
436 if (!run_tests_success) { 446 if (!run_tests_success) {
437 *exit_code = 1; 447 *exit_code = 1;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 cycles, 596 cycles,
587 &exit_code, 597 &exit_code,
588 true)); 598 true));
589 599
590 MessageLoop::current()->Run(); 600 MessageLoop::current()->Run();
591 601
592 return exit_code; 602 return exit_code;
593 } 603 }
594 604
595 } // namespace base 605 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698