Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/public/test/test_launcher.h" | 5 #include "content/public/test/test_launcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 #include "sandbox/win/src/dep.h" | 34 #include "sandbox/win/src/dep.h" |
| 35 #include "sandbox/win/src/sandbox_factory.h" | 35 #include "sandbox/win/src/sandbox_factory.h" |
| 36 #include "sandbox/win/src/sandbox_types.h" | 36 #include "sandbox/win/src/sandbox_types.h" |
| 37 #elif defined(OS_MACOSX) | 37 #elif defined(OS_MACOSX) |
| 38 #include "base/mac/scoped_nsautorelease_pool.h" | 38 #include "base/mac/scoped_nsautorelease_pool.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 namespace test_launcher { | 41 namespace test_launcher { |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | |
| 45 // A multiplier for slow tests. We generally avoid multiplying | |
| 46 // test timeouts by any constants. Here it is used as last resort | |
| 47 // to implement the SLOW_ test prefix. | |
| 48 static const int kSlowTestTimeoutMultiplier = 5; | |
|
darin (slow to review)
2012/08/11 06:16:59
nit: 'static' is redundant w/ anonymous namespace
jam
2012/08/13 00:45:25
Done.
| |
| 49 | |
| 50 // Tests with this prefix have a longer timeout, see above. | |
| 51 const char kSlowTestPrefix[] = "SLOW_"; | |
| 52 | |
| 53 // Tests with this prefix run before the same test without it, and use the same | |
| 54 // profile. i.e. Foo.PRE_Test runs and then Foo.Test. This allows writing tests | |
| 55 // that span browser restarts. | |
| 56 const char kPreTestPrefix[] = "PRE_"; | |
| 57 | |
| 58 // Manual tests only run when --run-manual is specified. This allows writing | |
| 59 // tests that don't run automatically but are still in the same test binary. | |
| 60 // This is useful so that a team that wants to run a few tests doesn't have to | |
| 61 // add a new binary that must be compiled on all builds. | |
| 62 const char kManualTestPrefix[] = "MANUAL_"; | |
| 63 | |
| 44 TestLauncherDelegate* g_launcher_delegate; | 64 TestLauncherDelegate* g_launcher_delegate; |
| 45 } | 65 } |
| 46 | 66 |
| 47 // The environment variable name for the total number of test shards. | 67 // The environment variable name for the total number of test shards. |
| 48 const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; | 68 const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; |
| 49 // The environment variable name for the test shard index. | 69 // The environment variable name for the test shard index. |
| 50 const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; | 70 const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; |
| 51 | 71 |
| 52 // The default output file for XML output. | 72 // The default output file for XML output. |
| 53 const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( | 73 const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 // Returns if no more pattern can be found. | 294 // Returns if no more pattern can be found. |
| 275 if (cur_pattern == NULL) { | 295 if (cur_pattern == NULL) { |
| 276 return false; | 296 return false; |
| 277 } | 297 } |
| 278 | 298 |
| 279 // Skips the pattern separater (the ':' character). | 299 // Skips the pattern separater (the ':' character). |
| 280 cur_pattern++; | 300 cur_pattern++; |
| 281 } | 301 } |
| 282 } | 302 } |
| 283 | 303 |
| 284 // A multiplier for slow tests. We generally avoid multiplying | |
| 285 // test timeouts by any constants. Here it is used as last resort | |
| 286 // to implement the SLOW_ test prefix. | |
| 287 static const int kSlowTestTimeoutMultiplier = 5; | |
| 288 | |
| 289 base::TimeDelta GetTestTerminationTimeout(const std::string& test_name, | 304 base::TimeDelta GetTestTerminationTimeout(const std::string& test_name, |
| 290 base::TimeDelta default_timeout) { | 305 base::TimeDelta default_timeout) { |
| 291 base::TimeDelta timeout = default_timeout; | 306 base::TimeDelta timeout = default_timeout; |
| 292 | 307 |
| 293 // Make it possible for selected tests to request a longer timeout. | 308 // Make it possible for selected tests to request a longer timeout. |
| 294 // Generally tests should really avoid doing too much, and splitting | 309 // Generally tests should really avoid doing too much, and splitting |
| 295 // a test instead of using SLOW prefix is strongly preferred. | 310 // a test instead of using SLOW prefix is strongly preferred. |
| 296 if (test_name.find("SLOW_") != std::string::npos) | 311 if (test_name.find(kSlowTestPrefix) != std::string::npos) |
| 297 timeout *= kSlowTestTimeoutMultiplier; | 312 timeout *= kSlowTestTimeoutMultiplier; |
| 298 | 313 |
| 299 return timeout; | 314 return timeout; |
| 300 } | 315 } |
| 301 | 316 |
| 302 int RunTestInternal(const testing::TestCase* test_case, | 317 int RunTestInternal(const testing::TestCase* test_case, |
| 303 const std::string& test_name, | 318 const std::string& test_name, |
| 304 CommandLine* command_line, | 319 CommandLine* command_line, |
| 305 base::TimeDelta default_timeout, | 320 base::TimeDelta default_timeout, |
| 306 bool* was_timeout) { | 321 bool* was_timeout) { |
| 307 if (test_case) { | 322 if (test_case) { |
| 308 std::string pre_test_name = test_name; | 323 std::string pre_test_name = test_name; |
| 309 ReplaceFirstSubstringAfterOffset(&pre_test_name, 0, ".", ".PRE_"); | 324 std::string replace_string = std::string(".") + kPreTestPrefix; |
| 325 ReplaceFirstSubstringAfterOffset(&pre_test_name, 0, ".", replace_string); | |
| 310 for (int i = 0; i < test_case->total_test_count(); ++i) { | 326 for (int i = 0; i < test_case->total_test_count(); ++i) { |
| 311 const testing::TestInfo* test_info = test_case->GetTestInfo(i); | 327 const testing::TestInfo* test_info = test_case->GetTestInfo(i); |
| 312 std::string cur_test_name = test_info->test_case_name(); | 328 std::string cur_test_name = test_info->test_case_name(); |
| 313 cur_test_name.append("."); | 329 cur_test_name.append("."); |
| 314 cur_test_name.append(test_info->name()); | 330 cur_test_name.append(test_info->name()); |
| 315 if (cur_test_name == pre_test_name) { | 331 if (cur_test_name == pre_test_name) { |
| 316 int exit_code = RunTestInternal(test_case, pre_test_name, command_line, | 332 int exit_code = RunTestInternal(test_case, pre_test_name, command_line, |
| 317 default_timeout, was_timeout); | 333 default_timeout, was_timeout); |
| 318 if (exit_code != 0) | 334 if (exit_code != 0) |
| 319 return exit_code; | 335 return exit_code; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 continue; | 492 continue; |
| 477 | 493 |
| 478 // Skip disabled tests. | 494 // Skip disabled tests. |
| 479 if (test_name.find("DISABLED") != std::string::npos && | 495 if (test_name.find("DISABLED") != std::string::npos && |
| 480 !command_line->HasSwitch(kGTestRunDisabledTestsFlag)) { | 496 !command_line->HasSwitch(kGTestRunDisabledTestsFlag)) { |
| 481 printer.OnTestEnd(test_info->name(), test_case->name(), | 497 printer.OnTestEnd(test_info->name(), test_case->name(), |
| 482 false, false, false, 0); | 498 false, false, false, 0); |
| 483 continue; | 499 continue; |
| 484 } | 500 } |
| 485 | 501 |
| 486 if (StartsWithASCII(test_info->name(), "PRE_", true)) | 502 if (StartsWithASCII(test_info->name(), kPreTestPrefix, true)) |
| 487 continue; | 503 continue; |
| 488 | 504 |
| 505 if (StartsWithASCII(test_info->name(), kManualTestPrefix, true) && | |
| 506 !command_line->HasSwitch(kRunManualTestsFlag)) { | |
| 507 continue; | |
| 508 } | |
| 509 | |
| 489 // Skip the test that doesn't match the filter string (if given). | 510 // Skip the test that doesn't match the filter string (if given). |
| 490 if ((!positive_filter.empty() && | 511 if ((!positive_filter.empty() && |
| 491 !MatchesFilter(test_name, positive_filter)) || | 512 !MatchesFilter(test_name, positive_filter)) || |
| 492 MatchesFilter(test_name, negative_filter)) { | 513 MatchesFilter(test_name, negative_filter)) { |
| 493 printer.OnTestEnd(test_info->name(), test_case->name(), | 514 printer.OnTestEnd(test_info->name(), test_case->name(), |
| 494 false, false, false, 0); | 515 false, false, false, 0); |
| 495 continue; | 516 continue; |
| 496 } | 517 } |
| 497 | 518 |
| 498 // Decide if this test should be run. | 519 // Decide if this test should be run. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 588 | 609 |
| 589 const char kGTestFilterFlag[] = "gtest_filter"; | 610 const char kGTestFilterFlag[] = "gtest_filter"; |
| 590 const char kGTestHelpFlag[] = "gtest_help"; | 611 const char kGTestHelpFlag[] = "gtest_help"; |
| 591 const char kGTestListTestsFlag[] = "gtest_list_tests"; | 612 const char kGTestListTestsFlag[] = "gtest_list_tests"; |
| 592 const char kGTestRepeatFlag[] = "gtest_repeat"; | 613 const char kGTestRepeatFlag[] = "gtest_repeat"; |
| 593 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests"; | 614 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests"; |
| 594 const char kGTestOutputFlag[] = "gtest_output"; | 615 const char kGTestOutputFlag[] = "gtest_output"; |
| 595 | 616 |
| 596 const char kSingleProcessTestsFlag[] = "single_process"; | 617 const char kSingleProcessTestsFlag[] = "single_process"; |
| 597 const char kSingleProcessTestsAndChromeFlag[] = "single-process"; | 618 const char kSingleProcessTestsAndChromeFlag[] = "single-process"; |
| 619 | |
| 620 // See kManualTestPrefix above. | |
| 621 const char kRunManualTestsFlag[] = "run-manual"; | |
| 622 | |
| 598 // The following is kept for historical reasons (so people that are used to | 623 // The following is kept for historical reasons (so people that are used to |
| 599 // using it don't get surprised). | 624 // using it don't get surprised). |
| 600 const char kChildProcessFlag[] = "child"; | 625 const char kChildProcessFlag[] = "child"; |
| 601 | 626 |
| 602 const char kHelpFlag[] = "help"; | 627 const char kHelpFlag[] = "help"; |
| 603 | 628 |
| 604 const char kWarmupFlag[] = "warmup"; | 629 const char kWarmupFlag[] = "warmup"; |
| 605 | 630 |
| 606 TestLauncherDelegate::~TestLauncherDelegate() { | 631 TestLauncherDelegate::~TestLauncherDelegate() { |
| 607 } | 632 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 cycles--; | 728 cycles--; |
| 704 } | 729 } |
| 705 return exit_code; | 730 return exit_code; |
| 706 } | 731 } |
| 707 | 732 |
| 708 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { | 733 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { |
| 709 return g_launcher_delegate; | 734 return g_launcher_delegate; |
| 710 } | 735 } |
| 711 | 736 |
| 712 } // namespace test_launcher | 737 } // namespace test_launcher |
| OLD | NEW |