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

Side by Side Diff: mojo/edk/system/multiprocess_message_pipe_unittest.cc

Issue 728553002: Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « mojo/edk/system/message_pipe_unittest.cc ('k') | mojo/edk/system/options_validation.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 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 #include <stdint.h> 5 #include <stdint.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 CHECK_EQ(hss.satisfied_signals, 0u); 65 CHECK_EQ(hss.satisfied_signals, 0u);
66 CHECK_EQ(hss.satisfiable_signals, 0u); 66 CHECK_EQ(hss.satisfiable_signals, 0u);
67 break; 67 break;
68 } else { 68 } else {
69 CHECK((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); 69 CHECK((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE));
70 CHECK((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); 70 CHECK((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE));
71 } 71 }
72 72
73 std::string read_buffer(1000, '\0'); 73 std::string read_buffer(1000, '\0');
74 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); 74 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size());
75 CHECK_EQ(mp->ReadMessage(0, 75 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
76 UserPointer<void>(&read_buffer[0]), 76 MakeUserPointer(&read_buffer_size), nullptr,
77 MakeUserPointer(&read_buffer_size), 77 nullptr, MOJO_READ_MESSAGE_FLAG_NONE),
78 nullptr,
79 nullptr,
80 MOJO_READ_MESSAGE_FLAG_NONE),
81 MOJO_RESULT_OK); 78 MOJO_RESULT_OK);
82 read_buffer.resize(read_buffer_size); 79 read_buffer.resize(read_buffer_size);
83 VLOG(2) << "Child got: " << read_buffer; 80 VLOG(2) << "Child got: " << read_buffer;
84 81
85 if (read_buffer == quitquitquit) { 82 if (read_buffer == quitquitquit) {
86 VLOG(2) << "Child quitting."; 83 VLOG(2) << "Child quitting.";
87 break; 84 break;
88 } 85 }
89 86
90 std::string write_buffer = read_buffer + read_buffer; 87 std::string write_buffer = read_buffer + read_buffer;
91 CHECK_EQ(mp->WriteMessage(0, 88 CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(write_buffer.data()),
92 UserPointer<const void>(write_buffer.data()),
93 static_cast<uint32_t>(write_buffer.size()), 89 static_cast<uint32_t>(write_buffer.size()),
94 nullptr, 90 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE),
95 MOJO_WRITE_MESSAGE_FLAG_NONE),
96 MOJO_RESULT_OK); 91 MOJO_RESULT_OK);
97 } 92 }
98 93
99 mp->Close(0); 94 mp->Close(0);
100 return rv; 95 return rv;
101 } 96 }
102 97
103 // Sends "hello" to child, and expects "hellohello" back. 98 // Sends "hello" to child, and expects "hellohello" back.
104 TEST_F(MultiprocessMessagePipeTest, Basic) { 99 TEST_F(MultiprocessMessagePipeTest, Basic) {
105 helper()->StartChild("EchoEcho"); 100 helper()->StartChild("EchoEcho");
106 101
107 scoped_refptr<ChannelEndpoint> ep; 102 scoped_refptr<ChannelEndpoint> ep;
108 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); 103 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep));
109 Init(ep); 104 Init(ep);
110 105
111 std::string hello("hello"); 106 std::string hello("hello");
112 EXPECT_EQ(MOJO_RESULT_OK, 107 EXPECT_EQ(MOJO_RESULT_OK,
113 mp->WriteMessage(0, 108 mp->WriteMessage(0, UserPointer<const void>(hello.data()),
114 UserPointer<const void>(hello.data()), 109 static_cast<uint32_t>(hello.size()), nullptr,
115 static_cast<uint32_t>(hello.size()),
116 nullptr,
117 MOJO_WRITE_MESSAGE_FLAG_NONE)); 110 MOJO_WRITE_MESSAGE_FLAG_NONE));
118 111
119 HandleSignalsState hss; 112 HandleSignalsState hss;
120 EXPECT_EQ(MOJO_RESULT_OK, 113 EXPECT_EQ(MOJO_RESULT_OK,
121 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); 114 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
122 // The child may or may not have closed its end of the message pipe and died 115 // The child may or may not have closed its end of the message pipe and died
123 // (and we may or may not know it yet), so our end may or may not appear as 116 // (and we may or may not know it yet), so our end may or may not appear as
124 // writable. 117 // writable.
125 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); 118 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE));
126 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); 119 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE));
127 120
128 std::string read_buffer(1000, '\0'); 121 std::string read_buffer(1000, '\0');
129 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); 122 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size());
130 CHECK_EQ(mp->ReadMessage(0, 123 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
131 UserPointer<void>(&read_buffer[0]), 124 MakeUserPointer(&read_buffer_size), nullptr, nullptr,
132 MakeUserPointer(&read_buffer_size),
133 nullptr,
134 nullptr,
135 MOJO_READ_MESSAGE_FLAG_NONE), 125 MOJO_READ_MESSAGE_FLAG_NONE),
136 MOJO_RESULT_OK); 126 MOJO_RESULT_OK);
137 read_buffer.resize(read_buffer_size); 127 read_buffer.resize(read_buffer_size);
138 VLOG(2) << "Parent got: " << read_buffer; 128 VLOG(2) << "Parent got: " << read_buffer;
139 EXPECT_EQ(hello + hello, read_buffer); 129 EXPECT_EQ(hello + hello, read_buffer);
140 130
141 mp->Close(0); 131 mp->Close(0);
142 132
143 // We sent one message. 133 // We sent one message.
144 EXPECT_EQ(1 % 100, helper()->WaitForChildShutdown()); 134 EXPECT_EQ(1 % 100, helper()->WaitForChildShutdown());
145 } 135 }
146 136
147 // Sends a bunch of messages to the child. Expects them "repeated" back. Waits 137 // Sends a bunch of messages to the child. Expects them "repeated" back. Waits
148 // for the child to close its end before quitting. 138 // for the child to close its end before quitting.
149 TEST_F(MultiprocessMessagePipeTest, QueueMessages) { 139 TEST_F(MultiprocessMessagePipeTest, QueueMessages) {
150 helper()->StartChild("EchoEcho"); 140 helper()->StartChild("EchoEcho");
151 141
152 scoped_refptr<ChannelEndpoint> ep; 142 scoped_refptr<ChannelEndpoint> ep;
153 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); 143 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep));
154 Init(ep); 144 Init(ep);
155 145
156 static const size_t kNumMessages = 1001; 146 static const size_t kNumMessages = 1001;
157 for (size_t i = 0; i < kNumMessages; i++) { 147 for (size_t i = 0; i < kNumMessages; i++) {
158 std::string write_buffer(i, 'A' + (i % 26)); 148 std::string write_buffer(i, 'A' + (i % 26));
159 EXPECT_EQ(MOJO_RESULT_OK, 149 EXPECT_EQ(MOJO_RESULT_OK,
160 mp->WriteMessage(0, 150 mp->WriteMessage(0, UserPointer<const void>(write_buffer.data()),
161 UserPointer<const void>(write_buffer.data()),
162 static_cast<uint32_t>(write_buffer.size()), 151 static_cast<uint32_t>(write_buffer.size()),
163 nullptr, 152 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
164 MOJO_WRITE_MESSAGE_FLAG_NONE));
165 } 153 }
166 154
167 const std::string quitquitquit("quitquitquit"); 155 const std::string quitquitquit("quitquitquit");
168 EXPECT_EQ(MOJO_RESULT_OK, 156 EXPECT_EQ(MOJO_RESULT_OK,
169 mp->WriteMessage(0, 157 mp->WriteMessage(0, UserPointer<const void>(quitquitquit.data()),
170 UserPointer<const void>(quitquitquit.data()),
171 static_cast<uint32_t>(quitquitquit.size()), 158 static_cast<uint32_t>(quitquitquit.size()),
172 nullptr, 159 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
173 MOJO_WRITE_MESSAGE_FLAG_NONE));
174 160
175 for (size_t i = 0; i < kNumMessages; i++) { 161 for (size_t i = 0; i < kNumMessages; i++) {
176 HandleSignalsState hss; 162 HandleSignalsState hss;
177 EXPECT_EQ(MOJO_RESULT_OK, 163 EXPECT_EQ(MOJO_RESULT_OK,
178 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); 164 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
179 // The child may or may not have closed its end of the message pipe and died 165 // The child may or may not have closed its end of the message pipe and died
180 // (and we may or may not know it yet), so our end may or may not appear as 166 // (and we may or may not know it yet), so our end may or may not appear as
181 // writable. 167 // writable.
182 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); 168 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE));
183 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); 169 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE));
184 170
185 std::string read_buffer(kNumMessages * 2, '\0'); 171 std::string read_buffer(kNumMessages * 2, '\0');
186 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); 172 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size());
187 CHECK_EQ(mp->ReadMessage(0, 173 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
188 UserPointer<void>(&read_buffer[0]), 174 MakeUserPointer(&read_buffer_size), nullptr,
189 MakeUserPointer(&read_buffer_size), 175 nullptr, MOJO_READ_MESSAGE_FLAG_NONE),
190 nullptr,
191 nullptr,
192 MOJO_READ_MESSAGE_FLAG_NONE),
193 MOJO_RESULT_OK); 176 MOJO_RESULT_OK);
194 read_buffer.resize(read_buffer_size); 177 read_buffer.resize(read_buffer_size);
195 178
196 EXPECT_EQ(std::string(i * 2, 'A' + (i % 26)), read_buffer); 179 EXPECT_EQ(std::string(i * 2, 'A' + (i % 26)), read_buffer);
197 } 180 }
198 181
199 // Wait for it to become readable, which should fail (since we sent 182 // Wait for it to become readable, which should fail (since we sent
200 // "quitquitquit"). 183 // "quitquitquit").
201 HandleSignalsState hss; 184 HandleSignalsState hss;
202 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 185 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
(...skipping 26 matching lines...) Expand all
229 CHECK_EQ(hss.satisfied_signals, 212 CHECK_EQ(hss.satisfied_signals,
230 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); 213 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE);
231 CHECK_EQ(hss.satisfiable_signals, 214 CHECK_EQ(hss.satisfiable_signals,
232 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); 215 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE);
233 216
234 // It should have a shared buffer. 217 // It should have a shared buffer.
235 std::string read_buffer(100, '\0'); 218 std::string read_buffer(100, '\0');
236 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); 219 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
237 DispatcherVector dispatchers; 220 DispatcherVector dispatchers;
238 uint32_t num_dispatchers = 10; // Maximum number to receive. 221 uint32_t num_dispatchers = 10; // Maximum number to receive.
239 CHECK_EQ(mp->ReadMessage(0, 222 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
240 UserPointer<void>(&read_buffer[0]), 223 MakeUserPointer(&num_bytes), &dispatchers,
241 MakeUserPointer(&num_bytes), 224 &num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE),
242 &dispatchers,
243 &num_dispatchers,
244 MOJO_READ_MESSAGE_FLAG_NONE),
245 MOJO_RESULT_OK); 225 MOJO_RESULT_OK);
246 read_buffer.resize(num_bytes); 226 read_buffer.resize(num_bytes);
247 CHECK_EQ(read_buffer, std::string("go 1")); 227 CHECK_EQ(read_buffer, std::string("go 1"));
248 CHECK_EQ(num_dispatchers, 1u); 228 CHECK_EQ(num_dispatchers, 1u);
249 229
250 CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypeSharedBuffer); 230 CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypeSharedBuffer);
251 231
252 scoped_refptr<SharedBufferDispatcher> dispatcher( 232 scoped_refptr<SharedBufferDispatcher> dispatcher(
253 static_cast<SharedBufferDispatcher*>(dispatchers[0].get())); 233 static_cast<SharedBufferDispatcher*>(dispatchers[0].get()));
254 234
255 // Make a mapping. 235 // Make a mapping.
256 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping; 236 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping;
257 CHECK_EQ(dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping), 237 CHECK_EQ(dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping),
258 MOJO_RESULT_OK); 238 MOJO_RESULT_OK);
259 CHECK(mapping); 239 CHECK(mapping);
260 CHECK(mapping->GetBase()); 240 CHECK(mapping->GetBase());
261 CHECK_EQ(mapping->GetLength(), 100u); 241 CHECK_EQ(mapping->GetLength(), 100u);
262 242
263 // Write some stuff to the shared buffer. 243 // Write some stuff to the shared buffer.
264 static const char kHello[] = "hello"; 244 static const char kHello[] = "hello";
265 memcpy(mapping->GetBase(), kHello, sizeof(kHello)); 245 memcpy(mapping->GetBase(), kHello, sizeof(kHello));
266 246
267 // We should be able to close the dispatcher now. 247 // We should be able to close the dispatcher now.
268 dispatcher->Close(); 248 dispatcher->Close();
269 249
270 // And send a message to signal that we've written stuff. 250 // And send a message to signal that we've written stuff.
271 const std::string go2("go 2"); 251 const std::string go2("go 2");
272 CHECK_EQ(mp->WriteMessage(0, 252 CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(&go2[0]),
273 UserPointer<const void>(&go2[0]), 253 static_cast<uint32_t>(go2.size()), nullptr,
274 static_cast<uint32_t>(go2.size()),
275 nullptr,
276 MOJO_WRITE_MESSAGE_FLAG_NONE), 254 MOJO_WRITE_MESSAGE_FLAG_NONE),
277 MOJO_RESULT_OK); 255 MOJO_RESULT_OK);
278 256
279 // Now wait for our parent to send us a message. 257 // Now wait for our parent to send us a message.
280 hss = HandleSignalsState(); 258 hss = HandleSignalsState();
281 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), 259 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss),
282 MOJO_RESULT_OK); 260 MOJO_RESULT_OK);
283 CHECK_EQ(hss.satisfied_signals, 261 CHECK_EQ(hss.satisfied_signals,
284 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); 262 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE);
285 CHECK_EQ(hss.satisfiable_signals, 263 CHECK_EQ(hss.satisfiable_signals,
286 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); 264 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE);
287 265
288 read_buffer = std::string(100, '\0'); 266 read_buffer = std::string(100, '\0');
289 num_bytes = static_cast<uint32_t>(read_buffer.size()); 267 num_bytes = static_cast<uint32_t>(read_buffer.size());
290 CHECK_EQ(mp->ReadMessage(0, 268 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
291 UserPointer<void>(&read_buffer[0]), 269 MakeUserPointer(&num_bytes), nullptr, nullptr,
292 MakeUserPointer(&num_bytes),
293 nullptr,
294 nullptr,
295 MOJO_READ_MESSAGE_FLAG_NONE), 270 MOJO_READ_MESSAGE_FLAG_NONE),
296 MOJO_RESULT_OK); 271 MOJO_RESULT_OK);
297 read_buffer.resize(num_bytes); 272 read_buffer.resize(num_bytes);
298 CHECK_EQ(read_buffer, std::string("go 3")); 273 CHECK_EQ(read_buffer, std::string("go 3"));
299 274
300 // It should have written something to the shared buffer. 275 // It should have written something to the shared buffer.
301 static const char kWorld[] = "world!!!"; 276 static const char kWorld[] = "world!!!";
302 CHECK_EQ(memcmp(mapping->GetBase(), kWorld, sizeof(kWorld)), 0); 277 CHECK_EQ(memcmp(mapping->GetBase(), kWorld, sizeof(kWorld)), 0);
303 278
304 // And we're done. 279 // And we're done.
(...skipping 10 matching lines...) Expand all
315 #endif 290 #endif
316 TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) { 291 TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
317 helper()->StartChild("CheckSharedBuffer"); 292 helper()->StartChild("CheckSharedBuffer");
318 293
319 scoped_refptr<ChannelEndpoint> ep; 294 scoped_refptr<ChannelEndpoint> ep;
320 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); 295 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep));
321 Init(ep); 296 Init(ep);
322 297
323 // Make a shared buffer. 298 // Make a shared buffer.
324 scoped_refptr<SharedBufferDispatcher> dispatcher; 299 scoped_refptr<SharedBufferDispatcher> dispatcher;
325 EXPECT_EQ(MOJO_RESULT_OK, 300 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
326 SharedBufferDispatcher::Create( 301 platform_support(),
327 platform_support(), 302 SharedBufferDispatcher::kDefaultCreateOptions,
328 SharedBufferDispatcher::kDefaultCreateOptions, 303 100, &dispatcher));
329 100,
330 &dispatcher));
331 ASSERT_TRUE(dispatcher.get()); 304 ASSERT_TRUE(dispatcher.get());
332 305
333 // Make a mapping. 306 // Make a mapping.
334 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping; 307 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping;
335 EXPECT_EQ(MOJO_RESULT_OK, 308 EXPECT_EQ(MOJO_RESULT_OK,
336 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 309 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
337 ASSERT_TRUE(mapping); 310 ASSERT_TRUE(mapping);
338 ASSERT_TRUE(mapping->GetBase()); 311 ASSERT_TRUE(mapping->GetBase());
339 ASSERT_EQ(100u, mapping->GetLength()); 312 ASSERT_EQ(100u, mapping->GetLength());
340 313
341 // Send the shared buffer. 314 // Send the shared buffer.
342 const std::string go1("go 1"); 315 const std::string go1("go 1");
343 DispatcherTransport transport( 316 DispatcherTransport transport(
344 test::DispatcherTryStartTransport(dispatcher.get())); 317 test::DispatcherTryStartTransport(dispatcher.get()));
345 ASSERT_TRUE(transport.is_valid()); 318 ASSERT_TRUE(transport.is_valid());
346 319
347 std::vector<DispatcherTransport> transports; 320 std::vector<DispatcherTransport> transports;
348 transports.push_back(transport); 321 transports.push_back(transport);
349 EXPECT_EQ(MOJO_RESULT_OK, 322 EXPECT_EQ(MOJO_RESULT_OK,
350 mp->WriteMessage(0, 323 mp->WriteMessage(0, UserPointer<const void>(&go1[0]),
351 UserPointer<const void>(&go1[0]), 324 static_cast<uint32_t>(go1.size()), &transports,
352 static_cast<uint32_t>(go1.size()),
353 &transports,
354 MOJO_WRITE_MESSAGE_FLAG_NONE)); 325 MOJO_WRITE_MESSAGE_FLAG_NONE));
355 transport.End(); 326 transport.End();
356 327
357 EXPECT_TRUE(dispatcher->HasOneRef()); 328 EXPECT_TRUE(dispatcher->HasOneRef());
358 dispatcher = nullptr; 329 dispatcher = nullptr;
359 330
360 // Wait for a message from the child. 331 // Wait for a message from the child.
361 HandleSignalsState hss; 332 HandleSignalsState hss;
362 EXPECT_EQ(MOJO_RESULT_OK, 333 EXPECT_EQ(MOJO_RESULT_OK,
363 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); 334 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
364 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); 335 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE));
365 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); 336 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE));
366 337
367 std::string read_buffer(100, '\0'); 338 std::string read_buffer(100, '\0');
368 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); 339 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
369 EXPECT_EQ(MOJO_RESULT_OK, 340 EXPECT_EQ(MOJO_RESULT_OK,
370 mp->ReadMessage(0, 341 mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
371 UserPointer<void>(&read_buffer[0]), 342 MakeUserPointer(&num_bytes), nullptr, nullptr,
372 MakeUserPointer(&num_bytes),
373 nullptr,
374 nullptr,
375 MOJO_READ_MESSAGE_FLAG_NONE)); 343 MOJO_READ_MESSAGE_FLAG_NONE));
376 read_buffer.resize(num_bytes); 344 read_buffer.resize(num_bytes);
377 EXPECT_EQ(std::string("go 2"), read_buffer); 345 EXPECT_EQ(std::string("go 2"), read_buffer);
378 346
379 // After we get it, the child should have written something to the shared 347 // After we get it, the child should have written something to the shared
380 // buffer. 348 // buffer.
381 static const char kHello[] = "hello"; 349 static const char kHello[] = "hello";
382 EXPECT_EQ(0, memcmp(mapping->GetBase(), kHello, sizeof(kHello))); 350 EXPECT_EQ(0, memcmp(mapping->GetBase(), kHello, sizeof(kHello)));
383 351
384 // Now we'll write some stuff to the shared buffer. 352 // Now we'll write some stuff to the shared buffer.
385 static const char kWorld[] = "world!!!"; 353 static const char kWorld[] = "world!!!";
386 memcpy(mapping->GetBase(), kWorld, sizeof(kWorld)); 354 memcpy(mapping->GetBase(), kWorld, sizeof(kWorld));
387 355
388 // And send a message to signal that we've written stuff. 356 // And send a message to signal that we've written stuff.
389 const std::string go3("go 3"); 357 const std::string go3("go 3");
390 EXPECT_EQ(MOJO_RESULT_OK, 358 EXPECT_EQ(MOJO_RESULT_OK,
391 mp->WriteMessage(0, 359 mp->WriteMessage(0, UserPointer<const void>(&go3[0]),
392 UserPointer<const void>(&go3[0]), 360 static_cast<uint32_t>(go3.size()), nullptr,
393 static_cast<uint32_t>(go3.size()),
394 nullptr,
395 MOJO_WRITE_MESSAGE_FLAG_NONE)); 361 MOJO_WRITE_MESSAGE_FLAG_NONE));
396 362
397 // Wait for |mp| to become readable, which should fail. 363 // Wait for |mp| to become readable, which should fail.
398 hss = HandleSignalsState(); 364 hss = HandleSignalsState();
399 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 365 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
400 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); 366 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
401 EXPECT_EQ(0u, hss.satisfied_signals); 367 EXPECT_EQ(0u, hss.satisfied_signals);
402 EXPECT_EQ(0u, hss.satisfiable_signals); 368 EXPECT_EQ(0u, hss.satisfiable_signals);
403 369
404 mp->Close(0); 370 mp->Close(0);
(...skipping 16 matching lines...) Expand all
421 MOJO_RESULT_OK); 387 MOJO_RESULT_OK);
422 CHECK_EQ(hss.satisfied_signals, 388 CHECK_EQ(hss.satisfied_signals,
423 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); 389 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE);
424 CHECK_EQ(hss.satisfiable_signals, 390 CHECK_EQ(hss.satisfiable_signals,
425 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); 391 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE);
426 392
427 std::string read_buffer(100, '\0'); 393 std::string read_buffer(100, '\0');
428 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); 394 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
429 DispatcherVector dispatchers; 395 DispatcherVector dispatchers;
430 uint32_t num_dispatchers = 10; // Maximum number to receive. 396 uint32_t num_dispatchers = 10; // Maximum number to receive.
431 CHECK_EQ(mp->ReadMessage(0, 397 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
432 UserPointer<void>(&read_buffer[0]), 398 MakeUserPointer(&num_bytes), &dispatchers,
433 MakeUserPointer(&num_bytes), 399 &num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE),
434 &dispatchers,
435 &num_dispatchers,
436 MOJO_READ_MESSAGE_FLAG_NONE),
437 MOJO_RESULT_OK); 400 MOJO_RESULT_OK);
438 mp->Close(0); 401 mp->Close(0);
439 402
440 read_buffer.resize(num_bytes); 403 read_buffer.resize(num_bytes);
441 CHECK_EQ(read_buffer, std::string("hello")); 404 CHECK_EQ(read_buffer, std::string("hello"));
442 CHECK_EQ(num_dispatchers, 1u); 405 CHECK_EQ(num_dispatchers, 1u);
443 406
444 CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypePlatformHandle); 407 CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypePlatformHandle);
445 408
446 scoped_refptr<PlatformHandleDispatcher> dispatcher( 409 scoped_refptr<PlatformHandleDispatcher> dispatcher(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 new PlatformHandleDispatcher(h.Pass())); 452 new PlatformHandleDispatcher(h.Pass()));
490 453
491 const std::string hello("hello"); 454 const std::string hello("hello");
492 DispatcherTransport transport( 455 DispatcherTransport transport(
493 test::DispatcherTryStartTransport(dispatcher.get())); 456 test::DispatcherTryStartTransport(dispatcher.get()));
494 ASSERT_TRUE(transport.is_valid()); 457 ASSERT_TRUE(transport.is_valid());
495 458
496 std::vector<DispatcherTransport> transports; 459 std::vector<DispatcherTransport> transports;
497 transports.push_back(transport); 460 transports.push_back(transport);
498 EXPECT_EQ(MOJO_RESULT_OK, 461 EXPECT_EQ(MOJO_RESULT_OK,
499 mp->WriteMessage(0, 462 mp->WriteMessage(0, UserPointer<const void>(&hello[0]),
500 UserPointer<const void>(&hello[0]), 463 static_cast<uint32_t>(hello.size()), &transports,
501 static_cast<uint32_t>(hello.size()),
502 &transports,
503 MOJO_WRITE_MESSAGE_FLAG_NONE)); 464 MOJO_WRITE_MESSAGE_FLAG_NONE));
504 transport.End(); 465 transport.End();
505 466
506 EXPECT_TRUE(dispatcher->HasOneRef()); 467 EXPECT_TRUE(dispatcher->HasOneRef());
507 dispatcher = nullptr; 468 dispatcher = nullptr;
508 469
509 // Wait for it to become readable, which should fail. 470 // Wait for it to become readable, which should fail.
510 HandleSignalsState hss; 471 HandleSignalsState hss;
511 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 472 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
512 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); 473 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
513 EXPECT_EQ(0u, hss.satisfied_signals); 474 EXPECT_EQ(0u, hss.satisfied_signals);
514 EXPECT_EQ(0u, hss.satisfiable_signals); 475 EXPECT_EQ(0u, hss.satisfiable_signals);
515 476
516 mp->Close(0); 477 mp->Close(0);
517 478
518 EXPECT_EQ(0, helper()->WaitForChildShutdown()); 479 EXPECT_EQ(0, helper()->WaitForChildShutdown());
519 } 480 }
520 481
521 } // namespace 482 } // namespace
522 } // namespace system 483 } // namespace system
523 } // namespace mojo 484 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/message_pipe_unittest.cc ('k') | mojo/edk/system/options_validation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698