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

Side by Side Diff: ipc/ipc_send_fds_test.cc

Issue 11819041: Make ipc_tests file structure a little saner and add an ipc_perftests target. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ugh Created 7 years, 11 months 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 | « ipc/ipc_perftests.cc ('k') | ipc/ipc_test_base.h » ('j') | 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) 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"
8
9 #if defined(OS_MACOSX) 7 #if defined(OS_MACOSX)
10 extern "C" { 8 extern "C" {
11 #include <sandbox.h> 9 #include <sandbox.h>
12 } 10 }
13 #endif 11 #endif
14 #include <fcntl.h> 12 #include <fcntl.h>
15 #include <sys/stat.h> 13 #include <sys/stat.h>
16 14
17 #include "base/message_loop.h" 15 #include "base/message_loop.h"
18 #include "base/posix/eintr_wrapper.h" 16 #include "base/posix/eintr_wrapper.h"
19 #include "ipc/ipc_channel.h" 17 #include "ipc/ipc_channel.h"
20 #include "ipc/ipc_listener.h" 18 #include "ipc/ipc_listener.h"
21 #include "ipc/ipc_message_utils.h" 19 #include "ipc/ipc_message_utils.h"
22 #include "ipc/ipc_multiprocess_test.h" 20 #include "ipc/ipc_multiprocess_test.h"
21 #include "ipc/ipc_test_base.h"
23 #include "testing/multiprocess_func_list.h" 22 #include "testing/multiprocess_func_list.h"
24 23
25 #if defined(OS_POSIX) 24 #if defined(OS_POSIX)
26 #include "base/file_descriptor_posix.h" 25 #include "base/file_descriptor_posix.h"
27 26
28 namespace { 27 namespace {
29 28
30 const unsigned kNumFDsToSend = 20; 29 const unsigned kNumFDsToSend = 20;
31 const char* kDevZeroPath = "/dev/zero"; 30 const char* kDevZeroPath = "/dev/zero";
32 31
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 124
126 // Verify that the message loop was exited due to getting the correct 125 // Verify that the message loop was exited due to getting the correct
127 // number of descriptors, and not because the channel closing unexpectedly. 126 // number of descriptors, and not because the channel closing unexpectedly.
128 CHECK(listener.GotExpectedNumberOfDescriptors()); 127 CHECK(listener.GotExpectedNumberOfDescriptors());
129 128
130 return 0; 129 return 0;
131 } 130 }
132 131
133 } // namespace 132 } // namespace
134 133
135 // --------------------------------------------------------------------------- 134 class IPCSendFdsTest : public IPCTestBase {
135 };
136
136 #if defined(OS_MACOSX) 137 #if defined(OS_MACOSX)
137 // TODO(port): Make this test cross-platform. 138 // TODO(port): Make this test cross-platform.
138 MULTIPROCESS_IPC_TEST_MAIN(RunTestDescriptorClientSandboxed) { 139 MULTIPROCESS_IPC_TEST_MAIN(RunTestDescriptorClientSandboxed) {
139 struct stat st; 140 struct stat st;
140 const int fd = open(kDevZeroPath, O_RDONLY); 141 const int fd = open(kDevZeroPath, O_RDONLY);
141 fstat(fd, &st); 142 fstat(fd, &st);
142 if (HANDLE_EINTR(close(fd)) < 0) { 143 if (HANDLE_EINTR(close(fd)) < 0) {
143 return -1; 144 return -1;
144 } 145 }
145 146
(...skipping 12 matching lines...) Expand all
158 if (open(kDevZeroPath, O_RDONLY) != -1) { 159 if (open(kDevZeroPath, O_RDONLY) != -1) {
159 LOG(ERROR) << "Sandbox wasn't properly enabled"; 160 LOG(ERROR) << "Sandbox wasn't properly enabled";
160 return -1; 161 return -1;
161 } 162 }
162 163
163 // See if we can receive a file descriptor. 164 // See if we can receive a file descriptor.
164 return TestDescriptorClient(st.st_ino); 165 return TestDescriptorClient(st.st_ino);
165 } 166 }
166 167
167 // Test that FDs are correctly sent to a sandboxed process. 168 // Test that FDs are correctly sent to a sandboxed process.
168 TEST_F(IPCChannelTest, DescriptorTestSandboxed) { 169 TEST_F(IPCSendFdsTest, DescriptorTestSandboxed) {
169 // Setup IPC channel. 170 // Setup IPC channel.
170 MyChannelDescriptorListener listener(-1); 171 MyChannelDescriptorListener listener(-1);
171 172
172 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER, 173 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER,
173 &listener); 174 &listener);
174 ASSERT_TRUE(chan.Connect()); 175 ASSERT_TRUE(chan.Connect());
175 176
176 base::ProcessHandle process_handle = SpawnChild( 177 base::ProcessHandle process_handle = SpawnChild(
177 TEST_DESCRIPTOR_CLIENT_SANDBOXED, 178 TEST_DESCRIPTOR_CLIENT_SANDBOXED,
178 &chan); 179 &chan);
179 TestDescriptorServer(chan, process_handle); 180 TestDescriptorServer(chan, process_handle);
180 } 181 }
181 #endif // defined(OS_MACOSX) 182 #endif // defined(OS_MACOSX)
182 183
183 MULTIPROCESS_IPC_TEST_MAIN(RunTestDescriptorClient) { 184 MULTIPROCESS_IPC_TEST_MAIN(RunTestDescriptorClient) {
184 struct stat st; 185 struct stat st;
185 const int fd = open(kDevZeroPath, O_RDONLY); 186 const int fd = open(kDevZeroPath, O_RDONLY);
186 fstat(fd, &st); 187 fstat(fd, &st);
187 EXPECT_GE(HANDLE_EINTR(close(fd)), 0); 188 EXPECT_GE(HANDLE_EINTR(close(fd)), 0);
188 189
189 return TestDescriptorClient(st.st_ino); 190 return TestDescriptorClient(st.st_ino);
190 } 191 }
191 192
192 TEST_F(IPCChannelTest, DescriptorTest) { 193 TEST_F(IPCSendFdsTest, DescriptorTest) {
193 // Setup IPC channel. 194 // Setup IPC channel.
194 MyChannelDescriptorListener listener(-1); 195 MyChannelDescriptorListener listener(-1);
195 196
196 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER, 197 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER,
197 &listener); 198 &listener);
198 ASSERT_TRUE(chan.Connect()); 199 ASSERT_TRUE(chan.Connect());
199 200
200 base::ProcessHandle process_handle = SpawnChild(TEST_DESCRIPTOR_CLIENT, 201 base::ProcessHandle process_handle = SpawnChild(TEST_DESCRIPTOR_CLIENT,
201 &chan); 202 &chan);
202 TestDescriptorServer(chan, process_handle); 203 TestDescriptorServer(chan, process_handle);
203 } 204 }
204 205
205 #endif // defined(OS_POSIX) 206 #endif // defined(OS_POSIX)
OLDNEW
« no previous file with comments | « ipc/ipc_perftests.cc ('k') | ipc/ipc_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698