OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/common/process_watcher.h" | 5 #include "content/common/process_watcher.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <sys/wait.h> | 8 #include <sys/wait.h> |
9 | 9 |
10 #include "base/eintr_wrapper.h" | 10 #include "base/eintr_wrapper.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 // we'll get a nice value for errno which we can test for. | 24 // we'll get a nice value for errno which we can test for. |
25 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); | 25 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); |
26 return result == -1 && errno == ECHILD; | 26 return result == -1 && errno == ECHILD; |
27 } | 27 } |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 TEST_F(ProcessWatcherTest, DelayedTermination) { | 31 TEST_F(ProcessWatcherTest, DelayedTermination) { |
32 base::ProcessHandle child_process = | 32 base::ProcessHandle child_process = |
33 SpawnChild("process_watcher_test_never_die", false); | 33 SpawnChild("process_watcher_test_never_die", false); |
| 34 ASSERT_TRUE(child_process); |
34 ProcessWatcher::EnsureProcessTerminated(child_process); | 35 ProcessWatcher::EnsureProcessTerminated(child_process); |
35 base::WaitForSingleProcess(child_process, 5000); | 36 base::WaitForSingleProcess(child_process, 5000); |
36 | 37 |
37 // Check that process was really killed. | 38 // Check that process was really killed. |
38 EXPECT_TRUE(IsProcessDead(child_process)); | 39 EXPECT_TRUE(IsProcessDead(child_process)); |
39 base::CloseProcessHandle(child_process); | 40 base::CloseProcessHandle(child_process); |
40 } | 41 } |
41 | 42 |
42 MULTIPROCESS_TEST_MAIN(process_watcher_test_never_die) { | 43 MULTIPROCESS_TEST_MAIN(process_watcher_test_never_die) { |
43 while (1) { | 44 while (1) { |
44 sleep(500); | 45 sleep(500); |
45 } | 46 } |
46 return 0; | 47 return 0; |
47 } | 48 } |
48 | 49 |
49 TEST_F(ProcessWatcherTest, ImmediateTermination) { | 50 TEST_F(ProcessWatcherTest, ImmediateTermination) { |
50 base::ProcessHandle child_process = | 51 base::ProcessHandle child_process = |
51 SpawnChild("process_watcher_test_die_immediately", false); | 52 SpawnChild("process_watcher_test_die_immediately", false); |
| 53 ASSERT_TRUE(child_process); |
52 // Give it time to die. | 54 // Give it time to die. |
53 sleep(2); | 55 sleep(2); |
54 ProcessWatcher::EnsureProcessTerminated(child_process); | 56 ProcessWatcher::EnsureProcessTerminated(child_process); |
55 | 57 |
56 // Check that process was really killed. | 58 // Check that process was really killed. |
57 EXPECT_TRUE(IsProcessDead(child_process)); | 59 EXPECT_TRUE(IsProcessDead(child_process)); |
58 base::CloseProcessHandle(child_process); | 60 base::CloseProcessHandle(child_process); |
59 } | 61 } |
60 | 62 |
61 MULTIPROCESS_TEST_MAIN(process_watcher_test_die_immediately) { | 63 MULTIPROCESS_TEST_MAIN(process_watcher_test_die_immediately) { |
62 return 0; | 64 return 0; |
63 } | 65 } |
64 | 66 |
65 #endif // OS_POSIX | 67 #endif // OS_POSIX |
OLD | NEW |