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

Unified Diff: base/test/launcher/test_launcher.cc

Issue 2342403002: Use base::Thread instead of single-threaded SequencedWorkerPool in TestLauncher. (Closed)
Patch Set: cleaner DCHECKs Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/test/launcher/test_launcher.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0d2151fd54a8f248eb851d53a2933f291a84d44e 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,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 ] ") +
« no previous file with comments | « base/test/launcher/test_launcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698