Chromium Code Reviews| Index: base/test/launcher/test_launcher.cc |
| diff --git a/base/test/launcher/test_launcher.cc b/base/test/launcher/test_launcher.cc |
| index a51d97e31207acc6c5e85e74eaacc8400e94170d..8f317059af4aab80e7d3bb393a5f2dfa139a3bde 100644 |
| --- a/base/test/launcher/test_launcher.cc |
| +++ b/base/test/launcher/test_launcher.cc |
| @@ -19,6 +19,7 @@ |
| #include "base/location.h" |
| #include "base/logging.h" |
| #include "base/macros.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/process/kill.h" |
| #include "base/process/launch.h" |
| @@ -37,6 +38,7 @@ |
| #include "base/test/sequenced_worker_pool_owner.h" |
| #include "base/test/test_switches.h" |
| #include "base/test/test_timeouts.h" |
| +#include "base/threading/thread.h" |
| #include "base/threading/thread_checker.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "base/time/time.h" |
| @@ -573,7 +575,7 @@ void TestLauncher::LaunchChildGTestProcess( |
| // JSON summary. |
| bool redirect_stdio = (parallel_jobs_ > 1) || BotModeEnabled(); |
| - worker_pool_owner_->pool()->PostWorkerTask( |
| + GetTaskRunner()->PostTask( |
| FROM_HERE, |
| Bind(&DoLaunchChildTestProcess, new_command_line, timeout, options, |
| redirect_stdio, RetainedRef(ThreadTaskRunnerHandle::Get()), |
| @@ -801,10 +803,10 @@ bool TestLauncher::Init() { |
| force_run_broken_tests_ = true; |
| if (command_line->HasSwitch(switches::kTestLauncherJobs)) { |
| - int jobs = -1; |
| - if (!StringToInt(command_line->GetSwitchValueASCII( |
| + size_t jobs = 0U; |
| + if (!StringToSizeT(command_line->GetSwitchValueASCII( |
| switches::kTestLauncherJobs), &jobs) || |
| - jobs < 0) { |
| + !jobs) { |
| LOG(ERROR) << "Invalid value for " << switches::kTestLauncherJobs; |
| return false; |
| } |
| @@ -813,13 +815,18 @@ bool TestLauncher::Init() { |
| } else if (command_line->HasSwitch(kGTestFilterFlag) && !BotModeEnabled()) { |
| // Do not run jobs in parallel by default if we are running a subset of |
| // the tests and if bot mode is off. |
| - parallel_jobs_ = 1; |
| + parallel_jobs_ = 1U; |
| } |
| fprintf(stdout, "Using %" PRIuS " parallel jobs.\n", parallel_jobs_); |
| fflush(stdout); |
| - worker_pool_owner_.reset( |
| - new SequencedWorkerPoolOwner(parallel_jobs_, "test_launcher")); |
| + if (parallel_jobs_ > 1U) { |
| + worker_pool_owner_ = MakeUnique<SequencedWorkerPoolOwner>( |
| + parallel_jobs_, "test_launcher"); |
| + } else { |
| + worker_thread_ = MakeUnique<Thread>("test_launcher"); |
| + worker_thread_->Start(); |
| + } |
| if (command_line->HasSwitch(switches::kTestLauncherFilterFile) && |
| command_line->HasSwitch(kGTestFilterFlag)) { |
| @@ -1113,6 +1120,16 @@ void TestLauncher::OnOutputTimeout() { |
| watchdog_timer_.Reset(); |
| } |
| +scoped_refptr<TaskRunner> TestLauncher::GetTaskRunner() { |
| + if (worker_pool_owner_) { |
| + DCHECK(!worker_thread_); |
|
danakj
2016/09/16 17:52:48
nit: how about instead at the top of this method:
gab
2016/09/16 18:09:29
Nice trick :-), done.
|
| + return worker_pool_owner_->pool(); |
| + } |
| + DCHECK(worker_thread_); |
| + DCHECK(worker_thread_->IsRunning()); |
| + return worker_thread_->task_runner(); |
| +} |
| + |
| std::string GetTestOutputSnippet(const TestResult& result, |
| const std::string& full_output) { |
| size_t run_pos = full_output.find(std::string("[ RUN ] ") + |