OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // tests unless this flag was specified to the browser test executable. | 82 // tests unless this flag was specified to the browser test executable. |
83 new_cmd_line.AppendSwitch("gtest_also_run_disabled_tests"); | 83 new_cmd_line.AppendSwitch("gtest_also_run_disabled_tests"); |
84 new_cmd_line.AppendSwitchASCII("gtest_filter", test_name); | 84 new_cmd_line.AppendSwitchASCII("gtest_filter", test_name); |
85 new_cmd_line.AppendSwitch(kChildProcessFlag); | 85 new_cmd_line.AppendSwitch(kChildProcessFlag); |
86 | 86 |
87 // Do not let the child ignore failures. We need to propagate the | 87 // Do not let the child ignore failures. We need to propagate the |
88 // failure status back to the parent. | 88 // failure status back to the parent. |
89 new_cmd_line.AppendSwitch(base::TestSuite::kStrictFailureHandling); | 89 new_cmd_line.AppendSwitch(base::TestSuite::kStrictFailureHandling); |
90 | 90 |
91 base::ProcessHandle process_handle; | 91 base::ProcessHandle process_handle; |
| 92 #if defined(OS_POSIX) |
| 93 // On POSIX, we launch the test in a new process group with pgid equal to |
| 94 // its pid. Any child processes that the test may create will inherit the |
| 95 // same pgid. This way, if the test is abruptly terminated, we can clean up |
| 96 // any orphaned child processes it may have left behind. |
| 97 base::environment_vector no_env; |
| 98 base::file_handle_mapping_vector no_files; |
| 99 if (!base::LaunchAppInNewProcessGroup(new_cmd_line.argv(), no_env, no_files, |
| 100 false, &process_handle)) |
| 101 #else |
92 if (!base::LaunchApp(new_cmd_line, false, false, &process_handle)) | 102 if (!base::LaunchApp(new_cmd_line, false, false, &process_handle)) |
| 103 #endif |
93 return false; | 104 return false; |
94 | 105 |
95 int test_terminate_timeout_ms = kDefaultTestTimeoutMs; | 106 int test_terminate_timeout_ms = kDefaultTestTimeoutMs; |
96 if (cmd_line->HasSwitch(kTestTerminateTimeoutFlag)) { | 107 if (cmd_line->HasSwitch(kTestTerminateTimeoutFlag)) { |
97 std::string timeout_str = | 108 std::string timeout_str = |
98 cmd_line->GetSwitchValueASCII(kTestTerminateTimeoutFlag); | 109 cmd_line->GetSwitchValueASCII(kTestTerminateTimeoutFlag); |
99 int timeout; | 110 int timeout; |
100 base::StringToInt(timeout_str, &timeout); | 111 base::StringToInt(timeout_str, &timeout); |
101 test_terminate_timeout_ms = std::max(test_terminate_timeout_ms, timeout); | 112 test_terminate_timeout_ms = std::max(test_terminate_timeout_ms, timeout); |
102 } | 113 } |
103 | 114 |
104 int exit_code = 0; | 115 int exit_code = 0; |
105 if (!base::WaitForExitCodeWithTimeout(process_handle, &exit_code, | 116 if (!base::WaitForExitCodeWithTimeout(process_handle, &exit_code, |
106 test_terminate_timeout_ms)) { | 117 test_terminate_timeout_ms)) { |
107 LOG(ERROR) << "Test timeout (" << test_terminate_timeout_ms | 118 LOG(ERROR) << "Test timeout (" << test_terminate_timeout_ms |
108 << " ms) exceeded for " << test_name; | 119 << " ms) exceeded for " << test_name; |
109 | 120 |
110 exit_code = -1; // Set a non-zero exit code to signal a failure. | 121 exit_code = -1; // Set a non-zero exit code to signal a failure. |
111 | 122 |
112 // Ensure that the process terminates. | 123 // Ensure that the process terminates. |
113 base::KillProcess(process_handle, -1, true); | 124 base::KillProcess(process_handle, -1, true); |
| 125 |
| 126 #if defined(OS_POSIX) |
| 127 // On POSIX, we need to clean up any child processes that the test might |
| 128 // have created. On windows, child processes are automatically cleaned up |
| 129 // using JobObjects. |
| 130 base::KillProcessGroup(process_handle); |
| 131 #endif |
114 } | 132 } |
115 | 133 |
116 return exit_code == 0; | 134 return exit_code == 0; |
117 } | 135 } |
118 | 136 |
119 private: | 137 private: |
120 DISALLOW_COPY_AND_ASSIGN(OutOfProcTestRunner); | 138 DISALLOW_COPY_AND_ASSIGN(OutOfProcTestRunner); |
121 }; | 139 }; |
122 | 140 |
123 class OutOfProcTestRunnerFactory : public tests::TestRunnerFactory { | 141 class OutOfProcTestRunnerFactory : public tests::TestRunnerFactory { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 exit_code = 1; | 247 exit_code = 1; |
230 break; | 248 break; |
231 } | 249 } |
232 | 250 |
233 // Special value "-1" means "repeat indefinitely". | 251 // Special value "-1" means "repeat indefinitely". |
234 if (cycles != -1) | 252 if (cycles != -1) |
235 cycles--; | 253 cycles--; |
236 } | 254 } |
237 return exit_code; | 255 return exit_code; |
238 } | 256 } |
OLD | NEW |