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

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

Issue 469533002: Change gtest launcher to run in parallel and retry failures by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: enable parallel jobs by default as well Created 6 years, 4 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 | base/test/test_switches.cc » ('j') | 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/launcher/test_launcher.h" 5 #include "base/test/launcher/test_launcher.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #endif 9 #endif
10 10
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 bool UnsetEnvironmentVariableIfExists(const std::string& name) { 194 bool UnsetEnvironmentVariableIfExists(const std::string& name) {
195 scoped_ptr<Environment> env(Environment::Create()); 195 scoped_ptr<Environment> env(Environment::Create());
196 std::string str_val; 196 std::string str_val;
197 197
198 if (!env->GetVar(name.c_str(), &str_val)) 198 if (!env->GetVar(name.c_str(), &str_val))
199 return true; 199 return true;
200 200
201 return env->UnSetVar(name.c_str()); 201 return env->UnSetVar(name.c_str());
202 } 202 }
203 203
204 // Returns true if bot mode has been requested, i.e. defaults optimized
205 // for continuous integration bots. This way developers don't have to remember
206 // special command-line flags.
207 bool BotModeEnabled() {
208 scoped_ptr<Environment> env(Environment::Create());
209 return CommandLine::ForCurrentProcess()->HasSwitch(
210 switches::kTestLauncherBotMode) ||
211 env->HasVar("CHROMIUM_TEST_LAUNCHER_BOT_MODE");
212 }
213
214 void RunCallback( 204 void RunCallback(
215 const TestLauncher::LaunchChildGTestProcessCallback& callback, 205 const TestLauncher::LaunchChildGTestProcessCallback& callback,
216 int exit_code, 206 int exit_code,
217 const TimeDelta& elapsed_time, 207 const TimeDelta& elapsed_time,
218 bool was_timeout, 208 bool was_timeout,
219 const std::string& output) { 209 const std::string& output) {
220 callback.Run(exit_code, elapsed_time, was_timeout, output); 210 callback.Run(exit_code, elapsed_time, was_timeout, output);
221 } 211 }
222 212
223 void DoLaunchChildTestProcess( 213 void DoLaunchChildTestProcess(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 test_success_count_(0), 319 test_success_count_(0),
330 test_broken_count_(0), 320 test_broken_count_(0),
331 retry_count_(0), 321 retry_count_(0),
332 retry_limit_(0), 322 retry_limit_(0),
333 run_result_(true), 323 run_result_(true),
334 watchdog_timer_(FROM_HERE, 324 watchdog_timer_(FROM_HERE,
335 TimeDelta::FromSeconds(kOutputTimeoutSeconds), 325 TimeDelta::FromSeconds(kOutputTimeoutSeconds),
336 this, 326 this,
337 &TestLauncher::OnOutputTimeout), 327 &TestLauncher::OnOutputTimeout),
338 parallel_jobs_(parallel_jobs) { 328 parallel_jobs_(parallel_jobs) {
339 if (BotModeEnabled()) {
340 fprintf(stdout,
341 "Enabling defaults optimized for continuous integration bots.\n");
342 fflush(stdout);
343
344 // Enable test retries by default for bots. This can be still overridden
345 // from command line using --test-launcher-retry-limit flag.
346 retry_limit_ = 3;
347 } else {
348 // Default to serial test execution if not running on a bot. This makes it
349 // possible to disable stdio redirection and can still be overridden with
350 // --test-launcher-jobs flag.
351 parallel_jobs_ = 1;
352 }
353 } 329 }
354 330
355 TestLauncher::~TestLauncher() { 331 TestLauncher::~TestLauncher() {
356 if (worker_pool_owner_) 332 if (worker_pool_owner_)
357 worker_pool_owner_->pool()->Shutdown(); 333 worker_pool_owner_->pool()->Shutdown();
358 } 334 }
359 335
360 bool TestLauncher::Run() { 336 bool TestLauncher::Run() {
361 if (!Init()) 337 if (!Init())
362 return false; 338 return false;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 base::TimeDelta timeout, 387 base::TimeDelta timeout,
412 int flags, 388 int flags,
413 const LaunchChildGTestProcessCallback& callback) { 389 const LaunchChildGTestProcessCallback& callback) {
414 DCHECK(thread_checker_.CalledOnValidThread()); 390 DCHECK(thread_checker_.CalledOnValidThread());
415 391
416 // Record the exact command line used to launch the child. 392 // Record the exact command line used to launch the child.
417 CommandLine new_command_line( 393 CommandLine new_command_line(
418 PrepareCommandLineForGTest(command_line, wrapper)); 394 PrepareCommandLineForGTest(command_line, wrapper));
419 395
420 // When running in parallel mode we need to redirect stdio to avoid mixed-up 396 // When running in parallel mode we need to redirect stdio to avoid mixed-up
421 // output. We also always redirect on the bots to get the test output into 397 // output. We also always redirect on the bots to get the test output into
Paweł Hajdan Jr. 2014/08/13 09:36:37 Please see this comment. It's important behavior:
Dirk Pranke 2014/08/13 16:56:04 Ah, okay. I will restore this and BotModeEnabled()
422 // JSON summary. 398 // JSON summary.
423 bool redirect_stdio = (parallel_jobs_ > 1) || BotModeEnabled(); 399 bool redirect_stdio = (parallel_jobs_ > 1);
424 400
425 worker_pool_owner_->pool()->PostWorkerTask( 401 worker_pool_owner_->pool()->PostWorkerTask(
426 FROM_HERE, 402 FROM_HERE,
427 Bind(&DoLaunchChildTestProcess, 403 Bind(&DoLaunchChildTestProcess,
428 new_command_line, 404 new_command_line,
429 timeout, 405 timeout,
430 flags, 406 flags,
431 redirect_stdio, 407 redirect_stdio,
432 MessageLoopProxy::current(), 408 MessageLoopProxy::current(),
433 Bind(&TestLauncher::OnLaunchTestProcessFinished, 409 Bind(&TestLauncher::OnLaunchTestProcessFinished,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 switches::kTestLauncherRetryLimit)) { 619 switches::kTestLauncherRetryLimit)) {
644 int retry_limit = -1; 620 int retry_limit = -1;
645 if (!StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 621 if (!StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
646 switches::kTestLauncherRetryLimit), &retry_limit) || 622 switches::kTestLauncherRetryLimit), &retry_limit) ||
647 retry_limit < 0) { 623 retry_limit < 0) {
648 LOG(ERROR) << "Invalid value for " << switches::kTestLauncherRetryLimit; 624 LOG(ERROR) << "Invalid value for " << switches::kTestLauncherRetryLimit;
649 return false; 625 return false;
650 } 626 }
651 627
652 retry_limit_ = retry_limit; 628 retry_limit_ = retry_limit;
629 } else if (!CommandLine::ForCurrentProcess()->HasSwitch(kGTestFilterFlag)) {
630 // Retry failures 3 times by default if we are running all of the tests.
631 retry_limit_ = 3;
653 } 632 }
654 633
655 if (CommandLine::ForCurrentProcess()->HasSwitch( 634 if (CommandLine::ForCurrentProcess()->HasSwitch(
656 switches::kTestLauncherJobs)) { 635 switches::kTestLauncherJobs)) {
657 int jobs = -1; 636 int jobs = -1;
658 if (!StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 637 if (!StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
659 switches::kTestLauncherJobs), &jobs) || 638 switches::kTestLauncherJobs), &jobs) ||
660 jobs < 0) { 639 jobs < 0) {
661 LOG(ERROR) << "Invalid value for " << switches::kTestLauncherJobs; 640 LOG(ERROR) << "Invalid value for " << switches::kTestLauncherJobs;
662 return false; 641 return false;
663 } 642 }
664 643
665 parallel_jobs_ = jobs; 644 parallel_jobs_ = jobs;
645 } else if (CommandLine::ForCurrentProcess()->HasSwitch(kGTestFilterFlag)) {
646 // Do not run jobs in parallel by default if we are running a subset of
647 // the tests.
648 parallel_jobs_ = 1;
666 } 649 }
650
667 fprintf(stdout, "Using %" PRIuS " parallel jobs.\n", parallel_jobs_); 651 fprintf(stdout, "Using %" PRIuS " parallel jobs.\n", parallel_jobs_);
668 fflush(stdout); 652 fflush(stdout);
669 worker_pool_owner_.reset( 653 worker_pool_owner_.reset(
670 new SequencedWorkerPoolOwner(parallel_jobs_, "test_launcher")); 654 new SequencedWorkerPoolOwner(parallel_jobs_, "test_launcher"));
671 655
672 if (command_line->HasSwitch(switches::kTestLauncherFilterFile) && 656 if (command_line->HasSwitch(switches::kTestLauncherFilterFile) &&
673 command_line->HasSwitch(kGTestFilterFlag)) { 657 command_line->HasSwitch(kGTestFilterFlag)) {
674 LOG(ERROR) << "Only one of --test-launcher-filter-file and --gtest_filter " 658 LOG(ERROR) << "Only one of --test-launcher-filter-file and --gtest_filter "
675 << "at a time is allowed."; 659 << "at a time is allowed.";
676 return false; 660 return false;
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 1081
1098 g_live_processes.Get().erase(process_handle); 1082 g_live_processes.Get().erase(process_handle);
1099 } 1083 }
1100 1084
1101 base::CloseProcessHandle(process_handle); 1085 base::CloseProcessHandle(process_handle);
1102 1086
1103 return exit_code; 1087 return exit_code;
1104 } 1088 }
1105 1089
1106 } // namespace base 1090 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/test/test_switches.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698