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 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 PathService::Get(base::DIR_CACHE, &tmp_dir); | 137 PathService::Get(base::DIR_CACHE, &tmp_dir); |
138 tmp_dir = tmp_dir.Append(filename); | 138 tmp_dir = tmp_dir.Append(filename); |
139 return tmp_dir.value(); | 139 return tmp_dir.value(); |
140 #endif | 140 #endif |
141 } | 141 } |
142 | 142 |
143 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { | 143 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { |
144 return 0; | 144 return 0; |
145 } | 145 } |
146 | 146 |
| 147 // TODO(viettrungluu): This should be in a "MultiProcessTestTest". |
147 TEST_F(ProcessUtilTest, SpawnChild) { | 148 TEST_F(ProcessUtilTest, SpawnChild) { |
148 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess", false); | 149 base::ProcessHandle handle = SpawnChild("SimpleChildProcess"); |
149 ASSERT_NE(base::kNullProcessHandle, handle); | 150 ASSERT_NE(base::kNullProcessHandle, handle); |
150 EXPECT_TRUE(base::WaitForSingleProcess( | 151 EXPECT_TRUE(base::WaitForSingleProcess( |
151 handle, TestTimeouts::action_max_timeout())); | 152 handle, TestTimeouts::action_max_timeout())); |
152 base::CloseProcessHandle(handle); | 153 base::CloseProcessHandle(handle); |
153 } | 154 } |
154 | 155 |
155 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { | 156 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { |
156 WaitToDie(ProcessUtilTest::GetSignalFilePath(kSignalFileSlow).c_str()); | 157 WaitToDie(ProcessUtilTest::GetSignalFilePath(kSignalFileSlow).c_str()); |
157 return 0; | 158 return 0; |
158 } | 159 } |
159 | 160 |
160 TEST_F(ProcessUtilTest, KillSlowChild) { | 161 TEST_F(ProcessUtilTest, KillSlowChild) { |
161 const std::string signal_file = | 162 const std::string signal_file = |
162 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); | 163 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); |
163 remove(signal_file.c_str()); | 164 remove(signal_file.c_str()); |
164 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); | 165 base::ProcessHandle handle = SpawnChild("SlowChildProcess"); |
165 ASSERT_NE(base::kNullProcessHandle, handle); | 166 ASSERT_NE(base::kNullProcessHandle, handle); |
166 SignalChildren(signal_file.c_str()); | 167 SignalChildren(signal_file.c_str()); |
167 EXPECT_TRUE(base::WaitForSingleProcess( | 168 EXPECT_TRUE(base::WaitForSingleProcess( |
168 handle, TestTimeouts::action_max_timeout())); | 169 handle, TestTimeouts::action_max_timeout())); |
169 base::CloseProcessHandle(handle); | 170 base::CloseProcessHandle(handle); |
170 remove(signal_file.c_str()); | 171 remove(signal_file.c_str()); |
171 } | 172 } |
172 | 173 |
173 // Times out on Linux and Win, flakes on other platforms, http://crbug.com/95058 | 174 // Times out on Linux and Win, flakes on other platforms, http://crbug.com/95058 |
174 TEST_F(ProcessUtilTest, DISABLED_GetTerminationStatusExit) { | 175 TEST_F(ProcessUtilTest, DISABLED_GetTerminationStatusExit) { |
175 const std::string signal_file = | 176 const std::string signal_file = |
176 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); | 177 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); |
177 remove(signal_file.c_str()); | 178 remove(signal_file.c_str()); |
178 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); | 179 base::ProcessHandle handle = SpawnChild("SlowChildProcess"); |
179 ASSERT_NE(base::kNullProcessHandle, handle); | 180 ASSERT_NE(base::kNullProcessHandle, handle); |
180 | 181 |
181 int exit_code = 42; | 182 int exit_code = 42; |
182 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING, | 183 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING, |
183 base::GetTerminationStatus(handle, &exit_code)); | 184 base::GetTerminationStatus(handle, &exit_code)); |
184 EXPECT_EQ(kExpectedStillRunningExitCode, exit_code); | 185 EXPECT_EQ(kExpectedStillRunningExitCode, exit_code); |
185 | 186 |
186 SignalChildren(signal_file.c_str()); | 187 SignalChildren(signal_file.c_str()); |
187 exit_code = 42; | 188 exit_code = 42; |
188 base::TerminationStatus status = | 189 base::TerminationStatus status = |
189 WaitForChildTermination(handle, &exit_code); | 190 WaitForChildTermination(handle, &exit_code); |
190 EXPECT_EQ(base::TERMINATION_STATUS_NORMAL_TERMINATION, status); | 191 EXPECT_EQ(base::TERMINATION_STATUS_NORMAL_TERMINATION, status); |
191 EXPECT_EQ(0, exit_code); | 192 EXPECT_EQ(0, exit_code); |
192 base::CloseProcessHandle(handle); | 193 base::CloseProcessHandle(handle); |
193 remove(signal_file.c_str()); | 194 remove(signal_file.c_str()); |
194 } | 195 } |
195 | 196 |
196 #if defined(OS_WIN) | 197 #if defined(OS_WIN) |
197 // TODO(cpu): figure out how to test this in other platforms. | 198 // TODO(cpu): figure out how to test this in other platforms. |
198 TEST_F(ProcessUtilTest, GetProcId) { | 199 TEST_F(ProcessUtilTest, GetProcId) { |
199 base::ProcessId id1 = base::GetProcId(GetCurrentProcess()); | 200 base::ProcessId id1 = base::GetProcId(GetCurrentProcess()); |
200 EXPECT_NE(0ul, id1); | 201 EXPECT_NE(0ul, id1); |
201 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess", false); | 202 base::ProcessHandle handle = SpawnChild("SimpleChildProcess"); |
202 ASSERT_NE(base::kNullProcessHandle, handle); | 203 ASSERT_NE(base::kNullProcessHandle, handle); |
203 base::ProcessId id2 = base::GetProcId(handle); | 204 base::ProcessId id2 = base::GetProcId(handle); |
204 EXPECT_NE(0ul, id2); | 205 EXPECT_NE(0ul, id2); |
205 EXPECT_NE(id1, id2); | 206 EXPECT_NE(id1, id2); |
206 base::CloseProcessHandle(handle); | 207 base::CloseProcessHandle(handle); |
207 } | 208 } |
208 #endif | 209 #endif |
209 | 210 |
210 #if !defined(OS_MACOSX) | 211 #if !defined(OS_MACOSX) |
211 // This test is disabled on Mac, since it's flaky due to ReportCrash | 212 // This test is disabled on Mac, since it's flaky due to ReportCrash |
(...skipping 24 matching lines...) Expand all Loading... |
236 // TODO(jschuh): crbug.com/175753 Fix this in Win64 bots. | 237 // TODO(jschuh): crbug.com/175753 Fix this in Win64 bots. |
237 #if defined(ADDRESS_SANITIZER) || (defined(OS_WIN) && defined(ARCH_CPU_X86_64)) | 238 #if defined(ADDRESS_SANITIZER) || (defined(OS_WIN) && defined(ARCH_CPU_X86_64)) |
238 #define MAYBE_GetTerminationStatusCrash DISABLED_GetTerminationStatusCrash | 239 #define MAYBE_GetTerminationStatusCrash DISABLED_GetTerminationStatusCrash |
239 #else | 240 #else |
240 #define MAYBE_GetTerminationStatusCrash GetTerminationStatusCrash | 241 #define MAYBE_GetTerminationStatusCrash GetTerminationStatusCrash |
241 #endif | 242 #endif |
242 TEST_F(ProcessUtilTest, MAYBE_GetTerminationStatusCrash) { | 243 TEST_F(ProcessUtilTest, MAYBE_GetTerminationStatusCrash) { |
243 const std::string signal_file = | 244 const std::string signal_file = |
244 ProcessUtilTest::GetSignalFilePath(kSignalFileCrash); | 245 ProcessUtilTest::GetSignalFilePath(kSignalFileCrash); |
245 remove(signal_file.c_str()); | 246 remove(signal_file.c_str()); |
246 base::ProcessHandle handle = this->SpawnChild("CrashingChildProcess", | 247 base::ProcessHandle handle = SpawnChild("CrashingChildProcess"); |
247 false); | |
248 ASSERT_NE(base::kNullProcessHandle, handle); | 248 ASSERT_NE(base::kNullProcessHandle, handle); |
249 | 249 |
250 int exit_code = 42; | 250 int exit_code = 42; |
251 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING, | 251 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING, |
252 base::GetTerminationStatus(handle, &exit_code)); | 252 base::GetTerminationStatus(handle, &exit_code)); |
253 EXPECT_EQ(kExpectedStillRunningExitCode, exit_code); | 253 EXPECT_EQ(kExpectedStillRunningExitCode, exit_code); |
254 | 254 |
255 SignalChildren(signal_file.c_str()); | 255 SignalChildren(signal_file.c_str()); |
256 exit_code = 42; | 256 exit_code = 42; |
257 base::TerminationStatus status = | 257 base::TerminationStatus status = |
(...skipping 26 matching lines...) Expand all Loading... |
284 // Send a SIGKILL to this process, just like the OOM killer would. | 284 // Send a SIGKILL to this process, just like the OOM killer would. |
285 ::kill(getpid(), SIGKILL); | 285 ::kill(getpid(), SIGKILL); |
286 #endif | 286 #endif |
287 return 1; | 287 return 1; |
288 } | 288 } |
289 | 289 |
290 TEST_F(ProcessUtilTest, GetTerminationStatusKill) { | 290 TEST_F(ProcessUtilTest, GetTerminationStatusKill) { |
291 const std::string signal_file = | 291 const std::string signal_file = |
292 ProcessUtilTest::GetSignalFilePath(kSignalFileKill); | 292 ProcessUtilTest::GetSignalFilePath(kSignalFileKill); |
293 remove(signal_file.c_str()); | 293 remove(signal_file.c_str()); |
294 base::ProcessHandle handle = this->SpawnChild("KilledChildProcess", | 294 base::ProcessHandle handle = SpawnChild("KilledChildProcess"); |
295 false); | |
296 ASSERT_NE(base::kNullProcessHandle, handle); | 295 ASSERT_NE(base::kNullProcessHandle, handle); |
297 | 296 |
298 int exit_code = 42; | 297 int exit_code = 42; |
299 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING, | 298 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING, |
300 base::GetTerminationStatus(handle, &exit_code)); | 299 base::GetTerminationStatus(handle, &exit_code)); |
301 EXPECT_EQ(kExpectedStillRunningExitCode, exit_code); | 300 EXPECT_EQ(kExpectedStillRunningExitCode, exit_code); |
302 | 301 |
303 SignalChildren(signal_file.c_str()); | 302 SignalChildren(signal_file.c_str()); |
304 exit_code = 42; | 303 exit_code = 42; |
305 base::TerminationStatus status = | 304 base::TerminationStatus status = |
306 WaitForChildTermination(handle, &exit_code); | 305 WaitForChildTermination(handle, &exit_code); |
307 EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_WAS_KILLED, status); | 306 EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_WAS_KILLED, status); |
308 #if defined(OS_WIN) | 307 #if defined(OS_WIN) |
309 EXPECT_EQ(kExpectedKilledExitCode, exit_code); | 308 EXPECT_EQ(kExpectedKilledExitCode, exit_code); |
310 #elif defined(OS_POSIX) | 309 #elif defined(OS_POSIX) |
311 int signaled = WIFSIGNALED(exit_code); | 310 int signaled = WIFSIGNALED(exit_code); |
312 EXPECT_NE(0, signaled); | 311 EXPECT_NE(0, signaled); |
313 int signal = WTERMSIG(exit_code); | 312 int signal = WTERMSIG(exit_code); |
314 EXPECT_EQ(SIGKILL, signal); | 313 EXPECT_EQ(SIGKILL, signal); |
315 #endif | 314 #endif |
316 base::CloseProcessHandle(handle); | 315 base::CloseProcessHandle(handle); |
317 remove(signal_file.c_str()); | 316 remove(signal_file.c_str()); |
318 } | 317 } |
319 | 318 |
320 // Ensure that the priority of a process is restored correctly after | 319 // Ensure that the priority of a process is restored correctly after |
321 // backgrounding and restoring. | 320 // backgrounding and restoring. |
322 // Note: a platform may not be willing or able to lower the priority of | 321 // Note: a platform may not be willing or able to lower the priority of |
323 // a process. The calls to SetProcessBackground should be noops then. | 322 // a process. The calls to SetProcessBackground should be noops then. |
324 TEST_F(ProcessUtilTest, SetProcessBackgrounded) { | 323 TEST_F(ProcessUtilTest, SetProcessBackgrounded) { |
325 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess", false); | 324 base::ProcessHandle handle = SpawnChild("SimpleChildProcess"); |
326 base::Process process(handle); | 325 base::Process process(handle); |
327 int old_priority = process.GetPriority(); | 326 int old_priority = process.GetPriority(); |
328 #if defined(OS_WIN) | 327 #if defined(OS_WIN) |
329 EXPECT_TRUE(process.SetProcessBackgrounded(true)); | 328 EXPECT_TRUE(process.SetProcessBackgrounded(true)); |
330 EXPECT_TRUE(process.IsProcessBackgrounded()); | 329 EXPECT_TRUE(process.IsProcessBackgrounded()); |
331 EXPECT_TRUE(process.SetProcessBackgrounded(false)); | 330 EXPECT_TRUE(process.SetProcessBackgrounded(false)); |
332 EXPECT_FALSE(process.IsProcessBackgrounded()); | 331 EXPECT_FALSE(process.IsProcessBackgrounded()); |
333 #else | 332 #else |
334 process.SetProcessBackgrounded(true); | 333 process.SetProcessBackgrounded(true); |
335 process.SetProcessBackgrounded(false); | 334 process.SetProcessBackgrounded(false); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 ASSERT_TRUE(base::GetAppOutput(other_cmd_line, &output)); | 385 ASSERT_TRUE(base::GetAppOutput(other_cmd_line, &output)); |
387 EXPECT_EQ("", output); | 386 EXPECT_EQ("", output); |
388 } | 387 } |
389 | 388 |
390 // TODO(estade): if possible, port this test. | 389 // TODO(estade): if possible, port this test. |
391 TEST_F(ProcessUtilTest, LaunchAsUser) { | 390 TEST_F(ProcessUtilTest, LaunchAsUser) { |
392 base::UserTokenHandle token; | 391 base::UserTokenHandle token; |
393 ASSERT_TRUE(OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &token)); | 392 ASSERT_TRUE(OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &token)); |
394 base::LaunchOptions options; | 393 base::LaunchOptions options; |
395 options.as_user = token; | 394 options.as_user = token; |
396 EXPECT_TRUE(base::LaunchProcess( | 395 EXPECT_TRUE(base::LaunchProcess(MakeCmdLine("SimpleChildProcess"), options, |
397 this->MakeCmdLine("SimpleChildProcess", false), options, NULL)); | 396 NULL)); |
398 } | 397 } |
399 | 398 |
400 static const char kEventToTriggerHandleSwitch[] = "event-to-trigger-handle"; | 399 static const char kEventToTriggerHandleSwitch[] = "event-to-trigger-handle"; |
401 | 400 |
402 MULTIPROCESS_TEST_MAIN(TriggerEventChildProcess) { | 401 MULTIPROCESS_TEST_MAIN(TriggerEventChildProcess) { |
403 std::string handle_value_string = | 402 std::string handle_value_string = |
404 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 403 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
405 kEventToTriggerHandleSwitch); | 404 kEventToTriggerHandleSwitch); |
406 CHECK(!handle_value_string.empty()); | 405 CHECK(!handle_value_string.empty()); |
407 | 406 |
(...skipping 15 matching lines...) Expand all Loading... |
423 security_attributes.bInheritHandle = true; | 422 security_attributes.bInheritHandle = true; |
424 | 423 |
425 // Takes ownership of the event handle. | 424 // Takes ownership of the event handle. |
426 base::WaitableEvent event( | 425 base::WaitableEvent event( |
427 CreateEvent(&security_attributes, true, false, NULL)); | 426 CreateEvent(&security_attributes, true, false, NULL)); |
428 base::HandlesToInheritVector handles_to_inherit; | 427 base::HandlesToInheritVector handles_to_inherit; |
429 handles_to_inherit.push_back(event.handle()); | 428 handles_to_inherit.push_back(event.handle()); |
430 base::LaunchOptions options; | 429 base::LaunchOptions options; |
431 options.handles_to_inherit = &handles_to_inherit; | 430 options.handles_to_inherit = &handles_to_inherit; |
432 | 431 |
433 CommandLine cmd_line = MakeCmdLine("TriggerEventChildProcess", false); | 432 CommandLine cmd_line = MakeCmdLine("TriggerEventChildProcess"); |
434 cmd_line.AppendSwitchASCII(kEventToTriggerHandleSwitch, | 433 cmd_line.AppendSwitchASCII(kEventToTriggerHandleSwitch, |
435 base::Uint64ToString(reinterpret_cast<uint64>(event.handle()))); | 434 base::Uint64ToString(reinterpret_cast<uint64>(event.handle()))); |
436 | 435 |
437 // This functionality actually requires Vista or later. Make sure that it | 436 // This functionality actually requires Vista or later. Make sure that it |
438 // fails properly on XP. | 437 // fails properly on XP. |
439 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 438 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
440 EXPECT_FALSE(base::LaunchProcess(cmd_line, options, NULL)); | 439 EXPECT_FALSE(base::LaunchProcess(cmd_line, options, NULL)); |
441 return; | 440 return; |
442 } | 441 } |
443 | 442 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 499 |
501 int ProcessUtilTest::CountOpenFDsInChild() { | 500 int ProcessUtilTest::CountOpenFDsInChild() { |
502 int fds[2]; | 501 int fds[2]; |
503 if (pipe(fds) < 0) | 502 if (pipe(fds) < 0) |
504 NOTREACHED(); | 503 NOTREACHED(); |
505 | 504 |
506 base::FileHandleMappingVector fd_mapping_vec; | 505 base::FileHandleMappingVector fd_mapping_vec; |
507 fd_mapping_vec.push_back(std::pair<int, int>(fds[1], kChildPipe)); | 506 fd_mapping_vec.push_back(std::pair<int, int>(fds[1], kChildPipe)); |
508 base::LaunchOptions options; | 507 base::LaunchOptions options; |
509 options.fds_to_remap = &fd_mapping_vec; | 508 options.fds_to_remap = &fd_mapping_vec; |
510 base::ProcessHandle handle = this->SpawnChildWithOptions( | 509 base::ProcessHandle handle = |
511 "ProcessUtilsLeakFDChildProcess", options, false); | 510 SpawnChildWithOptions("ProcessUtilsLeakFDChildProcess", options); |
512 CHECK(handle); | 511 CHECK(handle); |
513 int ret = IGNORE_EINTR(close(fds[1])); | 512 int ret = IGNORE_EINTR(close(fds[1])); |
514 DPCHECK(ret == 0); | 513 DPCHECK(ret == 0); |
515 | 514 |
516 // Read number of open files in client process from pipe; | 515 // Read number of open files in client process from pipe; |
517 int num_open_files = -1; | 516 int num_open_files = -1; |
518 ssize_t bytes_read = | 517 ssize_t bytes_read = |
519 HANDLE_EINTR(read(fds[0], &num_open_files, sizeof(num_open_files))); | 518 HANDLE_EINTR(read(fds[0], &num_open_files, sizeof(num_open_files))); |
520 CHECK_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files))); | 519 CHECK_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files))); |
521 | 520 |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 // TODO(port): port those unit tests. | 806 // TODO(port): port those unit tests. |
808 bool IsProcessDead(base::ProcessHandle child) { | 807 bool IsProcessDead(base::ProcessHandle child) { |
809 // waitpid() will actually reap the process which is exactly NOT what we | 808 // waitpid() will actually reap the process which is exactly NOT what we |
810 // want to test for. The good thing is that if it can't find the process | 809 // want to test for. The good thing is that if it can't find the process |
811 // we'll get a nice value for errno which we can test for. | 810 // we'll get a nice value for errno which we can test for. |
812 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); | 811 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); |
813 return result == -1 && errno == ECHILD; | 812 return result == -1 && errno == ECHILD; |
814 } | 813 } |
815 | 814 |
816 TEST_F(ProcessUtilTest, DelayedTermination) { | 815 TEST_F(ProcessUtilTest, DelayedTermination) { |
817 base::ProcessHandle child_process = | 816 base::ProcessHandle child_process = SpawnChild("process_util_test_never_die"); |
818 SpawnChild("process_util_test_never_die", false); | |
819 ASSERT_TRUE(child_process); | 817 ASSERT_TRUE(child_process); |
820 base::EnsureProcessTerminated(child_process); | 818 base::EnsureProcessTerminated(child_process); |
821 base::WaitForSingleProcess(child_process, base::TimeDelta::FromSeconds(5)); | 819 base::WaitForSingleProcess(child_process, base::TimeDelta::FromSeconds(5)); |
822 | 820 |
823 // Check that process was really killed. | 821 // Check that process was really killed. |
824 EXPECT_TRUE(IsProcessDead(child_process)); | 822 EXPECT_TRUE(IsProcessDead(child_process)); |
825 base::CloseProcessHandle(child_process); | 823 base::CloseProcessHandle(child_process); |
826 } | 824 } |
827 | 825 |
828 MULTIPROCESS_TEST_MAIN(process_util_test_never_die) { | 826 MULTIPROCESS_TEST_MAIN(process_util_test_never_die) { |
829 while (1) { | 827 while (1) { |
830 sleep(500); | 828 sleep(500); |
831 } | 829 } |
832 return 0; | 830 return 0; |
833 } | 831 } |
834 | 832 |
835 TEST_F(ProcessUtilTest, ImmediateTermination) { | 833 TEST_F(ProcessUtilTest, ImmediateTermination) { |
836 base::ProcessHandle child_process = | 834 base::ProcessHandle child_process = |
837 SpawnChild("process_util_test_die_immediately", false); | 835 SpawnChild("process_util_test_die_immediately"); |
838 ASSERT_TRUE(child_process); | 836 ASSERT_TRUE(child_process); |
839 // Give it time to die. | 837 // Give it time to die. |
840 sleep(2); | 838 sleep(2); |
841 base::EnsureProcessTerminated(child_process); | 839 base::EnsureProcessTerminated(child_process); |
842 | 840 |
843 // Check that process was really killed. | 841 // Check that process was really killed. |
844 EXPECT_TRUE(IsProcessDead(child_process)); | 842 EXPECT_TRUE(IsProcessDead(child_process)); |
845 base::CloseProcessHandle(child_process); | 843 base::CloseProcessHandle(child_process); |
846 } | 844 } |
847 | 845 |
848 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { | 846 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { |
849 return 0; | 847 return 0; |
850 } | 848 } |
851 | 849 |
852 #endif // defined(OS_POSIX) | 850 #endif // defined(OS_POSIX) |
OLD | NEW |