summaryrefslogtreecommitdiffstats
path: root/base/process_util_unittest.cc
diff options
context:
space:
mode:
authordkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 20:19:43 +0000
committerdkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 20:19:43 +0000
commitab0e2220a2038f42c47ce6cf68691cc0e24b3eb0 (patch)
treecf5e39e527fd11e4f3b7131f58c8a31f0656773d /base/process_util_unittest.cc
parentb44ff1e7456978b4e8cfcd3f61932e96bcbca2be (diff)
downloadchromium_src-ab0e2220a2038f42c47ce6cf68691cc0e24b3eb0.zip
chromium_src-ab0e2220a2038f42c47ce6cf68691cc0e24b3eb0.tar.gz
chromium_src-ab0e2220a2038f42c47ce6cf68691cc0e24b3eb0.tar.bz2
Port GetProcessCount(), KillProcesses(), and CleanupProcesses().
Also switch to fork() from vfork(), since strace on my box doesn't support vfork! It's deprecated, anyway. Review URL: http://codereview.chromium.org/8880 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4315 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r--base/process_util_unittest.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc
index 261eb46..1ba0ee2 100644
--- a/base/process_util_unittest.cc
+++ b/base/process_util_unittest.cc
@@ -5,6 +5,7 @@
#define _CRT_SECURE_NO_WARNINGS
#include "base/multiprocess_test.h"
+#include "base/platform_thread.h"
#include "base/process_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -29,6 +30,46 @@ TEST_F(ProcessUtilTest, SpawnChild) {
EXPECT_TRUE(process_util::WaitForSingleProcess(handle, 1000));
}
+MULTIPROCESS_TEST_MAIN(SlowChildProcess) {
+ // Sleep until file "SlowChildProcess.die" is created.
+ FILE *fp;
+ do {
+ PlatformThread::Sleep(100);
+ fp = fopen("SlowChildProcess.die", "r");
+ } while (!fp);
+ fclose(fp);
+ remove("SlowChildProcess.die");
+ exit(0);
+ return 0;
+}
+
+#if defined(OS_WIN)
+#define EXE_SUFFIX ".exe"
+#else
+#define EXE_SUFFIX ""
+#endif
+
+// TODO(port): finish port on Mac
+#if defined(OS_MACOSX)
+TEST_F(ProcessUtilTest, DISABLED_KillSlowChild)
+#else
+TEST_F(ProcessUtilTest, KillSlowChild)
+#endif
+{
+ remove("SlowChildProcess.die");
+ int oldcount = process_util::GetProcessCount(L"base_unittests" EXE_SUFFIX, 0);
+
+ ProcessHandle handle = this->SpawnChild(L"SlowChildProcess");
+
+ ASSERT_NE(static_cast<ProcessHandle>(NULL), handle);
+ EXPECT_EQ(oldcount+1, process_util::GetProcessCount(L"base_unittests" EXE_SUFFIX, 0));
+ FILE *fp = fopen("SlowChildProcess.die", "w");
+ fclose(fp);
+ // TODO(port): do something less racy here
+ PlatformThread::Sleep(1000);
+ EXPECT_EQ(oldcount, process_util::GetProcessCount(L"base_unittests" EXE_SUFFIX, 0));
+}
+
// TODO(estade): if possible, port these 2 tests.
#if defined(OS_WIN)
TEST_F(ProcessUtilTest, EnableLFH) {