Commit 17d49a70 authored by gab's avatar gab Committed by Commit bot

Use base::Thread instead of single-threaded SequencedWorkerPool in TestLauncher.

BUG=646443

Review-Url: https://codereview.chromium.org/2342403002
Cr-Commit-Position: refs/heads/master@{#419247}
parent 5c1a81e6
......@@ -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,17 @@ void TestLauncher::OnOutputTimeout() {
watchdog_timer_.Reset();
}
scoped_refptr<TaskRunner> TestLauncher::GetTaskRunner() {
// One and only one of |worker_pool_owner_| or |worker_thread_| should be
// ready.
DCHECK_NE(!!worker_pool_owner_, !!worker_thread_);
if (worker_pool_owner_)
return worker_pool_owner_->pool();
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 ] ") +
......
......@@ -32,6 +32,7 @@ class CommandLine;
struct LaunchOptions;
class SequencedWorkerPoolOwner;
class TestLauncher;
class Thread;
// Constants for GTest command-line flags.
extern const char kGTestFilterFlag[];
......@@ -165,6 +166,10 @@ class TestLauncher {
// Called by the delay timer when no output was made for a while.
void OnOutputTimeout();
// Returns the TaskRunner to be used to launch child test processes. This
// TaskRunner will have TaskShutdownBehavior::BLOCK_SHUTDOWN semantics.
scoped_refptr<TaskRunner> GetTaskRunner();
// Make sure we don't accidentally call the wrong methods e.g. on the worker
// pool thread. With lots of callbacks used this is non-trivial.
// Should be the first member so that it's destroyed last: when destroying
......@@ -227,8 +232,10 @@ class TestLauncher {
// Number of jobs to run in parallel.
size_t parallel_jobs_;
// Worker pool used to launch processes in parallel.
// Worker pool used to launch processes in parallel (|worker_thread_| is used
// instead if |parallel_jobs == 1|).
std::unique_ptr<SequencedWorkerPoolOwner> worker_pool_owner_;
std::unique_ptr<Thread> worker_thread_;
DISALLOW_COPY_AND_ASSIGN(TestLauncher);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment