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

Side by Side Diff: base/process_util_unittest.cc

Issue 8880: Port GetProcessCount(), KillProcesses(), and CleanupProcesses().... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/process_util_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #define _CRT_SECURE_NO_WARNINGS 5 #define _CRT_SECURE_NO_WARNINGS
6 6
7 #include "base/multiprocess_test.h" 7 #include "base/multiprocess_test.h"
8 #include "base/platform_thread.h"
8 #include "base/process_util.h" 9 #include "base/process_util.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 #if defined(OS_WIN) 12 #if defined(OS_WIN)
12 #include <windows.h> 13 #include <windows.h>
13 #elif defined(OS_LINUX) 14 #elif defined(OS_LINUX)
14 #include <dlfcn.h> 15 #include <dlfcn.h>
15 #endif 16 #endif
16 17
17 namespace { 18 namespace {
18 class ProcessUtilTest : public MultiProcessTest { 19 class ProcessUtilTest : public MultiProcessTest {
19 }; 20 };
20 21
21 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { 22 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) {
22 return 0; 23 return 0;
23 } 24 }
24 25
25 TEST_F(ProcessUtilTest, SpawnChild) { 26 TEST_F(ProcessUtilTest, SpawnChild) {
26 ProcessHandle handle = this->SpawnChild(L"SimpleChildProcess"); 27 ProcessHandle handle = this->SpawnChild(L"SimpleChildProcess");
27 28
28 ASSERT_NE(static_cast<ProcessHandle>(NULL), handle); 29 ASSERT_NE(static_cast<ProcessHandle>(NULL), handle);
29 EXPECT_TRUE(process_util::WaitForSingleProcess(handle, 1000)); 30 EXPECT_TRUE(process_util::WaitForSingleProcess(handle, 1000));
30 } 31 }
31 32
33 MULTIPROCESS_TEST_MAIN(SlowChildProcess) {
34 // Sleep until file "SlowChildProcess.die" is created.
35 FILE *fp;
36 do {
37 PlatformThread::Sleep(100);
38 fp = fopen("SlowChildProcess.die", "r");
39 } while (!fp);
40 fclose(fp);
41 remove("SlowChildProcess.die");
42 exit(0);
43 return 0;
44 }
45
46 #if defined(OS_WIN)
47 #define EXE_SUFFIX ".exe"
48 #else
49 #define EXE_SUFFIX ""
50 #endif
51
52 TEST_F(ProcessUtilTest, KillSlowChild) {
53 remove("SlowChildProcess.die");
54 int oldcount = process_util::GetProcessCount(L"base_unittests" EXE_SUFFIX, 0);
55
56 ProcessHandle handle = this->SpawnChild(L"SlowChildProcess");
57
58 ASSERT_NE(static_cast<ProcessHandle>(NULL), handle);
59 EXPECT_EQ(oldcount+1, process_util::GetProcessCount(L"base_unittests" EXE_SUFF IX, 0));
60 FILE *fp = fopen("SlowChildProcess.die", "w");
61 fclose(fp);
62 // TODO(port): do something less racy here
63 PlatformThread::Sleep(1000);
64 EXPECT_EQ(oldcount, process_util::GetProcessCount(L"base_unittests" EXE_SUFFIX , 0));
65 }
66
32 // TODO(estade): if possible, port these 2 tests. 67 // TODO(estade): if possible, port these 2 tests.
33 #if defined(OS_WIN) 68 #if defined(OS_WIN)
34 TEST_F(ProcessUtilTest, EnableLFH) { 69 TEST_F(ProcessUtilTest, EnableLFH) {
35 ASSERT_TRUE(process_util::EnableLowFragmentationHeap()); 70 ASSERT_TRUE(process_util::EnableLowFragmentationHeap());
36 if (IsDebuggerPresent()) { 71 if (IsDebuggerPresent()) {
37 // Under these conditions, LFH can't be enabled. There's no point to test 72 // Under these conditions, LFH can't be enabled. There's no point to test
38 // anything. 73 // anything.
39 const char* no_debug_env = getenv("_NO_DEBUG_HEAP"); 74 const char* no_debug_env = getenv("_NO_DEBUG_HEAP");
40 if (!no_debug_env || strcmp(no_debug_env, "1")) 75 if (!no_debug_env || strcmp(no_debug_env, "1"))
41 return; 76 return;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 EXPECT_GE(expected_total, free_mem2.total); 127 EXPECT_GE(expected_total, free_mem2.total);
93 EXPECT_GE(expected_largest, free_mem2.largest); 128 EXPECT_GE(expected_largest, free_mem2.largest);
94 EXPECT_TRUE(NULL != free_mem2.largest_ptr); 129 EXPECT_TRUE(NULL != free_mem2.largest_ptr);
95 130
96 delete[] alloc; 131 delete[] alloc;
97 delete metrics; 132 delete metrics;
98 } 133 }
99 #endif // defined(OS_WIN) 134 #endif // defined(OS_WIN)
100 135
101 } // namespace 136 } // namespace
OLDNEW
« no previous file with comments | « base/process_util_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698