| OLD | NEW |
| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 CHECK(client_platform_handle.is_valid()); | 152 CHECK(client_platform_handle.is_valid()); |
| 153 scoped_refptr<MessagePipe> mp(new MessagePipe( | 153 scoped_refptr<MessagePipe> mp(new MessagePipe( |
| 154 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), | 154 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), |
| 155 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); | 155 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); |
| 156 channel_thread.Start(client_platform_handle.Pass(), mp); | 156 channel_thread.Start(client_platform_handle.Pass(), mp); |
| 157 | 157 |
| 158 const std::string quitquitquit("quitquitquit"); | 158 const std::string quitquitquit("quitquitquit"); |
| 159 int rv = 0; | 159 int rv = 0; |
| 160 for (;; rv = (rv + 1) % 100) { | 160 for (;; rv = (rv + 1) % 100) { |
| 161 // Wait for our end of the message pipe to be readable. | 161 // Wait for our end of the message pipe to be readable. |
| 162 MojoResult result = WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE); | 162 MojoResult result = WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE); |
| 163 if (result != MOJO_RESULT_OK) { | 163 if (result != MOJO_RESULT_OK) { |
| 164 // It was closed, probably. | 164 // It was closed, probably. |
| 165 CHECK_EQ(result, MOJO_RESULT_FAILED_PRECONDITION); | 165 CHECK_EQ(result, MOJO_RESULT_FAILED_PRECONDITION); |
| 166 break; | 166 break; |
| 167 } | 167 } |
| 168 | 168 |
| 169 std::string read_buffer(1000, '\0'); | 169 std::string read_buffer(1000, '\0'); |
| 170 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); | 170 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); |
| 171 CHECK_EQ(mp->ReadMessage(0, | 171 CHECK_EQ(mp->ReadMessage(0, |
| 172 &read_buffer[0], &read_buffer_size, | 172 &read_buffer[0], &read_buffer_size, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 203 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); | 203 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); |
| 204 Init(mp); | 204 Init(mp); |
| 205 | 205 |
| 206 std::string hello("hello"); | 206 std::string hello("hello"); |
| 207 EXPECT_EQ(MOJO_RESULT_OK, | 207 EXPECT_EQ(MOJO_RESULT_OK, |
| 208 mp->WriteMessage(0, | 208 mp->WriteMessage(0, |
| 209 hello.data(), static_cast<uint32_t>(hello.size()), | 209 hello.data(), static_cast<uint32_t>(hello.size()), |
| 210 NULL, | 210 NULL, |
| 211 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 211 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 212 | 212 |
| 213 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE)); | 213 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE)); |
| 214 | 214 |
| 215 std::string read_buffer(1000, '\0'); | 215 std::string read_buffer(1000, '\0'); |
| 216 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); | 216 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); |
| 217 CHECK_EQ(mp->ReadMessage(0, | 217 CHECK_EQ(mp->ReadMessage(0, |
| 218 &read_buffer[0], &read_buffer_size, | 218 &read_buffer[0], &read_buffer_size, |
| 219 NULL, NULL, | 219 NULL, NULL, |
| 220 MOJO_READ_MESSAGE_FLAG_NONE), | 220 MOJO_READ_MESSAGE_FLAG_NONE), |
| 221 MOJO_RESULT_OK); | 221 MOJO_RESULT_OK); |
| 222 read_buffer.resize(read_buffer_size); | 222 read_buffer.resize(read_buffer_size); |
| 223 VLOG(2) << "Parent got: " << read_buffer; | 223 VLOG(2) << "Parent got: " << read_buffer; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 252 | 252 |
| 253 const std::string quitquitquit("quitquitquit"); | 253 const std::string quitquitquit("quitquitquit"); |
| 254 EXPECT_EQ(MOJO_RESULT_OK, | 254 EXPECT_EQ(MOJO_RESULT_OK, |
| 255 mp->WriteMessage(0, | 255 mp->WriteMessage(0, |
| 256 quitquitquit.data(), | 256 quitquitquit.data(), |
| 257 static_cast<uint32_t>(quitquitquit.size()), | 257 static_cast<uint32_t>(quitquitquit.size()), |
| 258 NULL, | 258 NULL, |
| 259 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 259 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 260 | 260 |
| 261 for (size_t i = 0; i < kNumMessages; i++) { | 261 for (size_t i = 0; i < kNumMessages; i++) { |
| 262 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE)); | 262 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE)); |
| 263 | 263 |
| 264 std::string read_buffer(kNumMessages * 2, '\0'); | 264 std::string read_buffer(kNumMessages * 2, '\0'); |
| 265 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); | 265 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); |
| 266 CHECK_EQ(mp->ReadMessage(0, | 266 CHECK_EQ(mp->ReadMessage(0, |
| 267 &read_buffer[0], &read_buffer_size, | 267 &read_buffer[0], &read_buffer_size, |
| 268 NULL, NULL, | 268 NULL, NULL, |
| 269 MOJO_READ_MESSAGE_FLAG_NONE), | 269 MOJO_READ_MESSAGE_FLAG_NONE), |
| 270 MOJO_RESULT_OK); | 270 MOJO_RESULT_OK); |
| 271 read_buffer.resize(read_buffer_size); | 271 read_buffer.resize(read_buffer_size); |
| 272 | 272 |
| 273 EXPECT_EQ(std::string(i * 2, 'A' + (i % 26)), read_buffer); | 273 EXPECT_EQ(std::string(i * 2, 'A' + (i % 26)), read_buffer); |
| 274 } | 274 } |
| 275 | 275 |
| 276 // Wait for it to become readable, which should fail (since we sent | 276 // Wait for it to become readable, which should fail (since we sent |
| 277 // "quitquitquit"). | 277 // "quitquitquit"). |
| 278 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 278 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
| 279 WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE)); | 279 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE)); |
| 280 | 280 |
| 281 mp->Close(0); | 281 mp->Close(0); |
| 282 | 282 |
| 283 EXPECT_EQ(static_cast<int>(kNumMessages % 100), | 283 EXPECT_EQ(static_cast<int>(kNumMessages % 100), |
| 284 helper()->WaitForChildShutdown()); | 284 helper()->WaitForChildShutdown()); |
| 285 } | 285 } |
| 286 | 286 |
| 287 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) { | 287 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) { |
| 288 ChannelThread channel_thread; | 288 ChannelThread channel_thread; |
| 289 embedder::ScopedPlatformHandle client_platform_handle = | 289 embedder::ScopedPlatformHandle client_platform_handle = |
| 290 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 290 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 291 CHECK(client_platform_handle.is_valid()); | 291 CHECK(client_platform_handle.is_valid()); |
| 292 scoped_refptr<MessagePipe> mp(new MessagePipe( | 292 scoped_refptr<MessagePipe> mp(new MessagePipe( |
| 293 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), | 293 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), |
| 294 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); | 294 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); |
| 295 channel_thread.Start(client_platform_handle.Pass(), mp); | 295 channel_thread.Start(client_platform_handle.Pass(), mp); |
| 296 | 296 |
| 297 // Wait for the first message from our parent. | 297 // Wait for the first message from our parent. |
| 298 CHECK_EQ(WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE), MOJO_RESULT_OK); | 298 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK); |
| 299 | 299 |
| 300 // It should have a shared buffer. | 300 // It should have a shared buffer. |
| 301 std::string read_buffer(100, '\0'); | 301 std::string read_buffer(100, '\0'); |
| 302 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); | 302 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); |
| 303 DispatcherVector dispatchers; | 303 DispatcherVector dispatchers; |
| 304 uint32_t num_dispatchers = 10; // Maximum number to receive. | 304 uint32_t num_dispatchers = 10; // Maximum number to receive. |
| 305 CHECK_EQ(mp->ReadMessage(0, | 305 CHECK_EQ(mp->ReadMessage(0, |
| 306 &read_buffer[0], &num_bytes, | 306 &read_buffer[0], &num_bytes, |
| 307 &dispatchers, &num_dispatchers, | 307 &dispatchers, &num_dispatchers, |
| 308 MOJO_READ_MESSAGE_FLAG_NONE), | 308 MOJO_READ_MESSAGE_FLAG_NONE), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 334 // And send a message to signal that we've written stuff. | 334 // And send a message to signal that we've written stuff. |
| 335 const std::string go2("go 2"); | 335 const std::string go2("go 2"); |
| 336 CHECK_EQ(mp->WriteMessage(0, | 336 CHECK_EQ(mp->WriteMessage(0, |
| 337 &go2[0], | 337 &go2[0], |
| 338 static_cast<uint32_t>(go2.size()), | 338 static_cast<uint32_t>(go2.size()), |
| 339 NULL, | 339 NULL, |
| 340 MOJO_WRITE_MESSAGE_FLAG_NONE), | 340 MOJO_WRITE_MESSAGE_FLAG_NONE), |
| 341 MOJO_RESULT_OK); | 341 MOJO_RESULT_OK); |
| 342 | 342 |
| 343 // Now wait for our parent to send us a message. | 343 // Now wait for our parent to send us a message. |
| 344 CHECK_EQ(WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE), MOJO_RESULT_OK); | 344 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK); |
| 345 | 345 |
| 346 read_buffer = std::string(100, '\0'); | 346 read_buffer = std::string(100, '\0'); |
| 347 num_bytes = static_cast<uint32_t>(read_buffer.size()); | 347 num_bytes = static_cast<uint32_t>(read_buffer.size()); |
| 348 CHECK_EQ(mp->ReadMessage(0, | 348 CHECK_EQ(mp->ReadMessage(0, |
| 349 &read_buffer[0], &num_bytes, | 349 &read_buffer[0], &num_bytes, |
| 350 NULL, NULL, | 350 NULL, NULL, |
| 351 MOJO_READ_MESSAGE_FLAG_NONE), | 351 MOJO_READ_MESSAGE_FLAG_NONE), |
| 352 MOJO_RESULT_OK); | 352 MOJO_RESULT_OK); |
| 353 read_buffer.resize(num_bytes); | 353 read_buffer.resize(num_bytes); |
| 354 CHECK_EQ(read_buffer, std::string("go 3")); | 354 CHECK_EQ(read_buffer, std::string("go 3")); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 &go1[0], | 406 &go1[0], |
| 407 static_cast<uint32_t>(go1.size()), | 407 static_cast<uint32_t>(go1.size()), |
| 408 &transports, | 408 &transports, |
| 409 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 409 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 410 transport.End(); | 410 transport.End(); |
| 411 | 411 |
| 412 EXPECT_TRUE(dispatcher->HasOneRef()); | 412 EXPECT_TRUE(dispatcher->HasOneRef()); |
| 413 dispatcher = NULL; | 413 dispatcher = NULL; |
| 414 | 414 |
| 415 // Wait for a message from the child. | 415 // Wait for a message from the child. |
| 416 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE)); | 416 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE)); |
| 417 | 417 |
| 418 std::string read_buffer(100, '\0'); | 418 std::string read_buffer(100, '\0'); |
| 419 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); | 419 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); |
| 420 EXPECT_EQ(MOJO_RESULT_OK, | 420 EXPECT_EQ(MOJO_RESULT_OK, |
| 421 mp->ReadMessage(0, | 421 mp->ReadMessage(0, |
| 422 &read_buffer[0], &num_bytes, | 422 &read_buffer[0], &num_bytes, |
| 423 NULL, NULL, | 423 NULL, NULL, |
| 424 MOJO_READ_MESSAGE_FLAG_NONE)); | 424 MOJO_READ_MESSAGE_FLAG_NONE)); |
| 425 read_buffer.resize(num_bytes); | 425 read_buffer.resize(num_bytes); |
| 426 EXPECT_EQ(std::string("go 2"), read_buffer); | 426 EXPECT_EQ(std::string("go 2"), read_buffer); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 438 const std::string go3("go 3"); | 438 const std::string go3("go 3"); |
| 439 EXPECT_EQ(MOJO_RESULT_OK, | 439 EXPECT_EQ(MOJO_RESULT_OK, |
| 440 mp->WriteMessage(0, | 440 mp->WriteMessage(0, |
| 441 &go3[0], | 441 &go3[0], |
| 442 static_cast<uint32_t>(go3.size()), | 442 static_cast<uint32_t>(go3.size()), |
| 443 NULL, | 443 NULL, |
| 444 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 444 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 445 | 445 |
| 446 // Wait for |mp| to become readable, which should fail. | 446 // Wait for |mp| to become readable, which should fail. |
| 447 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 447 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
| 448 WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE)); | 448 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE)); |
| 449 | 449 |
| 450 mp->Close(0); | 450 mp->Close(0); |
| 451 | 451 |
| 452 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | 452 EXPECT_EQ(0, helper()->WaitForChildShutdown()); |
| 453 } | 453 } |
| 454 | 454 |
| 455 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) { | 455 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) { |
| 456 ChannelThread channel_thread; | 456 ChannelThread channel_thread; |
| 457 embedder::ScopedPlatformHandle client_platform_handle = | 457 embedder::ScopedPlatformHandle client_platform_handle = |
| 458 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 458 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 459 CHECK(client_platform_handle.is_valid()); | 459 CHECK(client_platform_handle.is_valid()); |
| 460 scoped_refptr<MessagePipe> mp(new MessagePipe( | 460 scoped_refptr<MessagePipe> mp(new MessagePipe( |
| 461 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), | 461 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), |
| 462 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); | 462 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); |
| 463 channel_thread.Start(client_platform_handle.Pass(), mp); | 463 channel_thread.Start(client_platform_handle.Pass(), mp); |
| 464 | 464 |
| 465 CHECK_EQ(WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE), MOJO_RESULT_OK); | 465 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK); |
| 466 | 466 |
| 467 std::string read_buffer(100, '\0'); | 467 std::string read_buffer(100, '\0'); |
| 468 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); | 468 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); |
| 469 DispatcherVector dispatchers; | 469 DispatcherVector dispatchers; |
| 470 uint32_t num_dispatchers = 10; // Maximum number to receive. | 470 uint32_t num_dispatchers = 10; // Maximum number to receive. |
| 471 CHECK_EQ(mp->ReadMessage(0, | 471 CHECK_EQ(mp->ReadMessage(0, |
| 472 &read_buffer[0], &num_bytes, | 472 &read_buffer[0], &num_bytes, |
| 473 &dispatchers, &num_dispatchers, | 473 &dispatchers, &num_dispatchers, |
| 474 MOJO_READ_MESSAGE_FLAG_NONE), | 474 MOJO_READ_MESSAGE_FLAG_NONE), |
| 475 MOJO_RESULT_OK); | 475 MOJO_RESULT_OK); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 static_cast<uint32_t>(hello.size()), | 536 static_cast<uint32_t>(hello.size()), |
| 537 &transports, | 537 &transports, |
| 538 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 538 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 539 transport.End(); | 539 transport.End(); |
| 540 | 540 |
| 541 EXPECT_TRUE(dispatcher->HasOneRef()); | 541 EXPECT_TRUE(dispatcher->HasOneRef()); |
| 542 dispatcher = NULL; | 542 dispatcher = NULL; |
| 543 | 543 |
| 544 // Wait for it to become readable, which should fail. | 544 // Wait for it to become readable, which should fail. |
| 545 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 545 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
| 546 WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE)); | 546 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE)); |
| 547 | 547 |
| 548 mp->Close(0); | 548 mp->Close(0); |
| 549 | 549 |
| 550 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | 550 EXPECT_EQ(0, helper()->WaitForChildShutdown()); |
| 551 } | 551 } |
| 552 | 552 |
| 553 } // namespace | 553 } // namespace |
| 554 } // namespace system | 554 } // namespace system |
| 555 } // namespace mojo | 555 } // namespace mojo |
| OLD | NEW |