Chromium Code Reviews| Index: content/test/test_launcher.cc |
| =================================================================== |
| --- content/test/test_launcher.cc (revision 149553) |
| +++ content/test/test_launcher.cc (working copy) |
| @@ -299,53 +299,37 @@ |
| return timeout; |
| } |
| -// Runs test specified by |test_name| in a child process, |
| -// and returns the exit code. |
| -int RunTest(TestLauncherDelegate* launcher_delegate, |
| - const std::string& test_name, |
| - base::TimeDelta default_timeout, |
| - bool* was_timeout) { |
| - if (was_timeout) |
| - *was_timeout = false; |
| +int RunTestInternal(const testing::TestCase* test_case, |
| + const std::string& test_name, |
| + CommandLine* command_line, |
| + base::TimeDelta default_timeout, |
| + bool* was_timeout) { |
| + std::string pre_test_name = test_name; |
|
sky
2012/08/02 15:21:55
move 307/308 inside if (test_case)
jam
2012/08/05 21:44:02
Done.
|
| + ReplaceFirstSubstringAfterOffset(&pre_test_name, 0, ".", ".PRE_"); |
| -#if defined(OS_MACOSX) |
| - // Some of the below method calls will leak objects if there is no |
| - // autorelease pool in place. |
| - base::mac::ScopedNSAutoreleasePool pool; |
| -#endif |
| + if (test_case) { |
| + for (int i = 0; i < test_case->total_test_count(); ++i) { |
| + const testing::TestInfo* test_info = test_case->GetTestInfo(i); |
| + std::string test_name = test_info->test_case_name(); |
|
sky
2012/08/02 15:21:55
nit: use a different name here so you aren't shado
|
| + test_name.append("."); |
| + test_name.append(test_info->name()); |
| + if (test_name == pre_test_name) { |
| + int exit_code = RunTestInternal(test_case, pre_test_name, command_line, |
| + default_timeout, was_timeout); |
| + if (exit_code != 0) |
| + return exit_code; |
| + } |
| + } |
| + } |
| - const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| - CommandLine new_cmd_line(cmd_line->GetProgram()); |
| - CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
| + CommandLine new_cmd_line(*command_line); |
| - // Strip out gtest_output flag because otherwise we would overwrite results |
| - // of the previous test. We will generate the final output file later |
| - // in RunTests(). |
| - switches.erase(kGTestOutputFlag); |
| - |
| - // Strip out gtest_repeat flag because we can only run one test in the child |
| - // process (restarting the browser in the same process is illegal after it |
| - // has been shut down and will actually crash). |
| - switches.erase(kGTestRepeatFlag); |
| - |
| - for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); |
| - iter != switches.end(); ++iter) { |
| - new_cmd_line.AppendSwitchNative((*iter).first, (*iter).second); |
| - } |
| - |
| // Always enable disabled tests. This method is not called with disabled |
| // tests unless this flag was specified to the browser test executable. |
| new_cmd_line.AppendSwitch("gtest_also_run_disabled_tests"); |
| new_cmd_line.AppendSwitchASCII("gtest_filter", test_name); |
| new_cmd_line.AppendSwitch(kSingleProcessTestsFlag); |
| - // Do not let the child ignore failures. We need to propagate the |
| - // failure status back to the parent. |
| - new_cmd_line.AppendSwitch(base::TestSuite::kStrictFailureHandling); |
| - |
| - if (!launcher_delegate->AdjustChildProcessCommandLine(&new_cmd_line)) |
| - return -1; |
| - |
| const char* browser_wrapper = getenv("BROWSER_WRAPPER"); |
| if (browser_wrapper) { |
| #if defined(OS_WIN) |
| @@ -402,6 +386,52 @@ |
| return exit_code; |
| } |
| +// Runs test specified by |test_name| in a child process, |
| +// and returns the exit code. |
| +int RunTest(TestLauncherDelegate* launcher_delegate, |
| + const testing::TestCase* test_case, |
| + const std::string& test_name, |
| + base::TimeDelta default_timeout, |
| + bool* was_timeout) { |
| + if (was_timeout) |
| + *was_timeout = false; |
| + |
| +#if defined(OS_MACOSX) |
| + // Some of the below method calls will leak objects if there is no |
| + // autorelease pool in place. |
| + base::mac::ScopedNSAutoreleasePool pool; |
| +#endif |
| + |
| + const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| + CommandLine new_cmd_line(cmd_line->GetProgram()); |
| + CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
| + |
| + // Strip out gtest_output flag because otherwise we would overwrite results |
| + // of the previous test. We will generate the final output file later |
| + // in RunTests(). |
| + switches.erase(kGTestOutputFlag); |
| + |
| + // Strip out gtest_repeat flag because we can only run one test in the child |
| + // process (restarting the browser in the same process is illegal after it |
| + // has been shut down and will actually crash). |
| + switches.erase(kGTestRepeatFlag); |
| + |
| + for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); |
| + iter != switches.end(); ++iter) { |
| + new_cmd_line.AppendSwitchNative((*iter).first, (*iter).second); |
| + } |
| + |
| + // Do not let the child ignore failures. We need to propagate the |
| + // failure status back to the parent. |
| + new_cmd_line.AppendSwitch(base::TestSuite::kStrictFailureHandling); |
| + |
| + if (!launcher_delegate->AdjustChildProcessCommandLine(&new_cmd_line)) |
| + return -1; |
| + |
| + return RunTestInternal( |
| + test_case, test_name, &new_cmd_line, default_timeout, was_timeout); |
| +} |
| + |
| bool RunTests(TestLauncherDelegate* launcher_delegate, |
| bool should_shard, |
| int total_shards, |
| @@ -454,6 +484,9 @@ |
| continue; |
| } |
| + if (StartsWithASCII(test_info->name(), "PRE_", true)) |
| + continue; |
| + |
| // Skip the test that doesn't match the filter string (if given). |
| if ((!positive_filter.empty() && |
| !MatchesFilter(test_name, positive_filter)) || |
| @@ -479,6 +512,7 @@ |
| ++test_run_count; |
| bool was_timeout = false; |
| int exit_code = RunTest(launcher_delegate, |
| + test_case, |
| test_name, |
| TestTimeouts::action_max_timeout(), |
| &was_timeout); |
| @@ -641,6 +675,7 @@ |
| bool has_filter = command_line->HasSwitch(kGTestFilterFlag); |
| if (warmup || (!should_shard && !has_filter)) { |
| exit_code = RunTest(launcher_delegate, |
| + NULL, |
| empty_test, |
| TestTimeouts::large_test_timeout(), |
| NULL); |