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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 DISALLOW_COPY_AND_ASSIGN(DefaultUnitTestPlatformDelegate); | 139 DISALLOW_COPY_AND_ASSIGN(DefaultUnitTestPlatformDelegate); |
140 }; | 140 }; |
141 | 141 |
142 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { | 142 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { |
143 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) | 143 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) |
144 return true; | 144 return true; |
145 | 145 |
146 std::string switch_value = | 146 std::string switch_value = |
147 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); | 147 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); |
148 if (!StringToInt(switch_value, result) || *result < 1) { | 148 if (!StringToInt(switch_value, result) || *result < 0) { |
149 LOG(ERROR) << "Invalid value for " << switch_name << ": " << switch_value; | 149 LOG(ERROR) << "Invalid value for " << switch_name << ": " << switch_value; |
150 return false; | 150 return false; |
151 } | 151 } |
152 | 152 |
153 return true; | 153 return true; |
154 } | 154 } |
155 | 155 |
156 int LaunchUnitTestsInternal(const RunTestSuiteCallback& run_test_suite, | 156 int LaunchUnitTestsInternal(const RunTestSuiteCallback& run_test_suite, |
157 int default_jobs, | 157 int default_jobs, |
| 158 int default_batch_limit, |
158 bool use_job_objects, | 159 bool use_job_objects, |
159 const Closure& gtest_init) { | 160 const Closure& gtest_init) { |
160 #if defined(OS_ANDROID) | 161 #if defined(OS_ANDROID) |
161 // We can't easily fork on Android, just run the test suite directly. | 162 // We can't easily fork on Android, just run the test suite directly. |
162 return run_test_suite.Run(); | 163 return run_test_suite.Run(); |
163 #else | 164 #else |
164 bool force_single_process = false; | 165 bool force_single_process = false; |
165 if (CommandLine::ForCurrentProcess()->HasSwitch( | 166 if (CommandLine::ForCurrentProcess()->HasSwitch( |
166 switches::kTestLauncherDebugLauncher)) { | 167 switches::kTestLauncherDebugLauncher)) { |
167 fprintf(stdout, "Forcing test launcher debugging mode.\n"); | 168 fprintf(stdout, "Forcing test launcher debugging mode.\n"); |
(...skipping 20 matching lines...) Expand all Loading... |
188 if (CommandLine::ForCurrentProcess()->HasSwitch(kHelpFlag)) { | 189 if (CommandLine::ForCurrentProcess()->HasSwitch(kHelpFlag)) { |
189 PrintUsage(); | 190 PrintUsage(); |
190 return 0; | 191 return 0; |
191 } | 192 } |
192 | 193 |
193 base::TimeTicks start_time(base::TimeTicks::Now()); | 194 base::TimeTicks start_time(base::TimeTicks::Now()); |
194 | 195 |
195 gtest_init.Run(); | 196 gtest_init.Run(); |
196 TestTimeouts::Initialize(); | 197 TestTimeouts::Initialize(); |
197 | 198 |
198 int batch_limit = kDefaultTestBatchLimit; | 199 int batch_limit = default_batch_limit; |
199 if (!GetSwitchValueAsInt(switches::kTestLauncherBatchLimit, &batch_limit)) | 200 if (!GetSwitchValueAsInt(switches::kTestLauncherBatchLimit, &batch_limit)) |
200 return 1; | 201 return 1; |
201 | 202 |
202 fprintf(stdout, | 203 fprintf(stdout, |
203 "IMPORTANT DEBUGGING NOTE: batches of tests are run inside their\n" | 204 "IMPORTANT DEBUGGING NOTE: batches of tests are run inside their\n" |
204 "own process. For debugging a test inside a debugger, use the\n" | 205 "own process. For debugging a test inside a debugger, use the\n" |
205 "--gtest_filter=<your_test_name> flag along with\n" | 206 "--gtest_filter=<your_test_name> flag along with\n" |
206 "--single-process-tests.\n"); | 207 "--single-process-tests.\n"); |
207 fflush(stdout); | 208 fflush(stdout); |
208 | 209 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 callback_state.platform_delegate, test_names, | 414 callback_state.platform_delegate, test_names, |
414 callback_state.launch_flags)); | 415 callback_state.launch_flags)); |
415 } | 416 } |
416 | 417 |
417 } // namespace | 418 } // namespace |
418 | 419 |
419 int LaunchUnitTests(int argc, | 420 int LaunchUnitTests(int argc, |
420 char** argv, | 421 char** argv, |
421 const RunTestSuiteCallback& run_test_suite) { | 422 const RunTestSuiteCallback& run_test_suite) { |
422 CommandLine::Init(argc, argv); | 423 CommandLine::Init(argc, argv); |
423 return LaunchUnitTestsInternal(run_test_suite, SysInfo::NumberOfProcessors(), | 424 return LaunchUnitTestsInternal( |
424 true, Bind(&InitGoogleTestChar, &argc, argv)); | 425 run_test_suite, |
| 426 SysInfo::NumberOfProcessors(), |
| 427 kDefaultTestBatchLimit, |
| 428 true, |
| 429 Bind(&InitGoogleTestChar, &argc, argv)); |
425 } | 430 } |
426 | 431 |
427 int LaunchUnitTestsSerially(int argc, | 432 int LaunchUnitTestsSerially(int argc, |
428 char** argv, | 433 char** argv, |
429 const RunTestSuiteCallback& run_test_suite) { | 434 const RunTestSuiteCallback& run_test_suite) { |
430 CommandLine::Init(argc, argv); | 435 CommandLine::Init(argc, argv); |
431 return LaunchUnitTestsInternal(run_test_suite, 1, true, | 436 return LaunchUnitTestsInternal( |
432 Bind(&InitGoogleTestChar, &argc, argv)); | 437 run_test_suite, |
| 438 1, |
| 439 kDefaultTestBatchLimit, |
| 440 true, |
| 441 Bind(&InitGoogleTestChar, &argc, argv)); |
| 442 } |
| 443 |
| 444 int LaunchUnitTestsWithOptions( |
| 445 int argc, |
| 446 char** argv, |
| 447 int default_jobs, |
| 448 int default_batch_limit, |
| 449 bool use_job_objects, |
| 450 const RunTestSuiteCallback& run_test_suite) { |
| 451 CommandLine::Init(argc, argv); |
| 452 return LaunchUnitTestsInternal( |
| 453 run_test_suite, |
| 454 default_jobs, |
| 455 default_batch_limit, |
| 456 use_job_objects, |
| 457 Bind(&InitGoogleTestChar, &argc, argv)); |
433 } | 458 } |
434 | 459 |
435 #if defined(OS_WIN) | 460 #if defined(OS_WIN) |
436 int LaunchUnitTests(int argc, | 461 int LaunchUnitTests(int argc, |
437 wchar_t** argv, | 462 wchar_t** argv, |
438 bool use_job_objects, | 463 bool use_job_objects, |
439 const RunTestSuiteCallback& run_test_suite) { | 464 const RunTestSuiteCallback& run_test_suite) { |
440 // Windows CommandLine::Init ignores argv anyway. | 465 // Windows CommandLine::Init ignores argv anyway. |
441 CommandLine::Init(argc, NULL); | 466 CommandLine::Init(argc, NULL); |
442 return LaunchUnitTestsInternal(run_test_suite, SysInfo::NumberOfProcessors(), | 467 return LaunchUnitTestsInternal( |
443 use_job_objects, | 468 run_test_suite, |
444 Bind(&InitGoogleTestWChar, &argc, argv)); | 469 SysInfo::NumberOfProcessors(), |
| 470 kDefaultTestBatchLimit, |
| 471 use_job_objects, |
| 472 Bind(&InitGoogleTestWChar, &argc, argv)); |
445 } | 473 } |
446 #endif // defined(OS_WIN) | 474 #endif // defined(OS_WIN) |
447 | 475 |
448 void RunUnitTestsSerially( | 476 void RunUnitTestsSerially( |
449 TestLauncher* test_launcher, | 477 TestLauncher* test_launcher, |
450 UnitTestPlatformDelegate* platform_delegate, | 478 UnitTestPlatformDelegate* platform_delegate, |
451 const std::vector<std::string>& test_names, | 479 const std::vector<std::string>& test_names, |
452 int launch_flags) { | 480 int launch_flags) { |
453 if (test_names.empty()) | 481 if (test_names.empty()) |
454 return; | 482 return; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 TestLauncher* test_launcher, | 605 TestLauncher* test_launcher, |
578 const std::vector<std::string>& test_names) { | 606 const std::vector<std::string>& test_names) { |
579 ThreadTaskRunnerHandle::Get()->PostTask( | 607 ThreadTaskRunnerHandle::Get()->PostTask( |
580 FROM_HERE, | 608 FROM_HERE, |
581 Bind(&RunUnitTestsSerially, test_launcher, platform_delegate_, test_names, | 609 Bind(&RunUnitTestsSerially, test_launcher, platform_delegate_, test_names, |
582 use_job_objects_ ? TestLauncher::USE_JOB_OBJECTS : 0)); | 610 use_job_objects_ ? TestLauncher::USE_JOB_OBJECTS : 0)); |
583 return test_names.size(); | 611 return test_names.size(); |
584 } | 612 } |
585 | 613 |
586 } // namespace base | 614 } // namespace base |
OLD | NEW |