| OLD | NEW |
| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 bool BotModeEnabled() { | 204 bool BotModeEnabled() { |
| 205 scoped_ptr<Environment> env(Environment::Create()); | 205 scoped_ptr<Environment> env(Environment::Create()); |
| 206 return CommandLine::ForCurrentProcess()->HasSwitch( | 206 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 207 switches::kTestLauncherBotMode) || | 207 switches::kTestLauncherBotMode) || |
| 208 env->HasVar("CHROMIUM_TEST_LAUNCHER_BOT_MODE"); | 208 env->HasVar("CHROMIUM_TEST_LAUNCHER_BOT_MODE"); |
| 209 } | 209 } |
| 210 | 210 |
| 211 // Returns command line command line after gtest-specific processing | 211 // Returns command line command line after gtest-specific processing |
| 212 // and applying |wrapper|. | 212 // and applying |wrapper|. |
| 213 CommandLine PrepareCommandLineForGTest(const CommandLine& command_line, | 213 CommandLine PrepareCommandLineForGTest(const CommandLine& command_line, |
| 214 const std::string& wrapper) { | 214 const std::string& wrapper, |
| 215 bool use_gtest_output) { |
| 215 CommandLine new_command_line(command_line.GetProgram()); | 216 CommandLine new_command_line(command_line.GetProgram()); |
| 216 CommandLine::SwitchMap switches = command_line.GetSwitches(); | 217 CommandLine::SwitchMap switches = command_line.GetSwitches(); |
| 217 | 218 |
| 218 // Strip out gtest_repeat flag - this is handled by the launcher process. | 219 // Strip out gtest_repeat flag - this is handled by the launcher process. |
| 219 switches.erase(kGTestRepeatFlag); | 220 switches.erase(kGTestRepeatFlag); |
| 220 | 221 |
| 221 // Don't try to write the final XML report in child processes. | 222 // Don't try to write the final XML report in child processes. |
| 222 switches.erase(kGTestOutputFlag); | 223 if (!use_gtest_output) |
| 224 switches.erase(kGTestOutputFlag); |
| 223 | 225 |
| 224 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); | 226 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); |
| 225 iter != switches.end(); ++iter) { | 227 iter != switches.end(); ++iter) { |
| 226 new_command_line.AppendSwitchNative((*iter).first, (*iter).second); | 228 new_command_line.AppendSwitchNative((*iter).first, (*iter).second); |
| 227 } | 229 } |
| 228 | 230 |
| 229 // Prepend wrapper after last CommandLine quasi-copy operation. CommandLine | 231 // Prepend wrapper after last CommandLine quasi-copy operation. CommandLine |
| 230 // does not really support removing switches well, and trying to do that | 232 // does not really support removing switches well, and trying to do that |
| 231 // on a CommandLine with a wrapper is known to break. | 233 // on a CommandLine with a wrapper is known to break. |
| 232 // TODO(phajdan.jr): Give it a try to support CommandLine removing switches. | 234 // TODO(phajdan.jr): Give it a try to support CommandLine removing switches. |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 const char kGTestRepeatFlag[] = "gtest_repeat"; | 441 const char kGTestRepeatFlag[] = "gtest_repeat"; |
| 440 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests"; | 442 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests"; |
| 441 const char kGTestOutputFlag[] = "gtest_output"; | 443 const char kGTestOutputFlag[] = "gtest_output"; |
| 442 | 444 |
| 443 TestLauncherDelegate::~TestLauncherDelegate() { | 445 TestLauncherDelegate::~TestLauncherDelegate() { |
| 444 } | 446 } |
| 445 | 447 |
| 446 TestLauncher::TestLauncher(TestLauncherDelegate* launcher_delegate, | 448 TestLauncher::TestLauncher(TestLauncherDelegate* launcher_delegate, |
| 447 size_t parallel_jobs) | 449 size_t parallel_jobs) |
| 448 : launcher_delegate_(launcher_delegate), | 450 : launcher_delegate_(launcher_delegate), |
| 451 use_child_gtest_output_(false), |
| 449 total_shards_(1), | 452 total_shards_(1), |
| 450 shard_index_(0), | 453 shard_index_(0), |
| 451 cycles_(1), | 454 cycles_(1), |
| 452 test_started_count_(0), | 455 test_started_count_(0), |
| 453 test_finished_count_(0), | 456 test_finished_count_(0), |
| 454 test_success_count_(0), | 457 test_success_count_(0), |
| 455 test_broken_count_(0), | 458 test_broken_count_(0), |
| 456 retry_count_(0), | 459 retry_count_(0), |
| 457 retry_limit_(0), | 460 retry_limit_(0), |
| 458 run_result_(true), | 461 run_result_(true), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 520 |
| 518 void TestLauncher::LaunchChildGTestProcess( | 521 void TestLauncher::LaunchChildGTestProcess( |
| 519 const CommandLine& command_line, | 522 const CommandLine& command_line, |
| 520 const std::string& wrapper, | 523 const std::string& wrapper, |
| 521 TimeDelta timeout, | 524 TimeDelta timeout, |
| 522 int flags, | 525 int flags, |
| 523 const LaunchChildGTestProcessCallback& callback) { | 526 const LaunchChildGTestProcessCallback& callback) { |
| 524 DCHECK(thread_checker_.CalledOnValidThread()); | 527 DCHECK(thread_checker_.CalledOnValidThread()); |
| 525 | 528 |
| 526 // Record the exact command line used to launch the child. | 529 // Record the exact command line used to launch the child. |
| 527 CommandLine new_command_line( | 530 CommandLine new_command_line(PrepareCommandLineForGTest( |
| 528 PrepareCommandLineForGTest(command_line, wrapper)); | 531 command_line, wrapper, use_child_gtest_output_)); |
| 529 | 532 |
| 530 // When running in parallel mode we need to redirect stdio to avoid mixed-up | 533 // When running in parallel mode we need to redirect stdio to avoid mixed-up |
| 531 // output. We also always redirect on the bots to get the test output into | 534 // output. We also always redirect on the bots to get the test output into |
| 532 // JSON summary. | 535 // JSON summary. |
| 533 bool redirect_stdio = (parallel_jobs_ > 1) || BotModeEnabled(); | 536 bool redirect_stdio = (parallel_jobs_ > 1) || BotModeEnabled(); |
| 534 | 537 |
| 535 worker_pool_owner_->pool()->PostWorkerTask( | 538 worker_pool_owner_->pool()->PostWorkerTask( |
| 536 FROM_HERE, Bind(&DoLaunchChildTestProcess, new_command_line, timeout, | 539 FROM_HERE, Bind(&DoLaunchChildTestProcess, new_command_line, timeout, |
| 537 flags, redirect_stdio, ThreadTaskRunnerHandle::Get(), | 540 flags, redirect_stdio, ThreadTaskRunnerHandle::Get(), |
| 538 Bind(&TestLauncher::OnLaunchTestProcessFinished, | 541 Bind(&TestLauncher::OnLaunchTestProcessFinished, |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 } | 1073 } |
| 1071 | 1074 |
| 1072 std::string snippet(full_output.substr(run_pos)); | 1075 std::string snippet(full_output.substr(run_pos)); |
| 1073 if (end_pos != std::string::npos) | 1076 if (end_pos != std::string::npos) |
| 1074 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1077 snippet = full_output.substr(run_pos, end_pos - run_pos); |
| 1075 | 1078 |
| 1076 return snippet; | 1079 return snippet; |
| 1077 } | 1080 } |
| 1078 | 1081 |
| 1079 } // namespace base | 1082 } // namespace base |
| OLD | NEW |