Index: base/process_util_unittest.cc |
=================================================================== |
--- base/process_util_unittest.cc (revision 111236) |
+++ base/process_util_unittest.cc (working copy) |
@@ -833,6 +833,51 @@ |
} |
#endif // defined(OS_LINUX) || defined(OS_ANDROID) |
+// TODO(port): port those unit tests. |
+bool IsProcessDead(base::ProcessHandle child) { |
+ // waitpid() will actually reap the process which is exactly NOT what we |
+ // want to test for. The good thing is that if it can't find the process |
+ // we'll get a nice value for errno which we can test for. |
+ const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); |
+ return result == -1 && errno == ECHILD; |
+} |
+ |
+TEST_F(ProcessUtilTest, DelayedTermination) { |
+ base::ProcessHandle child_process = |
+ SpawnChild("process_util_test_never_die", false); |
+ ASSERT_TRUE(child_process); |
+ base::EnsureProcessTerminated(child_process); |
+ base::WaitForSingleProcess(child_process, 5000); |
cpu_(ooo_6.6-7.5)
2011/11/24 00:22:07
the problem here is that EnsureProcessTerminated c
|
+ |
+ // Check that process was really killed. |
+ EXPECT_TRUE(IsProcessDead(child_process)); |
+ base::CloseProcessHandle(child_process); |
+} |
+ |
+MULTIPROCESS_TEST_MAIN(process_util_test_never_die) { |
+ while (1) { |
+ sleep(500); |
+ } |
+ return 0; |
+} |
+ |
+TEST_F(ProcessUtilTest, ImmediateTermination) { |
+ base::ProcessHandle child_process = |
+ SpawnChild("process_util_test_die_immediately", false); |
+ ASSERT_TRUE(child_process); |
+ // Give it time to die. |
+ sleep(2); |
+ base::EnsureProcessTerminated(child_process); |
+ |
+ // Check that process was really killed. |
+ EXPECT_TRUE(IsProcessDead(child_process)); |
+ base::CloseProcessHandle(child_process); |
+} |
+ |
+MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { |
+ return 0; |
+} |
+ |
#endif // defined(OS_POSIX) |
// TODO(vandebo) make this work on Windows too. |