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

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

Issue 23506031: Fix a test launcher hang when no tests are run. (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 | « base/test/parallel_test_launcher.cc ('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 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // detailed failure messages either. 114 // detailed failure messages either.
115 class ResultsPrinter { 115 class ResultsPrinter {
116 public: 116 public:
117 ResultsPrinter(const CommandLine& command_line, 117 ResultsPrinter(const CommandLine& command_line,
118 const RunTestsCallback& callback); 118 const RunTestsCallback& callback);
119 ~ResultsPrinter(); 119 ~ResultsPrinter();
120 120
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
125 // to be started.
126 void OnAllTestsStarted();
127
124 // Adds |result| to the stored test results. 128 // Adds |result| to the stored test results.
125 void AddTestResult(const TestResult& result); 129 void AddTestResult(const TestResult& result);
126 130
127 private: 131 private:
128 // Prints a list of tests that finished with |status|. 132 // Prints a list of tests that finished with |status|.
129 void PrintTestsByStatus(TestResult::Status status, 133 void PrintTestsByStatus(TestResult::Status status,
130 const std::string& description); 134 const std::string& description);
131 135
132 // Test results grouped by test case name. 136 // Test results grouped by test case name.
133 typedef std::map<std::string, std::vector<TestResult> > ResultsMap; 137 typedef std::map<std::string, std::vector<TestResult> > ResultsMap;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 225 }
222 fprintf(out_, "</testsuites>\n"); 226 fprintf(out_, "</testsuites>\n");
223 fclose(out_); 227 fclose(out_);
224 } 228 }
225 229
226 void ResultsPrinter::OnTestStarted(const std::string& name) { 230 void ResultsPrinter::OnTestStarted(const std::string& name) {
227 DCHECK(thread_checker_.CalledOnValidThread()); 231 DCHECK(thread_checker_.CalledOnValidThread());
228 ++test_started_count_; 232 ++test_started_count_;
229 } 233 }
230 234
235 void ResultsPrinter::OnAllTestsStarted() {
236 if (test_started_count_ == 0) {
237 fprintf(stdout, "0 tests run\n");
Ken Russell (switch to Gerrit) 2013/09/04 18:00:30 Did you mean to leave this printf in here?
Paweł Hajdan Jr. 2013/09/04 18:02:30 Yes - it corresponds to "x tests run" below and ex
238 fflush(stdout);
239
240 // No tests have actually been started, so fire the callback
241 // to avoid a hang.
242 callback_.Run(true);
243 delete this;
244 }
245 }
246
231 void ResultsPrinter::AddTestResult(const TestResult& result) { 247 void ResultsPrinter::AddTestResult(const TestResult& result) {
232 DCHECK(thread_checker_.CalledOnValidThread()); 248 DCHECK(thread_checker_.CalledOnValidThread());
233 249
234 ++test_run_count_; 250 ++test_run_count_;
235 results_[result.test_case_name].push_back(result); 251 results_[result.test_case_name].push_back(result);
236 252
237 // TODO(phajdan.jr): Align counter (padding). 253 // TODO(phajdan.jr): Align counter (padding).
238 std::string status_line(StringPrintf("[%" PRIuS "/%" PRIuS "] %s ", 254 std::string status_line(StringPrintf("[%" PRIuS "/%" PRIuS "] %s ",
239 test_run_count_, 255 test_run_count_,
240 test_started_count_, 256 test_started_count_,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 test_case, 414 test_case,
399 test_info, 415 test_info,
400 Bind(&ResultsPrinter::AddTestResult, Unretained(printer)))); 416 Bind(&ResultsPrinter::AddTestResult, Unretained(printer))));
401 } 417 }
402 } 418 }
403 419
404 MessageLoop::current()->PostTask( 420 MessageLoop::current()->PostTask(
405 FROM_HERE, 421 FROM_HERE,
406 Bind(&TestLauncherDelegate::RunRemainingTests, 422 Bind(&TestLauncherDelegate::RunRemainingTests,
407 Unretained(launcher_delegate))); 423 Unretained(launcher_delegate)));
424
425 MessageLoop::current()->PostTask(
426 FROM_HERE,
427 Bind(&ResultsPrinter::OnAllTestsStarted, Unretained(printer)));
408 } 428 }
409 429
410 void RunTestIteration(TestLauncherDelegate* launcher_delegate, 430 void RunTestIteration(TestLauncherDelegate* launcher_delegate,
411 int32 total_shards, 431 int32 total_shards,
412 int32 shard_index, 432 int32 shard_index,
413 int cycles, 433 int cycles,
414 int* exit_code, 434 int* exit_code,
415 bool run_tests_success) { 435 bool run_tests_success) {
416 if (!run_tests_success) { 436 if (!run_tests_success) {
417 *exit_code = 1; 437 *exit_code = 1;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 cycles, 586 cycles,
567 &exit_code, 587 &exit_code,
568 true)); 588 true));
569 589
570 MessageLoop::current()->Run(); 590 MessageLoop::current()->Run();
571 591
572 return exit_code; 592 return exit_code;
573 } 593 }
574 594
575 } // namespace base 595 } // namespace base
OLDNEW
« no previous file with comments | « base/test/parallel_test_launcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698