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

Side by Side Diff: mojo/system/remote_message_pipe_posix_unittest.cc

Issue 67413003: Mojo: Implement plumbing to support passing handles over MessagePipes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased & review comments Created 7 years, 1 month 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 | « mojo/system/message_pipe_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // TODO(vtl): Factor out the POSIX-specific bits of this test (once we have a 5 // TODO(vtl): Factor out the POSIX-specific bits of this test (once we have a
6 // non-POSIX implementation). 6 // non-POSIX implementation).
7 7
8 #include "mojo/system/message_pipe.h" 8 #include "mojo/system/message_pipe.h"
9 9
10 #include <fcntl.h> 10 #include <fcntl.h>
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 145 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
146 // it later, it might already be readable.) 146 // it later, it might already be readable.)
147 waiter.Init(); 147 waiter.Init();
148 EXPECT_EQ(MOJO_RESULT_OK, 148 EXPECT_EQ(MOJO_RESULT_OK,
149 mp_1->AddWaiter(1, &waiter, MOJO_WAIT_FLAG_READABLE, 123)); 149 mp_1->AddWaiter(1, &waiter, MOJO_WAIT_FLAG_READABLE, 123));
150 150
151 // Write to MP 0, port 0. 151 // Write to MP 0, port 0.
152 EXPECT_EQ(MOJO_RESULT_OK, 152 EXPECT_EQ(MOJO_RESULT_OK,
153 mp_0->WriteMessage(0, 153 mp_0->WriteMessage(0,
154 hello, sizeof(hello), 154 hello, sizeof(hello),
155 NULL, 0, 155 NULL,
156 MOJO_WRITE_MESSAGE_FLAG_NONE)); 156 MOJO_WRITE_MESSAGE_FLAG_NONE));
157 157
158 // Wait. 158 // Wait.
159 EXPECT_EQ(123, waiter.Wait(MOJO_DEADLINE_INDEFINITE)); 159 EXPECT_EQ(123, waiter.Wait(MOJO_DEADLINE_INDEFINITE));
160 mp_1->RemoveWaiter(1, &waiter); 160 mp_1->RemoveWaiter(1, &waiter);
161 161
162 // Read from MP 1, port 1. 162 // Read from MP 1, port 1.
163 EXPECT_EQ(MOJO_RESULT_OK, 163 EXPECT_EQ(MOJO_RESULT_OK,
164 mp_1->ReadMessage(1, 164 mp_1->ReadMessage(1,
165 buffer, &buffer_size, 165 buffer, &buffer_size,
166 NULL, NULL, 166 0, NULL,
167 MOJO_READ_MESSAGE_FLAG_NONE)); 167 MOJO_READ_MESSAGE_FLAG_NONE));
168 EXPECT_EQ(sizeof(hello), static_cast<size_t>(buffer_size)); 168 EXPECT_EQ(sizeof(hello), static_cast<size_t>(buffer_size));
169 EXPECT_EQ(0, strcmp(buffer, hello)); 169 EXPECT_EQ(0, strcmp(buffer, hello));
170 170
171 // Write in the other direction: MP 1, port 1 -> ... -> MP 0, port 0. 171 // Write in the other direction: MP 1, port 1 -> ... -> MP 0, port 0.
172 172
173 waiter.Init(); 173 waiter.Init();
174 EXPECT_EQ(MOJO_RESULT_OK, 174 EXPECT_EQ(MOJO_RESULT_OK,
175 mp_0->AddWaiter(0, &waiter, MOJO_WAIT_FLAG_READABLE, 456)); 175 mp_0->AddWaiter(0, &waiter, MOJO_WAIT_FLAG_READABLE, 456));
176 176
177 EXPECT_EQ(MOJO_RESULT_OK, 177 EXPECT_EQ(MOJO_RESULT_OK,
178 mp_1->WriteMessage(1, 178 mp_1->WriteMessage(1,
179 world, sizeof(world), 179 world, sizeof(world),
180 NULL, 0, 180 NULL,
181 MOJO_WRITE_MESSAGE_FLAG_NONE)); 181 MOJO_WRITE_MESSAGE_FLAG_NONE));
182 182
183 EXPECT_EQ(456, waiter.Wait(MOJO_DEADLINE_INDEFINITE)); 183 EXPECT_EQ(456, waiter.Wait(MOJO_DEADLINE_INDEFINITE));
184 mp_0->RemoveWaiter(0, &waiter); 184 mp_0->RemoveWaiter(0, &waiter);
185 185
186 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 186 buffer_size = static_cast<uint32_t>(sizeof(buffer));
187 EXPECT_EQ(MOJO_RESULT_OK, 187 EXPECT_EQ(MOJO_RESULT_OK,
188 mp_0->ReadMessage(0, 188 mp_0->ReadMessage(0,
189 buffer, &buffer_size, 189 buffer, &buffer_size,
190 NULL, NULL, 190 0, NULL,
191 MOJO_READ_MESSAGE_FLAG_NONE)); 191 MOJO_READ_MESSAGE_FLAG_NONE));
192 EXPECT_EQ(sizeof(world), static_cast<size_t>(buffer_size)); 192 EXPECT_EQ(sizeof(world), static_cast<size_t>(buffer_size));
193 EXPECT_EQ(0, strcmp(buffer, world)); 193 EXPECT_EQ(0, strcmp(buffer, world));
194 194
195 // Close MP 0, port 0. 195 // Close MP 0, port 0.
196 mp_0->Close(0); 196 mp_0->Close(0);
197 197
198 // Try to wait for MP 1, port 1 to become readable. This will eventually fail 198 // Try to wait for MP 1, port 1 to become readable. This will eventually fail
199 // when it realizes that MP 0, port 0 has been closed. (It may also fail 199 // when it realizes that MP 0, port 0 has been closed. (It may also fail
200 // immediately.) 200 // immediately.)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 249
250 // Write: MP 2, port 0 -> MP 3, port 1. 250 // Write: MP 2, port 0 -> MP 3, port 1.
251 251
252 waiter.Init(); 252 waiter.Init();
253 EXPECT_EQ(MOJO_RESULT_OK, 253 EXPECT_EQ(MOJO_RESULT_OK,
254 mp_3->AddWaiter(1, &waiter, MOJO_WAIT_FLAG_READABLE, 789)); 254 mp_3->AddWaiter(1, &waiter, MOJO_WAIT_FLAG_READABLE, 789));
255 255
256 EXPECT_EQ(MOJO_RESULT_OK, 256 EXPECT_EQ(MOJO_RESULT_OK,
257 mp_2->WriteMessage(0, 257 mp_2->WriteMessage(0,
258 hello, sizeof(hello), 258 hello, sizeof(hello),
259 NULL, 0, 259 NULL,
260 MOJO_WRITE_MESSAGE_FLAG_NONE)); 260 MOJO_WRITE_MESSAGE_FLAG_NONE));
261 261
262 EXPECT_EQ(789, waiter.Wait(MOJO_DEADLINE_INDEFINITE)); 262 EXPECT_EQ(789, waiter.Wait(MOJO_DEADLINE_INDEFINITE));
263 mp_3->RemoveWaiter(1, &waiter); 263 mp_3->RemoveWaiter(1, &waiter);
264 264
265 // Make sure there's nothing on MP 0, port 0 or MP 1, port 1 or MP 2, port 0. 265 // Make sure there's nothing on MP 0, port 0 or MP 1, port 1 or MP 2, port 0.
266 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 266 buffer_size = static_cast<uint32_t>(sizeof(buffer));
267 EXPECT_EQ(MOJO_RESULT_NOT_FOUND, 267 EXPECT_EQ(MOJO_RESULT_NOT_FOUND,
268 mp_0->ReadMessage(0, 268 mp_0->ReadMessage(0,
269 buffer, &buffer_size, 269 buffer, &buffer_size,
270 NULL, NULL, 270 0, NULL,
271 MOJO_READ_MESSAGE_FLAG_NONE)); 271 MOJO_READ_MESSAGE_FLAG_NONE));
272 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 272 buffer_size = static_cast<uint32_t>(sizeof(buffer));
273 EXPECT_EQ(MOJO_RESULT_NOT_FOUND, 273 EXPECT_EQ(MOJO_RESULT_NOT_FOUND,
274 mp_1->ReadMessage(1, 274 mp_1->ReadMessage(1,
275 buffer, &buffer_size, 275 buffer, &buffer_size,
276 NULL, NULL, 276 0, NULL,
277 MOJO_READ_MESSAGE_FLAG_NONE)); 277 MOJO_READ_MESSAGE_FLAG_NONE));
278 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 278 buffer_size = static_cast<uint32_t>(sizeof(buffer));
279 EXPECT_EQ(MOJO_RESULT_NOT_FOUND, 279 EXPECT_EQ(MOJO_RESULT_NOT_FOUND,
280 mp_2->ReadMessage(0, 280 mp_2->ReadMessage(0,
281 buffer, &buffer_size, 281 buffer, &buffer_size,
282 NULL, NULL, 282 0, NULL,
283 MOJO_READ_MESSAGE_FLAG_NONE)); 283 MOJO_READ_MESSAGE_FLAG_NONE));
284 284
285 // Read from MP 3, port 1. 285 // Read from MP 3, port 1.
286 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 286 buffer_size = static_cast<uint32_t>(sizeof(buffer));
287 EXPECT_EQ(MOJO_RESULT_OK, 287 EXPECT_EQ(MOJO_RESULT_OK,
288 mp_3->ReadMessage(1, 288 mp_3->ReadMessage(1,
289 buffer, &buffer_size, 289 buffer, &buffer_size,
290 NULL, NULL, 290 0, NULL,
291 MOJO_READ_MESSAGE_FLAG_NONE)); 291 MOJO_READ_MESSAGE_FLAG_NONE));
292 EXPECT_EQ(sizeof(hello), static_cast<size_t>(buffer_size)); 292 EXPECT_EQ(sizeof(hello), static_cast<size_t>(buffer_size));
293 EXPECT_EQ(0, strcmp(buffer, hello)); 293 EXPECT_EQ(0, strcmp(buffer, hello));
294 294
295 // Write: MP 0, port 0 -> MP 1, port 1 again. 295 // Write: MP 0, port 0 -> MP 1, port 1 again.
296 296
297 waiter.Init(); 297 waiter.Init();
298 EXPECT_EQ(MOJO_RESULT_OK, 298 EXPECT_EQ(MOJO_RESULT_OK,
299 mp_1->AddWaiter(1, &waiter, MOJO_WAIT_FLAG_READABLE, 123)); 299 mp_1->AddWaiter(1, &waiter, MOJO_WAIT_FLAG_READABLE, 123));
300 300
301 EXPECT_EQ(MOJO_RESULT_OK, 301 EXPECT_EQ(MOJO_RESULT_OK,
302 mp_0->WriteMessage(0, 302 mp_0->WriteMessage(0,
303 world, sizeof(world), 303 world, sizeof(world),
304 NULL, 0, 304 NULL,
305 MOJO_WRITE_MESSAGE_FLAG_NONE)); 305 MOJO_WRITE_MESSAGE_FLAG_NONE));
306 306
307 EXPECT_EQ(123, waiter.Wait(MOJO_DEADLINE_INDEFINITE)); 307 EXPECT_EQ(123, waiter.Wait(MOJO_DEADLINE_INDEFINITE));
308 mp_1->RemoveWaiter(1, &waiter); 308 mp_1->RemoveWaiter(1, &waiter);
309 309
310 // Make sure there's nothing on the other ports. 310 // Make sure there's nothing on the other ports.
311 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 311 buffer_size = static_cast<uint32_t>(sizeof(buffer));
312 EXPECT_EQ(MOJO_RESULT_NOT_FOUND, 312 EXPECT_EQ(MOJO_RESULT_NOT_FOUND,
313 mp_0->ReadMessage(0, 313 mp_0->ReadMessage(0,
314 buffer, &buffer_size, 314 buffer, &buffer_size,
315 NULL, NULL, 315 0, NULL,
316 MOJO_READ_MESSAGE_FLAG_NONE)); 316 MOJO_READ_MESSAGE_FLAG_NONE));
317 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 317 buffer_size = static_cast<uint32_t>(sizeof(buffer));
318 EXPECT_EQ(MOJO_RESULT_NOT_FOUND, 318 EXPECT_EQ(MOJO_RESULT_NOT_FOUND,
319 mp_2->ReadMessage(0, 319 mp_2->ReadMessage(0,
320 buffer, &buffer_size, 320 buffer, &buffer_size,
321 NULL, NULL, 321 0, NULL,
322 MOJO_READ_MESSAGE_FLAG_NONE)); 322 MOJO_READ_MESSAGE_FLAG_NONE));
323 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 323 buffer_size = static_cast<uint32_t>(sizeof(buffer));
324 EXPECT_EQ(MOJO_RESULT_NOT_FOUND, 324 EXPECT_EQ(MOJO_RESULT_NOT_FOUND,
325 mp_3->ReadMessage(1, 325 mp_3->ReadMessage(1,
326 buffer, &buffer_size, 326 buffer, &buffer_size,
327 NULL, NULL, 327 0, NULL,
328 MOJO_READ_MESSAGE_FLAG_NONE)); 328 MOJO_READ_MESSAGE_FLAG_NONE));
329 329
330 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 330 buffer_size = static_cast<uint32_t>(sizeof(buffer));
331 EXPECT_EQ(MOJO_RESULT_OK, 331 EXPECT_EQ(MOJO_RESULT_OK,
332 mp_1->ReadMessage(1, 332 mp_1->ReadMessage(1,
333 buffer, &buffer_size, 333 buffer, &buffer_size,
334 NULL, NULL, 334 0, NULL,
335 MOJO_READ_MESSAGE_FLAG_NONE)); 335 MOJO_READ_MESSAGE_FLAG_NONE));
336 EXPECT_EQ(sizeof(world), static_cast<size_t>(buffer_size)); 336 EXPECT_EQ(sizeof(world), static_cast<size_t>(buffer_size));
337 EXPECT_EQ(0, strcmp(buffer, world)); 337 EXPECT_EQ(0, strcmp(buffer, world));
338 } 338 }
339 339
340 } // namespace 340 } // namespace
341 } // namespace system 341 } // namespace system
342 } // namespace mojo 342 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/message_pipe_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698