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