diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-25 01:14:36 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-25 01:14:36 +0000 |
commit | ce4f3bda0b09ed2cfd4773d493aeb432428a4cfc (patch) | |
tree | 01bce3d6d6590b967146b011c50b5763defc7ae6 /base/process_util_unittest.cc | |
parent | d07f31723cd037a8c6bef60b234fdb4ad746f34a (diff) | |
download | chromium_src-ce4f3bda0b09ed2cfd4773d493aeb432428a4cfc.zip chromium_src-ce4f3bda0b09ed2cfd4773d493aeb432428a4cfc.tar.gz chromium_src-ce4f3bda0b09ed2cfd4773d493aeb432428a4cfc.tar.bz2 |
Revert "linux: call g_thread_init() at relevant startup points"
This reverts commit r24203, Mac breakage.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24204 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r-- | base/process_util_unittest.cc | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index 23e33ee..7b30be6 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -27,11 +27,6 @@ namespace base { class ProcessUtilTest : public MultiProcessTest { -#if defined(OS_POSIX) - public: - // Spawn a child process that counts how many file descriptors are open. - int CountOpenFDsInChild(); -#endif }; MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { @@ -205,6 +200,14 @@ MULTIPROCESS_TEST_MAIN(ProcessUtilsLeakFDChildProcess) { } } + // InitLogging always opens a file at startup. + int expected_num_open_fds = 1; +#if defined(OS_LINUX) + // On Linux, '/etc/localtime' is opened before the test's main() enters. + expected_num_open_fds += 1; +#endif // defined(OS_LINUX) + num_open_files -= expected_num_open_fds; + int written = HANDLE_EINTR(write(write_pipe, &num_open_files, sizeof(num_open_files))); DCHECK_EQ(static_cast<size_t>(written), sizeof(num_open_files)); @@ -213,45 +216,40 @@ MULTIPROCESS_TEST_MAIN(ProcessUtilsLeakFDChildProcess) { return 0; } -int ProcessUtilTest::CountOpenFDsInChild() { +TEST_F(ProcessUtilTest, FDRemapping) { + // Open some files to check they don't get leaked to the child process. int fds[2]; if (pipe(fds) < 0) NOTREACHED(); + int pipe_read_fd = fds[0]; + int pipe_write_fd = fds[1]; + + // open some dummy fds to make sure they don't propogate over to the + // child process. + int dev_null = open("/dev/null", O_RDONLY); + int sockets[2]; + socketpair(AF_UNIX, SOCK_STREAM, 0, sockets); file_handle_mapping_vector fd_mapping_vec; - fd_mapping_vec.push_back(std::pair<int,int>(fds[1], kChildPipe)); + fd_mapping_vec.push_back(std::pair<int,int>(pipe_write_fd, kChildPipe)); ProcessHandle handle = this->SpawnChild(L"ProcessUtilsLeakFDChildProcess", fd_mapping_vec, false); - CHECK(static_cast<ProcessHandle>(NULL) != handle); - HANDLE_EINTR(close(fds[1])); + ASSERT_NE(static_cast<ProcessHandle>(NULL), handle); + HANDLE_EINTR(close(pipe_write_fd)); // Read number of open files in client process from pipe; int num_open_files = -1; ssize_t bytes_read = - HANDLE_EINTR(read(fds[0], &num_open_files, sizeof(num_open_files))); - CHECK(bytes_read == static_cast<ssize_t>(sizeof(num_open_files))); + HANDLE_EINTR(read(pipe_read_fd, &num_open_files, sizeof(num_open_files))); + ASSERT_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files))); + + // Make sure 0 fds are leaked to the client. + ASSERT_EQ(0, num_open_files); - CHECK(WaitForSingleProcess(handle, 1000)); + EXPECT_TRUE(WaitForSingleProcess(handle, 1000)); base::CloseProcessHandle(handle); HANDLE_EINTR(close(fds[0])); - - return num_open_files; -} - -TEST_F(ProcessUtilTest, FDRemapping) { - int fds_before = CountOpenFDsInChild(); - - // open some dummy fds to make sure they don't propogate over to the - // child process. - int dev_null = open("/dev/null", O_RDONLY); - int sockets[2]; - socketpair(AF_UNIX, SOCK_STREAM, 0, sockets); - - int fds_after = CountOpenFDsInChild(); - - ASSERT_EQ(fds_after, fds_before); - HANDLE_EINTR(close(sockets[0])); HANDLE_EINTR(close(sockets[1])); HANDLE_EINTR(close(dev_null)); |