diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/process_util.cc | 4 | ||||
-rw-r--r-- | base/process_util.h | 4 | ||||
-rw-r--r-- | base/process_util_unittest.cc | 35 |
3 files changed, 26 insertions, 17 deletions
diff --git a/base/process_util.cc b/base/process_util.cc index 8814956..f6e0d84 100644 --- a/base/process_util.cc +++ b/base/process_util.cc @@ -43,8 +43,8 @@ bool ProcessIterator::IncludeEntry() { return !filter_ || filter_->Includes(entry_); } -std::list<ProcessEntry> ProcessIterator::Snapshot() { - std::list<ProcessEntry> found; +ProcessIterator::ProcessEntries ProcessIterator::Snapshot() { + ProcessEntries found; while (const ProcessEntry* process_entry = NextProcessEntry()) { found.push_back(*process_entry); } diff --git a/base/process_util.h b/base/process_util.h index d6aed0d..9a28282 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -327,6 +327,8 @@ bool CleanupProcesses(const std::wstring& executable_name, // false. class ProcessIterator { public: + typedef std::list<ProcessEntry> ProcessEntries; + explicit ProcessIterator(const ProcessFilter* filter); virtual ~ProcessIterator(); @@ -338,7 +340,7 @@ class ProcessIterator { const ProcessEntry* NextProcessEntry(); // Takes a snapshot of all the ProcessEntry found. - std::list<ProcessEntry> Snapshot(); + ProcessEntries Snapshot(); protected: virtual bool IncludeEntry(); diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index 15405f4..4a42342 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -42,6 +42,22 @@ const wchar_t* const kProcessName = L"base_unittests.exe"; const wchar_t* const kProcessName = L"base_unittests"; #endif // defined(OS_WIN) +// Sleeps until file filename is created. +void WaitToDie(const char* filename) { + FILE *fp; + do { + PlatformThread::Sleep(10); + fp = fopen(filename, "r"); + } while (!fp); + fclose(fp); +} + +// Signals children they should die now. +void SignalChildren(const char* filename) { + FILE *fp = fopen(filename, "w"); + fclose(fp); +} + } // namespace class ProcessUtilTest : public MultiProcessTest { @@ -58,22 +74,13 @@ MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { TEST_F(ProcessUtilTest, SpawnChild) { base::ProcessHandle handle = this->SpawnChild(L"SimpleChildProcess"); - ASSERT_NE(base::kNullProcessHandle, handle); EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); base::CloseProcessHandle(handle); } 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); + WaitToDie("SlowChildProcess.die"); return 0; } @@ -81,10 +88,10 @@ TEST_F(ProcessUtilTest, KillSlowChild) { remove("SlowChildProcess.die"); base::ProcessHandle handle = this->SpawnChild(L"SlowChildProcess"); ASSERT_NE(base::kNullProcessHandle, handle); - FILE *fp = fopen("SlowChildProcess.die", "w"); - fclose(fp); + SignalChildren("SlowChildProcess.die"); EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); base::CloseProcessHandle(handle); + remove("SlowChildProcess.die"); } TEST_F(ProcessUtilTest, DidProcessCrash) { @@ -96,12 +103,12 @@ TEST_F(ProcessUtilTest, DidProcessCrash) { EXPECT_FALSE(base::DidProcessCrash(&child_exited, handle)); EXPECT_FALSE(child_exited); - FILE *fp = fopen("SlowChildProcess.die", "w"); - fclose(fp); + SignalChildren("SlowChildProcess.die"); EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); EXPECT_FALSE(base::DidProcessCrash(&child_exited, handle)); base::CloseProcessHandle(handle); + remove("SlowChildProcess.die"); } // Ensure that the priority of a process is restored correctly after |