| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "ipc/ipc_tests.h" | 7 #include "ipc/ipc_tests.h" |
| 8 | 8 |
| 9 #if defined(OS_MACOSX) | 9 #if defined(OS_MACOSX) |
| 10 extern "C" { | 10 extern "C" { |
| 11 #include <sandbox.h> | 11 #include <sandbox.h> |
| 12 } | 12 } |
| 13 #endif | 13 #endif |
| 14 #include <fcntl.h> | 14 #include <fcntl.h> |
| 15 #include <sys/stat.h> | 15 #include <sys/stat.h> |
| 16 | 16 |
| 17 #include "base/eintr_wrapper.h" | 17 #include "base/eintr_wrapper.h" |
| 18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "ipc/ipc_channel.h" | 19 #include "ipc/ipc_channel.h" |
| 20 #include "ipc/ipc_message_utils.h" | 20 #include "ipc/ipc_message_utils.h" |
| 21 #include "testing/multiprocess_func_list.h" | 21 #include "testing/multiprocess_func_list.h" |
| 22 | 22 |
| 23 #if defined(OS_POSIX) | 23 #if defined(OS_POSIX) |
| 24 #include "base/file_descriptor_posix.h" | 24 #include "base/file_descriptor_posix.h" |
| 25 #include "base/global_descriptors_posix.h" |
| 26 #include "ipc/ipc_descriptors.h" |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 const unsigned kNumFDsToSend = 20; | 30 const unsigned kNumFDsToSend = 20; |
| 29 const char* kDevZeroPath = "/dev/zero"; | 31 const char* kDevZeroPath = "/dev/zero"; |
| 30 | 32 |
| 31 static void VerifyAndCloseDescriptor(int fd, ino_t inode_num) { | 33 static void VerifyAndCloseDescriptor(int fd, ino_t inode_num) { |
| 32 // Check that we can read from the FD. | 34 // Check that we can read from the FD. |
| 33 char buf; | 35 char buf; |
| 34 ssize_t amt_read = read(fd, &buf, 1); | 36 ssize_t amt_read = read(fd, &buf, 1); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 CHECK(listener.GotExpectedNumberOfDescriptors()); | 127 CHECK(listener.GotExpectedNumberOfDescriptors()); |
| 126 | 128 |
| 127 return 0; | 129 return 0; |
| 128 } | 130 } |
| 129 | 131 |
| 130 } // namespace | 132 } // namespace |
| 131 | 133 |
| 132 // --------------------------------------------------------------------------- | 134 // --------------------------------------------------------------------------- |
| 133 #if defined(OS_MACOSX) | 135 #if defined(OS_MACOSX) |
| 134 // TODO(port): Make this test cross-platform. | 136 // TODO(port): Make this test cross-platform. |
| 135 MULTIPROCESS_TEST_MAIN(RunTestDescriptorClientSandboxed) { | 137 MULTIPROCESS_TEST_MAIN(RunTestDescriptorClientSandboxed, |
| 138 MultiProcessTestIPCSetUp) { |
| 136 struct stat st; | 139 struct stat st; |
| 137 const int fd = open(kDevZeroPath, O_RDONLY); | 140 const int fd = open(kDevZeroPath, O_RDONLY); |
| 138 fstat(fd, &st); | 141 fstat(fd, &st); |
| 139 if (HANDLE_EINTR(close(fd)) < 0) { | 142 if (HANDLE_EINTR(close(fd)) < 0) { |
| 140 return -1; | 143 return -1; |
| 141 } | 144 } |
| 142 | 145 |
| 143 // Enable the Sandbox. | 146 // Enable the Sandbox. |
| 144 char* error_buff = NULL; | 147 char* error_buff = NULL; |
| 145 int error = sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED, | 148 int error = sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 170 &listener); | 173 &listener); |
| 171 ASSERT_TRUE(chan.Connect()); | 174 ASSERT_TRUE(chan.Connect()); |
| 172 | 175 |
| 173 base::ProcessHandle process_handle = SpawnChild( | 176 base::ProcessHandle process_handle = SpawnChild( |
| 174 TEST_DESCRIPTOR_CLIENT_SANDBOXED, | 177 TEST_DESCRIPTOR_CLIENT_SANDBOXED, |
| 175 &chan); | 178 &chan); |
| 176 TestDescriptorServer(chan, process_handle); | 179 TestDescriptorServer(chan, process_handle); |
| 177 } | 180 } |
| 178 #endif // defined(OS_MACOSX) | 181 #endif // defined(OS_MACOSX) |
| 179 | 182 |
| 180 MULTIPROCESS_TEST_MAIN(RunTestDescriptorClient) { | 183 MULTIPROCESS_TEST_MAIN(RunTestDescriptorClient, MultiProcessTestIPCSetUp) { |
| 181 struct stat st; | 184 struct stat st; |
| 182 const int fd = open(kDevZeroPath, O_RDONLY); | 185 const int fd = open(kDevZeroPath, O_RDONLY); |
| 183 fstat(fd, &st); | 186 fstat(fd, &st); |
| 184 EXPECT_GE(HANDLE_EINTR(close(fd)), 0); | 187 EXPECT_GE(HANDLE_EINTR(close(fd)), 0); |
| 185 | 188 |
| 186 return TestDescriptorClient(st.st_ino); | 189 return TestDescriptorClient(st.st_ino); |
| 187 } | 190 } |
| 188 | 191 |
| 189 TEST_F(IPCChannelTest, DescriptorTest) { | 192 TEST_F(IPCChannelTest, DescriptorTest) { |
| 190 // Setup IPC channel. | 193 // Setup IPC channel. |
| 191 MyChannelDescriptorListener listener(-1); | 194 MyChannelDescriptorListener listener(-1); |
| 192 | 195 |
| 193 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER, | 196 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER, |
| 194 &listener); | 197 &listener); |
| 195 ASSERT_TRUE(chan.Connect()); | 198 ASSERT_TRUE(chan.Connect()); |
| 196 | 199 |
| 197 base::ProcessHandle process_handle = SpawnChild(TEST_DESCRIPTOR_CLIENT, | 200 base::ProcessHandle process_handle = SpawnChild(TEST_DESCRIPTOR_CLIENT, |
| 198 &chan); | 201 &chan); |
| 199 TestDescriptorServer(chan, process_handle); | 202 TestDescriptorServer(chan, process_handle); |
| 200 } | 203 } |
| 201 | 204 |
| 202 #endif // defined(OS_POSIX) | 205 #endif // defined(OS_POSIX) |
| OLD | NEW |