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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 std::string switch_value = | 435 std::string switch_value = |
436 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); | 436 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); |
437 if (!StringToInt(switch_value, result) || *result < 1) { | 437 if (!StringToInt(switch_value, result) || *result < 1) { |
438 LOG(ERROR) << "Invalid value for " << switch_name << ": " << switch_value; | 438 LOG(ERROR) << "Invalid value for " << switch_name << ": " << switch_value; |
439 return false; | 439 return false; |
440 } | 440 } |
441 | 441 |
442 return true; | 442 return true; |
443 } | 443 } |
444 | 444 |
445 } // namespace | 445 int LaunchUnitTestsInternal(int argc, |
446 | 446 char** argv, |
447 int LaunchUnitTests(int argc, | 447 const RunTestSuiteCallback& run_test_suite, |
448 char** argv, | 448 int default_jobs) { |
449 const RunTestSuiteCallback& run_test_suite) { | |
450 CommandLine::Init(argc, argv); | 449 CommandLine::Init(argc, argv); |
451 if (CommandLine::ForCurrentProcess()->HasSwitch(kGTestHelpFlag) || | 450 if (CommandLine::ForCurrentProcess()->HasSwitch(kGTestHelpFlag) || |
452 CommandLine::ForCurrentProcess()->HasSwitch(kSingleProcessTestsFlag) || | 451 CommandLine::ForCurrentProcess()->HasSwitch(kSingleProcessTestsFlag) || |
453 !CommandLine::ForCurrentProcess()->HasSwitch(kBraveNewTestLauncherFlag)) { | 452 !CommandLine::ForCurrentProcess()->HasSwitch(kBraveNewTestLauncherFlag)) { |
454 return run_test_suite.Run(); | 453 return run_test_suite.Run(); |
455 } | 454 } |
456 | 455 |
457 if (CommandLine::ForCurrentProcess()->HasSwitch(kHelpFlag)) { | 456 if (CommandLine::ForCurrentProcess()->HasSwitch(kHelpFlag)) { |
458 PrintUsage(); | 457 PrintUsage(); |
459 return 0; | 458 return 0; |
(...skipping 10 matching lines...) Expand all Loading... |
470 | 469 |
471 fprintf(stdout, | 470 fprintf(stdout, |
472 "IMPORTANT DEBUGGING NOTE: batches of tests are run inside their\n" | 471 "IMPORTANT DEBUGGING NOTE: batches of tests are run inside their\n" |
473 "own process. For debugging a test inside a debugger, use the\n" | 472 "own process. For debugging a test inside a debugger, use the\n" |
474 "--gtest_filter=<your_test_name> flag along with\n" | 473 "--gtest_filter=<your_test_name> flag along with\n" |
475 "--single-process-tests.\n"); | 474 "--single-process-tests.\n"); |
476 fflush(stdout); | 475 fflush(stdout); |
477 | 476 |
478 MessageLoopForIO message_loop; | 477 MessageLoopForIO message_loop; |
479 | 478 |
480 base::UnitTestLauncherDelegate delegate(batch_limit); | 479 UnitTestLauncherDelegate delegate(batch_limit); |
481 base::TestLauncher launcher(&delegate, SysInfo::NumberOfProcessors()); | 480 base::TestLauncher launcher(&delegate, SysInfo::NumberOfProcessors()); |
482 bool success = launcher.Run(argc, argv); | 481 bool success = launcher.Run(argc, argv); |
483 | 482 |
484 fprintf(stdout, | 483 fprintf(stdout, |
485 "Tests took %" PRId64 " seconds.\n", | 484 "Tests took %" PRId64 " seconds.\n", |
486 (base::TimeTicks::Now() - start_time).InSeconds()); | 485 (base::TimeTicks::Now() - start_time).InSeconds()); |
487 fflush(stdout); | 486 fflush(stdout); |
488 | 487 |
489 return (success ? 0 : 1); | 488 return (success ? 0 : 1); |
490 } | 489 } |
491 | 490 |
| 491 } // namespace |
| 492 |
| 493 int LaunchUnitTests(int argc, |
| 494 char** argv, |
| 495 const RunTestSuiteCallback& run_test_suite) { |
| 496 return LaunchUnitTestsInternal( |
| 497 argc, argv, run_test_suite, SysInfo::NumberOfProcessors()); |
| 498 } |
| 499 |
| 500 int LaunchUnitTestsSerially(int argc, |
| 501 char** argv, |
| 502 const RunTestSuiteCallback& run_test_suite) { |
| 503 return LaunchUnitTestsInternal(argc, argv, run_test_suite, 1); |
| 504 } |
| 505 |
492 } // namespace base | 506 } // namespace base |
OLD | NEW |