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

Unified Diff: chrome/common/process_watcher_unittest.cc

Issue 496007: Make ProcessWatcher use kqueues on Mac. (Closed)
Patch Set: No need for a thread Created 11 years 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
« no previous file with comments | « chrome/common/process_watcher_posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/process_watcher_unittest.cc
diff --git a/chrome/common/process_watcher_unittest.cc b/chrome/common/process_watcher_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..505a468770ce927602aedf73d9b9b3ad768db2ee
--- /dev/null
+++ b/chrome/common/process_watcher_unittest.cc
@@ -0,0 +1,48 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/process_watcher.h"
+
+#if defined(OS_POSIX)
+#include <sys/wait.h>
+
+#include "base/eintr_wrapper.h"
+#include "base/multiprocess_test.h"
+#include "base/process_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class ProcessWatcherTest : public MultiProcessTest {
+};
+
+namespace {
+
+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;
+}
+
+} // namespace
+
+TEST_F(ProcessWatcherTest, DelayedTermination) {
+ base::ProcessHandle child_process =
+ SpawnChild(L"process_watcher_test_never_die");
+ ProcessWatcher::EnsureProcessTerminated(child_process);
+ base::WaitForSingleProcess(child_process, 5000);
+
+ // Check that process was really killed.
+ EXPECT_TRUE(IsProcessDead(child_process));
+ base::CloseProcessHandle(child_process);
+}
+
+MULTIPROCESS_TEST_MAIN(process_watcher_test_never_die) {
+ while(1){
+ sleep(500);
+ }
+ return 0;
+}
+
+#endif // OS_POSIX
« no previous file with comments | « chrome/common/process_watcher_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698