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/unit_test_launcher.h" | 5 #include "base/test/launcher/unit_test_launcher.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 151 |
152 DISALLOW_COPY_AND_ASSIGN(DefaultUnitTestPlatformDelegate); | 152 DISALLOW_COPY_AND_ASSIGN(DefaultUnitTestPlatformDelegate); |
153 }; | 153 }; |
154 | 154 |
155 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { | 155 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { |
156 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) | 156 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) |
157 return true; | 157 return true; |
158 | 158 |
159 std::string switch_value = | 159 std::string switch_value = |
160 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); | 160 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); |
161 if (!StringToInt(switch_value, result) || *result < 1) { | 161 if (!StringToInt(switch_value, result) || *result < 0) { |
162 LOG(ERROR) << "Invalid value for " << switch_name << ": " << switch_value; | 162 LOG(ERROR) << "Invalid value for " << switch_name << ": " << switch_value; |
163 return false; | 163 return false; |
164 } | 164 } |
165 | 165 |
166 return true; | 166 return true; |
167 } | 167 } |
168 | 168 |
169 int LaunchUnitTestsInternal(const RunTestSuiteCallback& run_test_suite, | 169 int LaunchUnitTestsInternal(const RunTestSuiteCallback& run_test_suite, |
170 int default_jobs, | 170 int default_jobs, |
| 171 int default_batch_limit, |
171 bool use_job_objects, | 172 bool use_job_objects, |
172 const Closure& gtest_init) { | 173 const Closure& gtest_init) { |
173 #if defined(OS_ANDROID) | 174 #if defined(OS_ANDROID) |
174 // We can't easily fork on Android, just run the test suite directly. | 175 // We can't easily fork on Android, just run the test suite directly. |
175 return run_test_suite.Run(); | 176 return run_test_suite.Run(); |
176 #else | 177 #else |
177 bool force_single_process = false; | 178 bool force_single_process = false; |
178 if (CommandLine::ForCurrentProcess()->HasSwitch( | 179 if (CommandLine::ForCurrentProcess()->HasSwitch( |
179 switches::kTestLauncherDebugLauncher)) { | 180 switches::kTestLauncherDebugLauncher)) { |
180 fprintf(stdout, "Forcing test launcher debugging mode.\n"); | 181 fprintf(stdout, "Forcing test launcher debugging mode.\n"); |
(...skipping 22 matching lines...) Expand all Loading... |
203 if (CommandLine::ForCurrentProcess()->HasSwitch(kHelpFlag)) { | 204 if (CommandLine::ForCurrentProcess()->HasSwitch(kHelpFlag)) { |
204 PrintUsage(); | 205 PrintUsage(); |
205 return 0; | 206 return 0; |
206 } | 207 } |
207 | 208 |
208 base::TimeTicks start_time(base::TimeTicks::Now()); | 209 base::TimeTicks start_time(base::TimeTicks::Now()); |
209 | 210 |
210 gtest_init.Run(); | 211 gtest_init.Run(); |
211 TestTimeouts::Initialize(); | 212 TestTimeouts::Initialize(); |
212 | 213 |
213 int batch_limit = kDefaultTestBatchLimit; | 214 int batch_limit = default_batch_limit; |
214 if (!GetSwitchValueAsInt(switches::kTestLauncherBatchLimit, &batch_limit)) | 215 if (!GetSwitchValueAsInt(switches::kTestLauncherBatchLimit, &batch_limit)) |
215 return 1; | 216 return 1; |
216 | 217 |
217 fprintf(stdout, | 218 fprintf(stdout, |
218 "IMPORTANT DEBUGGING NOTE: batches of tests are run inside their\n" | 219 "IMPORTANT DEBUGGING NOTE: batches of tests are run inside their\n" |
219 "own process. For debugging a test inside a debugger, use the\n" | 220 "own process. For debugging a test inside a debugger, use the\n" |
220 "--gtest_filter=<your_test_name> flag along with\n" | 221 "--gtest_filter=<your_test_name> flag along with\n" |
221 "--single-process-tests.\n"); | 222 "--single-process-tests.\n"); |
222 fflush(stdout); | 223 fflush(stdout); |
223 | 224 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 callback_state.platform_delegate, test_names, | 429 callback_state.platform_delegate, test_names, |
429 callback_state.launch_flags)); | 430 callback_state.launch_flags)); |
430 } | 431 } |
431 | 432 |
432 } // namespace | 433 } // namespace |
433 | 434 |
434 int LaunchUnitTests(int argc, | 435 int LaunchUnitTests(int argc, |
435 char** argv, | 436 char** argv, |
436 const RunTestSuiteCallback& run_test_suite) { | 437 const RunTestSuiteCallback& run_test_suite) { |
437 CommandLine::Init(argc, argv); | 438 CommandLine::Init(argc, argv); |
438 return LaunchUnitTestsInternal(run_test_suite, SysInfo::NumberOfProcessors(), | 439 return LaunchUnitTestsInternal( |
439 true, Bind(&InitGoogleTestChar, &argc, argv)); | 440 run_test_suite, |
| 441 SysInfo::NumberOfProcessors(), |
| 442 kDefaultTestBatchLimit, |
| 443 true, |
| 444 Bind(&InitGoogleTestChar, &argc, argv)); |
440 } | 445 } |
441 | 446 |
442 int LaunchUnitTestsSerially(int argc, | 447 int LaunchUnitTestsSerially(int argc, |
443 char** argv, | 448 char** argv, |
444 const RunTestSuiteCallback& run_test_suite) { | 449 const RunTestSuiteCallback& run_test_suite) { |
445 CommandLine::Init(argc, argv); | 450 CommandLine::Init(argc, argv); |
446 return LaunchUnitTestsInternal(run_test_suite, 1, true, | 451 return LaunchUnitTestsInternal( |
447 Bind(&InitGoogleTestChar, &argc, argv)); | 452 run_test_suite, |
| 453 1, |
| 454 kDefaultTestBatchLimit, |
| 455 true, |
| 456 Bind(&InitGoogleTestChar, &argc, argv)); |
| 457 } |
| 458 |
| 459 int LaunchUnitTestsWithOptions( |
| 460 int argc, |
| 461 char** argv, |
| 462 int default_jobs, |
| 463 int default_batch_limit, |
| 464 bool use_job_objects, |
| 465 const RunTestSuiteCallback& run_test_suite) { |
| 466 CommandLine::Init(argc, argv); |
| 467 return LaunchUnitTestsInternal( |
| 468 run_test_suite, |
| 469 default_jobs, |
| 470 default_batch_limit, |
| 471 use_job_objects, |
| 472 Bind(&InitGoogleTestChar, &argc, argv)); |
448 } | 473 } |
449 | 474 |
450 #if defined(OS_WIN) | 475 #if defined(OS_WIN) |
451 int LaunchUnitTests(int argc, | 476 int LaunchUnitTests(int argc, |
452 wchar_t** argv, | 477 wchar_t** argv, |
453 bool use_job_objects, | 478 bool use_job_objects, |
454 const RunTestSuiteCallback& run_test_suite) { | 479 const RunTestSuiteCallback& run_test_suite) { |
455 // Windows CommandLine::Init ignores argv anyway. | 480 // Windows CommandLine::Init ignores argv anyway. |
456 CommandLine::Init(argc, NULL); | 481 CommandLine::Init(argc, NULL); |
457 return LaunchUnitTestsInternal(run_test_suite, SysInfo::NumberOfProcessors(), | 482 return LaunchUnitTestsInternal( |
458 use_job_objects, | 483 run_test_suite, |
459 Bind(&InitGoogleTestWChar, &argc, argv)); | 484 SysInfo::NumberOfProcessors(), |
| 485 kDefaultTestBatchLimit, |
| 486 use_job_objects, |
| 487 Bind(&InitGoogleTestWChar, &argc, argv)); |
460 } | 488 } |
461 #endif // defined(OS_WIN) | 489 #endif // defined(OS_WIN) |
462 | 490 |
463 void RunUnitTestsSerially( | 491 void RunUnitTestsSerially( |
464 TestLauncher* test_launcher, | 492 TestLauncher* test_launcher, |
465 UnitTestPlatformDelegate* platform_delegate, | 493 UnitTestPlatformDelegate* platform_delegate, |
466 const std::vector<std::string>& test_names, | 494 const std::vector<std::string>& test_names, |
467 int launch_flags) { | 495 int launch_flags) { |
468 if (test_names.empty()) | 496 if (test_names.empty()) |
469 return; | 497 return; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 TestLauncher* test_launcher, | 620 TestLauncher* test_launcher, |
593 const std::vector<std::string>& test_names) { | 621 const std::vector<std::string>& test_names) { |
594 ThreadTaskRunnerHandle::Get()->PostTask( | 622 ThreadTaskRunnerHandle::Get()->PostTask( |
595 FROM_HERE, | 623 FROM_HERE, |
596 Bind(&RunUnitTestsSerially, test_launcher, platform_delegate_, test_names, | 624 Bind(&RunUnitTestsSerially, test_launcher, platform_delegate_, test_names, |
597 use_job_objects_ ? TestLauncher::USE_JOB_OBJECTS : 0)); | 625 use_job_objects_ ? TestLauncher::USE_JOB_OBJECTS : 0)); |
598 return test_names.size(); | 626 return test_names.size(); |
599 } | 627 } |
600 | 628 |
601 } // namespace base | 629 } // namespace base |
OLD | NEW |