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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 int max_files = GetMaxFilesOpenInProcess(); | 152 int max_files = GetMaxFilesOpenInProcess(); |
153 for (int i = STDERR_FILENO + 1; i < max_files; i++) { | 153 for (int i = STDERR_FILENO + 1; i < max_files; i++) { |
154 if (i != kChildPipe) { | 154 if (i != kChildPipe) { |
155 if (close(i) != -1) { | 155 if (close(i) != -1) { |
156 LOG(WARNING) << "Leaked FD " << i; | 156 LOG(WARNING) << "Leaked FD " << i; |
157 num_open_files += 1; | 157 num_open_files += 1; |
158 } | 158 } |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
| 162 // InitLogging always opens a file at startup. |
| 163 int expected_num_open_fds = 1; |
162 #if defined(OS_LINUX) | 164 #if defined(OS_LINUX) |
163 // On Linux, '/etc/localtime' is opened before the test's main() enters. | 165 // On Linux, '/etc/localtime' is opened before the test's main() enters. |
164 const int expected_num_open_fds = 1; | 166 expected_num_open_fds += 1; |
| 167 #endif // defined(OS_LINUX) |
165 num_open_files -= expected_num_open_fds; | 168 num_open_files -= expected_num_open_fds; |
166 #endif // defined(OS_LINUX) | |
167 | 169 |
168 write(write_pipe, &num_open_files, sizeof(num_open_files)); | 170 write(write_pipe, &num_open_files, sizeof(num_open_files)); |
169 close(write_pipe); | 171 close(write_pipe); |
170 | 172 |
171 return 0; | 173 return 0; |
172 } | 174 } |
173 | 175 |
174 TEST_F(ProcessUtilTest, FDRemapping) { | 176 TEST_F(ProcessUtilTest, FDRemapping) { |
175 // Open some files to check they don't get leaked to the child process. | 177 // Open some files to check they don't get leaked to the child process. |
176 int fds[2]; | 178 int fds[2]; |
(...skipping 27 matching lines...) Expand all Loading... |
204 EXPECT_TRUE(WaitForSingleProcess(handle, 1000)); | 206 EXPECT_TRUE(WaitForSingleProcess(handle, 1000)); |
205 close(fds[0]); | 207 close(fds[0]); |
206 close(sockets[0]); | 208 close(sockets[0]); |
207 close(sockets[1]); | 209 close(sockets[1]); |
208 close(dev_null); | 210 close(dev_null); |
209 } | 211 } |
210 | 212 |
211 #endif // defined(OS_POSIX) | 213 #endif // defined(OS_POSIX) |
212 | 214 |
213 } // namespace base | 215 } // namespace base |
OLD | NEW |