Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1855)

Unified Diff: base/process_util_unittest.cc

Issue 8674003: Move the ProcessWatcher methods out of content/common/process_watcher into base/process_util, alo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.

Powered by Google App Engine
This is Rietveld 408576698