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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // profile. i.e. Foo.PRE_Test runs and then Foo.Test. This allows writing tests | 54 // profile. i.e. Foo.PRE_Test runs and then Foo.Test. This allows writing tests |
55 // that span browser restarts. | 55 // that span browser restarts. |
56 const char kPreTestPrefix[] = "PRE_"; | 56 const char kPreTestPrefix[] = "PRE_"; |
57 | 57 |
58 // Manual tests only run when --run-manual is specified. This allows writing | 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. | 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 | 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. | 61 // add a new binary that must be compiled on all builds. |
62 const char kManualTestPrefix[] = "MANUAL_"; | 62 const char kManualTestPrefix[] = "MANUAL_"; |
63 | 63 |
| 64 // Tests with this suffix are expected to crash, so it won't count as a failure. |
| 65 // A test that uses this must have a PRE_ prefix. |
| 66 const char kCrashTestSuffix[] = "_CRASH"; |
| 67 |
64 TestLauncherDelegate* g_launcher_delegate; | 68 TestLauncherDelegate* g_launcher_delegate; |
65 } | 69 } |
66 | 70 |
67 // The environment variable name for the total number of test shards. | 71 // The environment variable name for the total number of test shards. |
68 const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; | 72 const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; |
69 // The environment variable name for the test shard index. | 73 // The environment variable name for the test shard index. |
70 const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; | 74 const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; |
71 | 75 |
72 // The default output file for XML output. | 76 // The default output file for XML output. |
73 const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( | 77 const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 std::string replace_string = std::string(".") + kPreTestPrefix; | 328 std::string replace_string = std::string(".") + kPreTestPrefix; |
325 ReplaceFirstSubstringAfterOffset(&pre_test_name, 0, ".", replace_string); | 329 ReplaceFirstSubstringAfterOffset(&pre_test_name, 0, ".", replace_string); |
326 for (int i = 0; i < test_case->total_test_count(); ++i) { | 330 for (int i = 0; i < test_case->total_test_count(); ++i) { |
327 const testing::TestInfo* test_info = test_case->GetTestInfo(i); | 331 const testing::TestInfo* test_info = test_case->GetTestInfo(i); |
328 std::string cur_test_name = test_info->test_case_name(); | 332 std::string cur_test_name = test_info->test_case_name(); |
329 cur_test_name.append("."); | 333 cur_test_name.append("."); |
330 cur_test_name.append(test_info->name()); | 334 cur_test_name.append(test_info->name()); |
331 if (cur_test_name == pre_test_name) { | 335 if (cur_test_name == pre_test_name) { |
332 int exit_code = RunTestInternal(test_case, pre_test_name, command_line, | 336 int exit_code = RunTestInternal(test_case, pre_test_name, command_line, |
333 default_timeout, was_timeout); | 337 default_timeout, was_timeout); |
334 if (exit_code != 0) | 338 if (exit_code != 0 && |
| 339 !EndsWith(pre_test_name, kCrashTestSuffix, true)) { |
335 return exit_code; | 340 return exit_code; |
| 341 } |
336 } | 342 } |
337 } | 343 } |
338 } | 344 } |
339 | 345 |
340 CommandLine new_cmd_line(*command_line); | 346 CommandLine new_cmd_line(*command_line); |
341 | 347 |
342 // Always enable disabled tests. This method is not called with disabled | 348 // Always enable disabled tests. This method is not called with disabled |
343 // tests unless this flag was specified to the browser test executable. | 349 // tests unless this flag was specified to the browser test executable. |
344 new_cmd_line.AppendSwitch("gtest_also_run_disabled_tests"); | 350 new_cmd_line.AppendSwitch("gtest_also_run_disabled_tests"); |
345 new_cmd_line.AppendSwitchASCII("gtest_filter", test_name); | 351 new_cmd_line.AppendSwitchASCII("gtest_filter", test_name); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 439 |
434 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); | 440 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); |
435 iter != switches.end(); ++iter) { | 441 iter != switches.end(); ++iter) { |
436 new_cmd_line.AppendSwitchNative((*iter).first, (*iter).second); | 442 new_cmd_line.AppendSwitchNative((*iter).first, (*iter).second); |
437 } | 443 } |
438 | 444 |
439 // Do not let the child ignore failures. We need to propagate the | 445 // Do not let the child ignore failures. We need to propagate the |
440 // failure status back to the parent. | 446 // failure status back to the parent. |
441 new_cmd_line.AppendSwitch(base::TestSuite::kStrictFailureHandling); | 447 new_cmd_line.AppendSwitch(base::TestSuite::kStrictFailureHandling); |
442 | 448 |
443 if (!launcher_delegate->AdjustChildProcessCommandLine(&new_cmd_line)) | 449 ScopedTempDir temp_dir; |
| 450 // Create a new data dir and pass it to the child. |
| 451 if (!temp_dir.CreateUniqueTempDir() || !temp_dir.IsValid()) { |
| 452 LOG(ERROR) << "Error creating temp data directory"; |
444 return -1; | 453 return -1; |
| 454 } |
| 455 |
| 456 if (!launcher_delegate->AdjustChildProcessCommandLine(&new_cmd_line, |
| 457 temp_dir.path())) { |
| 458 return -1; |
| 459 } |
445 | 460 |
446 return RunTestInternal( | 461 return RunTestInternal( |
447 test_case, test_name, &new_cmd_line, default_timeout, was_timeout); | 462 test_case, test_name, &new_cmd_line, default_timeout, was_timeout); |
448 } | 463 } |
449 | 464 |
450 bool RunTests(TestLauncherDelegate* launcher_delegate, | 465 bool RunTests(TestLauncherDelegate* launcher_delegate, |
451 bool should_shard, | 466 bool should_shard, |
452 int total_shards, | 467 int total_shards, |
453 int shard_index) { | 468 int shard_index) { |
454 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 469 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 cycles--; | 743 cycles--; |
729 } | 744 } |
730 return exit_code; | 745 return exit_code; |
731 } | 746 } |
732 | 747 |
733 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { | 748 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { |
734 return g_launcher_delegate; | 749 return g_launcher_delegate; |
735 } | 750 } |
736 | 751 |
737 } // namespace test_launcher | 752 } // namespace test_launcher |
OLD | NEW |