From ab0e2220a2038f42c47ce6cf68691cc0e24b3eb0 Mon Sep 17 00:00:00 2001 From: "dkegel@google.com" Date: Fri, 31 Oct 2008 20:19:43 +0000 Subject: 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 --- base/process_util_unittest.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'base/process_util_unittest.cc') 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(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) { -- cgit v1.1