OLD | NEW |
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/platform_thread.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { | 28 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { |
29 return 0; | 29 return 0; |
30 } | 30 } |
31 | 31 |
32 TEST_F(ProcessUtilTest, SpawnChild) { | 32 TEST_F(ProcessUtilTest, SpawnChild) { |
33 ProcessHandle handle = this->SpawnChild(L"SimpleChildProcess"); | 33 ProcessHandle handle = this->SpawnChild(L"SimpleChildProcess"); |
34 | 34 |
35 ASSERT_NE(static_cast<ProcessHandle>(NULL), handle); | 35 ASSERT_NE(static_cast<ProcessHandle>(NULL), handle); |
36 EXPECT_TRUE(WaitForSingleProcess(handle, 5000)); | 36 EXPECT_TRUE(WaitForSingleProcess(handle, 5000)); |
| 37 base::CloseProcessHandle(handle); |
37 } | 38 } |
38 | 39 |
39 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { | 40 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { |
40 // Sleep until file "SlowChildProcess.die" is created. | 41 // Sleep until file "SlowChildProcess.die" is created. |
41 FILE *fp; | 42 FILE *fp; |
42 do { | 43 do { |
43 PlatformThread::Sleep(100); | 44 PlatformThread::Sleep(100); |
44 fp = fopen("SlowChildProcess.die", "r"); | 45 fp = fopen("SlowChildProcess.die", "r"); |
45 } while (!fp); | 46 } while (!fp); |
46 fclose(fp); | 47 fclose(fp); |
(...skipping 11 matching lines...) Expand all Loading... |
58 TEST_F(ProcessUtilTest, KillSlowChild) { | 59 TEST_F(ProcessUtilTest, KillSlowChild) { |
59 remove("SlowChildProcess.die"); | 60 remove("SlowChildProcess.die"); |
60 int oldcount = GetProcessCount(L"base_unittests" EXE_SUFFIX, 0); | 61 int oldcount = GetProcessCount(L"base_unittests" EXE_SUFFIX, 0); |
61 ProcessHandle handle = this->SpawnChild(L"SlowChildProcess"); | 62 ProcessHandle handle = this->SpawnChild(L"SlowChildProcess"); |
62 ASSERT_NE(static_cast<ProcessHandle>(NULL), handle); | 63 ASSERT_NE(static_cast<ProcessHandle>(NULL), handle); |
63 EXPECT_EQ(oldcount+1, GetProcessCount(L"base_unittests" EXE_SUFFIX, 0)); | 64 EXPECT_EQ(oldcount+1, GetProcessCount(L"base_unittests" EXE_SUFFIX, 0)); |
64 FILE *fp = fopen("SlowChildProcess.die", "w"); | 65 FILE *fp = fopen("SlowChildProcess.die", "w"); |
65 fclose(fp); | 66 fclose(fp); |
66 EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); | 67 EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); |
67 EXPECT_EQ(oldcount, GetProcessCount(L"base_unittests" EXE_SUFFIX, 0)); | 68 EXPECT_EQ(oldcount, GetProcessCount(L"base_unittests" EXE_SUFFIX, 0)); |
| 69 base::CloseProcessHandle(handle); |
68 } | 70 } |
69 | 71 |
70 // TODO(estade): if possible, port these 2 tests. | 72 // TODO(estade): if possible, port these 2 tests. |
71 #if defined(OS_WIN) | 73 #if defined(OS_WIN) |
72 TEST_F(ProcessUtilTest, EnableLFH) { | 74 TEST_F(ProcessUtilTest, EnableLFH) { |
73 ASSERT_TRUE(EnableLowFragmentationHeap()); | 75 ASSERT_TRUE(EnableLowFragmentationHeap()); |
74 if (IsDebuggerPresent()) { | 76 if (IsDebuggerPresent()) { |
75 // Under these conditions, LFH can't be enabled. There's no point to test | 77 // Under these conditions, LFH can't be enabled. There's no point to test |
76 // anything. | 78 // anything. |
77 const char* no_debug_env = getenv("_NO_DEBUG_HEAP"); | 79 const char* no_debug_env = getenv("_NO_DEBUG_HEAP"); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // Read number of open files in client process from pipe; | 211 // Read number of open files in client process from pipe; |
210 int num_open_files = -1; | 212 int num_open_files = -1; |
211 ssize_t bytes_read = read(pipe_read_fd, &num_open_files, | 213 ssize_t bytes_read = read(pipe_read_fd, &num_open_files, |
212 sizeof(num_open_files)); | 214 sizeof(num_open_files)); |
213 ASSERT_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files))); | 215 ASSERT_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files))); |
214 | 216 |
215 // Make sure 0 fds are leaked to the client. | 217 // Make sure 0 fds are leaked to the client. |
216 ASSERT_EQ(0, num_open_files); | 218 ASSERT_EQ(0, num_open_files); |
217 | 219 |
218 EXPECT_TRUE(WaitForSingleProcess(handle, 1000)); | 220 EXPECT_TRUE(WaitForSingleProcess(handle, 1000)); |
| 221 base::CloseProcessHandle(handle); |
219 close(fds[0]); | 222 close(fds[0]); |
220 close(sockets[0]); | 223 close(sockets[0]); |
221 close(sockets[1]); | 224 close(sockets[1]); |
222 close(dev_null); | 225 close(dev_null); |
223 } | 226 } |
224 | 227 |
225 #endif // defined(OS_POSIX) | 228 #endif // defined(OS_POSIX) |
226 | 229 |
227 } // namespace base | 230 } // namespace base |
OLD | NEW |