| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 180 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 181 Waiter waiter; | 181 Waiter waiter; |
| 182 HandleSignalsState hss; | 182 HandleSignalsState hss; |
| 183 uint32_t context = 0; | 183 uint32_t context = 0; |
| 184 | 184 |
| 185 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 185 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
| 186 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 186 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
| 187 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 187 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
| 188 | 188 |
| 189 RefPtr<ChannelEndpoint> ep0; | 189 RefPtr<ChannelEndpoint> ep0; |
| 190 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 190 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 191 RefPtr<ChannelEndpoint> ep1; | 191 RefPtr<ChannelEndpoint> ep1; |
| 192 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 192 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 193 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 193 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 194 | 194 |
| 195 // Write in one direction: MP 0, port 0 -> ... -> MP 1, port 1. | 195 // Write in one direction: MP 0, port 0 -> ... -> MP 1, port 1. |
| 196 | 196 |
| 197 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 197 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 198 // it later, it might already be readable.) | 198 // it later, it might already be readable.) |
| 199 waiter.Init(); | 199 waiter.Init(); |
| 200 ASSERT_EQ( | 200 ASSERT_EQ( |
| 201 MOJO_RESULT_OK, | 201 MOJO_RESULT_OK, |
| 202 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 202 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 TEST_F(RemoteMessagePipeTest, PeerClosed) { | 279 TEST_F(RemoteMessagePipeTest, PeerClosed) { |
| 280 Waiter waiter; | 280 Waiter waiter; |
| 281 HandleSignalsState hss; | 281 HandleSignalsState hss; |
| 282 uint32_t context = 0; | 282 uint32_t context = 0; |
| 283 | 283 |
| 284 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 284 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
| 285 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 285 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
| 286 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 286 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
| 287 | 287 |
| 288 RefPtr<ChannelEndpoint> ep0; | 288 RefPtr<ChannelEndpoint> ep0; |
| 289 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 289 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 290 RefPtr<ChannelEndpoint> ep1; | 290 RefPtr<ChannelEndpoint> ep1; |
| 291 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 291 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 292 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 292 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 293 | 293 |
| 294 // Close MP 0, port 0. | 294 // Close MP 0, port 0. |
| 295 mp0->Close(0); | 295 mp0->Close(0); |
| 296 | 296 |
| 297 // Try to wait for MP 1, port 1 to be signaled with peer closed. | 297 // Try to wait for MP 1, port 1 to be signaled with peer closed. |
| 298 waiter.Init(); | 298 waiter.Init(); |
| 299 hss = HandleSignalsState(); | 299 hss = HandleSignalsState(); |
| 300 MojoResult result = | 300 MojoResult result = |
| 301 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 101, &hss); | 301 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 101, &hss); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 317 static const char kWorld[] = "world!!!1!!!1!"; | 317 static const char kWorld[] = "world!!!1!!!1!"; |
| 318 char buffer[100] = {0}; | 318 char buffer[100] = {0}; |
| 319 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 319 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 320 Waiter waiter; | 320 Waiter waiter; |
| 321 HandleSignalsState hss; | 321 HandleSignalsState hss; |
| 322 uint32_t context = 0; | 322 uint32_t context = 0; |
| 323 | 323 |
| 324 // Connect message pipes as in the |Basic| test. | 324 // Connect message pipes as in the |Basic| test. |
| 325 | 325 |
| 326 RefPtr<ChannelEndpoint> ep0; | 326 RefPtr<ChannelEndpoint> ep0; |
| 327 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 327 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 328 RefPtr<ChannelEndpoint> ep1; | 328 RefPtr<ChannelEndpoint> ep1; |
| 329 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 329 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 330 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 330 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 331 | 331 |
| 332 // Now put another message pipe on the channel. | 332 // Now put another message pipe on the channel. |
| 333 | 333 |
| 334 // Do this by creating a message pipe (for the |channels(0)| side) and | 334 // Do this by creating a message pipe (for the |channels(0)| side) and |
| 335 // attaching and running it, yielding the remote ID. A message is then sent | 335 // attaching and running it, yielding the remote ID. A message is then sent |
| 336 // via |ep0| (i.e., sent using |mp0|, port 0) with this remote ID. Upon | 336 // via |ep0| (i.e., sent using |mp0|, port 0) with this remote ID. Upon |
| 337 // receiving this message, |PassIncomingMessagePipe()| is used to obtain the | 337 // receiving this message, |PassIncomingMessagePipe()| is used to obtain the |
| 338 // message pipe on the other side. | 338 // message pipe on the other side. |
| 339 scoped_refptr<MessagePipe> mp2(MessagePipe::CreateLocalLocal()); | 339 auto mp2 = MessagePipe::CreateLocalLocal(); |
| 340 ASSERT_TRUE(channels(0)); | 340 ASSERT_TRUE(channels(0)); |
| 341 size_t max_endpoint_info_size; | 341 size_t max_endpoint_info_size; |
| 342 size_t max_platform_handle_count; | 342 size_t max_platform_handle_count; |
| 343 mp2->StartSerialize(1, channels(0), &max_endpoint_info_size, | 343 mp2->StartSerialize(1, channels(0), &max_endpoint_info_size, |
| 344 &max_platform_handle_count); | 344 &max_platform_handle_count); |
| 345 EXPECT_GT(max_endpoint_info_size, 0u); | 345 EXPECT_GT(max_endpoint_info_size, 0u); |
| 346 ASSERT_EQ(0u, max_platform_handle_count); | 346 ASSERT_EQ(0u, max_platform_handle_count); |
| 347 std::unique_ptr<char[]> endpoint_info(new char[max_endpoint_info_size]); | 347 std::unique_ptr<char[]> endpoint_info(new char[max_endpoint_info_size]); |
| 348 size_t endpoint_info_size; | 348 size_t endpoint_info_size; |
| 349 mp2->EndSerialize(1, channels(0), endpoint_info.get(), &endpoint_info_size, | 349 mp2->EndSerialize(1, channels(0), endpoint_info.get(), &endpoint_info_size, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 373 buffer_size = static_cast<uint32_t>(endpoint_info_size); | 373 buffer_size = static_cast<uint32_t>(endpoint_info_size); |
| 374 EXPECT_EQ(MOJO_RESULT_OK, | 374 EXPECT_EQ(MOJO_RESULT_OK, |
| 375 mp1->ReadMessage(1, UserPointer<void>(received_endpoint_info.get()), | 375 mp1->ReadMessage(1, UserPointer<void>(received_endpoint_info.get()), |
| 376 MakeUserPointer(&buffer_size), nullptr, nullptr, | 376 MakeUserPointer(&buffer_size), nullptr, nullptr, |
| 377 MOJO_READ_MESSAGE_FLAG_NONE)); | 377 MOJO_READ_MESSAGE_FLAG_NONE)); |
| 378 EXPECT_EQ(endpoint_info_size, static_cast<size_t>(buffer_size)); | 378 EXPECT_EQ(endpoint_info_size, static_cast<size_t>(buffer_size)); |
| 379 EXPECT_EQ(0, memcmp(received_endpoint_info.get(), endpoint_info.get(), | 379 EXPECT_EQ(0, memcmp(received_endpoint_info.get(), endpoint_info.get(), |
| 380 endpoint_info_size)); | 380 endpoint_info_size)); |
| 381 | 381 |
| 382 // Warning: The local side of mp3 is port 0, not port 1. | 382 // Warning: The local side of mp3 is port 0, not port 1. |
| 383 scoped_refptr<IncomingEndpoint> incoming_endpoint = | 383 RefPtr<IncomingEndpoint> incoming_endpoint = |
| 384 channels(1)->DeserializeEndpoint(received_endpoint_info.get()); | 384 channels(1)->DeserializeEndpoint(received_endpoint_info.get()); |
| 385 ASSERT_TRUE(incoming_endpoint); | 385 ASSERT_TRUE(incoming_endpoint); |
| 386 scoped_refptr<MessagePipe> mp3 = incoming_endpoint->ConvertToMessagePipe(); | 386 RefPtr<MessagePipe> mp3 = incoming_endpoint->ConvertToMessagePipe(); |
| 387 ASSERT_TRUE(mp3); | 387 ASSERT_TRUE(mp3); |
| 388 | 388 |
| 389 // Write: MP 2, port 0 -> MP 3, port 1. | 389 // Write: MP 2, port 0 -> MP 3, port 1. |
| 390 | 390 |
| 391 waiter.Init(); | 391 waiter.Init(); |
| 392 ASSERT_EQ( | 392 ASSERT_EQ( |
| 393 MOJO_RESULT_OK, | 393 MOJO_RESULT_OK, |
| 394 mp3->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); | 394 mp3->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); |
| 395 | 395 |
| 396 EXPECT_EQ( | 396 EXPECT_EQ( |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 490 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 491 Waiter waiter; | 491 Waiter waiter; |
| 492 HandleSignalsState hss; | 492 HandleSignalsState hss; |
| 493 uint32_t context = 0; | 493 uint32_t context = 0; |
| 494 | 494 |
| 495 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 495 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
| 496 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 496 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
| 497 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 497 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
| 498 | 498 |
| 499 RefPtr<ChannelEndpoint> ep0; | 499 RefPtr<ChannelEndpoint> ep0; |
| 500 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 500 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 501 | 501 |
| 502 // Write to MP 0, port 0. | 502 // Write to MP 0, port 0. |
| 503 EXPECT_EQ( | 503 EXPECT_EQ( |
| 504 MOJO_RESULT_OK, | 504 MOJO_RESULT_OK, |
| 505 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 505 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), |
| 506 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 506 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 507 | 507 |
| 508 // Close MP 0, port 0 before it's even been attached to the channel and run. | 508 // Close MP 0, port 0 before it's even been attached to the channel and run. |
| 509 mp0->Close(0); | 509 mp0->Close(0); |
| 510 | 510 |
| 511 BootstrapChannelEndpointNoWait(0, std::move(ep0)); | 511 BootstrapChannelEndpointNoWait(0, std::move(ep0)); |
| 512 | 512 |
| 513 RefPtr<ChannelEndpoint> ep1; | 513 RefPtr<ChannelEndpoint> ep1; |
| 514 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 514 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 515 | 515 |
| 516 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 516 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 517 // it later, it might already be readable.) | 517 // it later, it might already be readable.) |
| 518 waiter.Init(); | 518 waiter.Init(); |
| 519 ASSERT_EQ( | 519 ASSERT_EQ( |
| 520 MOJO_RESULT_OK, | 520 MOJO_RESULT_OK, |
| 521 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 521 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 522 | 522 |
| 523 BootstrapChannelEndpointNoWait(1, std::move(ep1)); | 523 BootstrapChannelEndpointNoWait(1, std::move(ep1)); |
| 524 | 524 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 552 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 552 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 553 Waiter waiter; | 553 Waiter waiter; |
| 554 HandleSignalsState hss; | 554 HandleSignalsState hss; |
| 555 uint32_t context = 0; | 555 uint32_t context = 0; |
| 556 | 556 |
| 557 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 557 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
| 558 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 558 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
| 559 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 559 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
| 560 | 560 |
| 561 RefPtr<ChannelEndpoint> ep0; | 561 RefPtr<ChannelEndpoint> ep0; |
| 562 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 562 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 563 | 563 |
| 564 // Write to MP 0, port 0. | 564 // Write to MP 0, port 0. |
| 565 EXPECT_EQ( | 565 EXPECT_EQ( |
| 566 MOJO_RESULT_OK, | 566 MOJO_RESULT_OK, |
| 567 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 567 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), |
| 568 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 568 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 569 | 569 |
| 570 BootstrapChannelEndpointNoWait(0, std::move(ep0)); | 570 BootstrapChannelEndpointNoWait(0, std::move(ep0)); |
| 571 | 571 |
| 572 // Close MP 0, port 0 before channel 1 is even connected. | 572 // Close MP 0, port 0 before channel 1 is even connected. |
| 573 mp0->Close(0); | 573 mp0->Close(0); |
| 574 | 574 |
| 575 RefPtr<ChannelEndpoint> ep1; | 575 RefPtr<ChannelEndpoint> ep1; |
| 576 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 576 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 577 | 577 |
| 578 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 578 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 579 // it later, it might already be readable.) | 579 // it later, it might already be readable.) |
| 580 waiter.Init(); | 580 waiter.Init(); |
| 581 ASSERT_EQ( | 581 ASSERT_EQ( |
| 582 MOJO_RESULT_OK, | 582 MOJO_RESULT_OK, |
| 583 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 583 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 584 | 584 |
| 585 BootstrapChannelEndpointNoWait(1, std::move(ep1)); | 585 BootstrapChannelEndpointNoWait(1, std::move(ep1)); |
| 586 | 586 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 608 mp1->Close(1); | 608 mp1->Close(1); |
| 609 } | 609 } |
| 610 | 610 |
| 611 TEST_F(RemoteMessagePipeTest, HandlePassing) { | 611 TEST_F(RemoteMessagePipeTest, HandlePassing) { |
| 612 static const char kHello[] = "hello"; | 612 static const char kHello[] = "hello"; |
| 613 Waiter waiter; | 613 Waiter waiter; |
| 614 HandleSignalsState hss; | 614 HandleSignalsState hss; |
| 615 uint32_t context = 0; | 615 uint32_t context = 0; |
| 616 | 616 |
| 617 RefPtr<ChannelEndpoint> ep0; | 617 RefPtr<ChannelEndpoint> ep0; |
| 618 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 618 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 619 RefPtr<ChannelEndpoint> ep1; | 619 RefPtr<ChannelEndpoint> ep1; |
| 620 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 620 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 621 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 621 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 622 | 622 |
| 623 // We'll try to pass this dispatcher. | 623 // We'll try to pass this dispatcher. |
| 624 scoped_refptr<MessagePipeDispatcher> dispatcher = | 624 scoped_refptr<MessagePipeDispatcher> dispatcher = |
| 625 MessagePipeDispatcher::Create( | 625 MessagePipeDispatcher::Create( |
| 626 MessagePipeDispatcher::kDefaultCreateOptions); | 626 MessagePipeDispatcher::kDefaultCreateOptions); |
| 627 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); | 627 auto local_mp = MessagePipe::CreateLocalLocal(); |
| 628 dispatcher->Init(local_mp, 0); | 628 dispatcher->Init(local_mp.Clone(), 0); |
| 629 | 629 |
| 630 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 630 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 631 // it later, it might already be readable.) | 631 // it later, it might already be readable.) |
| 632 waiter.Init(); | 632 waiter.Init(); |
| 633 ASSERT_EQ( | 633 ASSERT_EQ( |
| 634 MOJO_RESULT_OK, | 634 MOJO_RESULT_OK, |
| 635 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 635 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 636 | 636 |
| 637 // Write to MP 0, port 0. | 637 // Write to MP 0, port 0. |
| 638 { | 638 { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 static const char kHello[] = "hello"; | 762 static const char kHello[] = "hello"; |
| 763 static const char kWorld[] = "world!"; | 763 static const char kWorld[] = "world!"; |
| 764 Waiter waiter; | 764 Waiter waiter; |
| 765 HandleSignalsState hss; | 765 HandleSignalsState hss; |
| 766 uint32_t context = 0; | 766 uint32_t context = 0; |
| 767 | 767 |
| 768 // We'll try to pass this dispatcher. | 768 // We'll try to pass this dispatcher. |
| 769 scoped_refptr<MessagePipeDispatcher> dispatcher = | 769 scoped_refptr<MessagePipeDispatcher> dispatcher = |
| 770 MessagePipeDispatcher::Create( | 770 MessagePipeDispatcher::Create( |
| 771 MessagePipeDispatcher::kDefaultCreateOptions); | 771 MessagePipeDispatcher::kDefaultCreateOptions); |
| 772 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); | 772 auto local_mp = MessagePipe::CreateLocalLocal(); |
| 773 dispatcher->Init(local_mp, 0); | 773 dispatcher->Init(local_mp.Clone(), 0); |
| 774 | 774 |
| 775 hss = local_mp->GetHandleSignalsState(0); | 775 hss = local_mp->GetHandleSignalsState(0); |
| 776 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 776 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
| 777 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 777 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
| 778 // Write to the other end (|local_mp|, port 1), and then close it. | 778 // Write to the other end (|local_mp|, port 1), and then close it. |
| 779 EXPECT_EQ( | 779 EXPECT_EQ( |
| 780 MOJO_RESULT_OK, | 780 MOJO_RESULT_OK, |
| 781 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello), | 781 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello), |
| 782 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 782 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 783 hss = local_mp->GetHandleSignalsState(0); | 783 hss = local_mp->GetHandleSignalsState(0); |
| 784 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 784 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
| 785 hss.satisfied_signals); | 785 hss.satisfied_signals); |
| 786 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 786 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
| 787 // Then the second message.... | 787 // Then the second message.... |
| 788 EXPECT_EQ( | 788 EXPECT_EQ( |
| 789 MOJO_RESULT_OK, | 789 MOJO_RESULT_OK, |
| 790 local_mp->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld), | 790 local_mp->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld), |
| 791 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 791 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 792 hss = local_mp->GetHandleSignalsState(0); | 792 hss = local_mp->GetHandleSignalsState(0); |
| 793 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 793 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
| 794 hss.satisfied_signals); | 794 hss.satisfied_signals); |
| 795 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 795 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
| 796 // Then close it. | 796 // Then close it. |
| 797 local_mp->Close(1); | 797 local_mp->Close(1); |
| 798 | 798 |
| 799 RefPtr<ChannelEndpoint> ep0; | 799 RefPtr<ChannelEndpoint> ep0; |
| 800 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 800 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 801 RefPtr<ChannelEndpoint> ep1; | 801 RefPtr<ChannelEndpoint> ep1; |
| 802 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 802 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 803 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 803 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 804 | 804 |
| 805 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 805 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 806 // it later, it might already be readable.) | 806 // it later, it might already be readable.) |
| 807 waiter.Init(); | 807 waiter.Init(); |
| 808 ASSERT_EQ( | 808 ASSERT_EQ( |
| 809 MOJO_RESULT_OK, | 809 MOJO_RESULT_OK, |
| 810 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 810 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 811 | 811 |
| 812 // Write to MP 0, port 0. | 812 // Write to MP 0, port 0. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 899 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 900 } | 900 } |
| 901 | 901 |
| 902 TEST_F(RemoteMessagePipeTest, SharedBufferPassing) { | 902 TEST_F(RemoteMessagePipeTest, SharedBufferPassing) { |
| 903 static const char kHello[] = "hello"; | 903 static const char kHello[] = "hello"; |
| 904 Waiter waiter; | 904 Waiter waiter; |
| 905 HandleSignalsState hss; | 905 HandleSignalsState hss; |
| 906 uint32_t context = 0; | 906 uint32_t context = 0; |
| 907 | 907 |
| 908 RefPtr<ChannelEndpoint> ep0; | 908 RefPtr<ChannelEndpoint> ep0; |
| 909 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 909 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 910 RefPtr<ChannelEndpoint> ep1; | 910 RefPtr<ChannelEndpoint> ep1; |
| 911 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 911 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 912 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 912 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 913 | 913 |
| 914 // We'll try to pass this dispatcher. | 914 // We'll try to pass this dispatcher. |
| 915 scoped_refptr<SharedBufferDispatcher> dispatcher; | 915 scoped_refptr<SharedBufferDispatcher> dispatcher; |
| 916 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create( | 916 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create( |
| 917 platform_support(), | 917 platform_support(), |
| 918 SharedBufferDispatcher::kDefaultCreateOptions, | 918 SharedBufferDispatcher::kDefaultCreateOptions, |
| 919 100, &dispatcher)); | 919 100, &dispatcher)); |
| 920 ASSERT_TRUE(dispatcher); | 920 ASSERT_TRUE(dispatcher); |
| 921 | 921 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 TEST_F(RemoteMessagePipeTest, PlatformHandlePassing) { | 1020 TEST_F(RemoteMessagePipeTest, PlatformHandlePassing) { |
| 1021 mojo::test::ScopedTestDir test_dir; | 1021 mojo::test::ScopedTestDir test_dir; |
| 1022 | 1022 |
| 1023 static const char kHello[] = "hello"; | 1023 static const char kHello[] = "hello"; |
| 1024 static const char kWorld[] = "world"; | 1024 static const char kWorld[] = "world"; |
| 1025 Waiter waiter; | 1025 Waiter waiter; |
| 1026 uint32_t context = 0; | 1026 uint32_t context = 0; |
| 1027 HandleSignalsState hss; | 1027 HandleSignalsState hss; |
| 1028 | 1028 |
| 1029 RefPtr<ChannelEndpoint> ep0; | 1029 RefPtr<ChannelEndpoint> ep0; |
| 1030 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 1030 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 1031 RefPtr<ChannelEndpoint> ep1; | 1031 RefPtr<ChannelEndpoint> ep1; |
| 1032 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 1032 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 1033 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 1033 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 1034 | 1034 |
| 1035 util::ScopedFILE fp(test_dir.CreateFile()); | 1035 util::ScopedFILE fp(test_dir.CreateFile()); |
| 1036 EXPECT_EQ(sizeof(kHello), fwrite(kHello, 1, sizeof(kHello), fp.get())); | 1036 EXPECT_EQ(sizeof(kHello), fwrite(kHello, 1, sizeof(kHello), fp.get())); |
| 1037 // We'll try to pass this dispatcher, which will cause a |PlatformHandle| to | 1037 // We'll try to pass this dispatcher, which will cause a |PlatformHandle| to |
| 1038 // be passed. | 1038 // be passed. |
| 1039 scoped_refptr<PlatformHandleDispatcher> dispatcher = | 1039 scoped_refptr<PlatformHandleDispatcher> dispatcher = |
| 1040 PlatformHandleDispatcher::Create( | 1040 PlatformHandleDispatcher::Create( |
| 1041 mojo::test::PlatformHandleFromFILE(fp.Pass())); | 1041 mojo::test::PlatformHandleFromFILE(fp.Pass())); |
| 1042 | 1042 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 // Test racing closes (on each end). | 1119 // Test racing closes (on each end). |
| 1120 // Note: A flaky failure would almost certainly indicate a problem in the code | 1120 // Note: A flaky failure would almost certainly indicate a problem in the code |
| 1121 // itself (not in the test). Also, any logged warnings/errors would also | 1121 // itself (not in the test). Also, any logged warnings/errors would also |
| 1122 // probably be indicative of bugs. | 1122 // probably be indicative of bugs. |
| 1123 TEST_F(RemoteMessagePipeTest, RacingClosesStress) { | 1123 TEST_F(RemoteMessagePipeTest, RacingClosesStress) { |
| 1124 MojoDeadline delay = test::DeadlineFromMilliseconds(5); | 1124 MojoDeadline delay = test::DeadlineFromMilliseconds(5); |
| 1125 | 1125 |
| 1126 for (unsigned i = 0; i < 256; i++) { | 1126 for (unsigned i = 0; i < 256; i++) { |
| 1127 DVLOG(2) << "---------------------------------------- " << i; | 1127 DVLOG(2) << "---------------------------------------- " << i; |
| 1128 RefPtr<ChannelEndpoint> ep0; | 1128 RefPtr<ChannelEndpoint> ep0; |
| 1129 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 1129 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 1130 BootstrapChannelEndpointNoWait(0, std::move(ep0)); | 1130 BootstrapChannelEndpointNoWait(0, std::move(ep0)); |
| 1131 | 1131 |
| 1132 RefPtr<ChannelEndpoint> ep1; | 1132 RefPtr<ChannelEndpoint> ep1; |
| 1133 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 1133 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 1134 BootstrapChannelEndpointNoWait(1, std::move(ep1)); | 1134 BootstrapChannelEndpointNoWait(1, std::move(ep1)); |
| 1135 | 1135 |
| 1136 if (i & 1u) { | 1136 if (i & 1u) { |
| 1137 io_thread()->task_runner()->PostTask(FROM_HERE, | 1137 io_thread()->task_runner()->PostTask(FROM_HERE, |
| 1138 base::Bind(&test::Sleep, delay)); | 1138 base::Bind(&test::Sleep, delay)); |
| 1139 } | 1139 } |
| 1140 if (i & 2u) | 1140 if (i & 2u) |
| 1141 test::Sleep(delay); | 1141 test::Sleep(delay); |
| 1142 | 1142 |
| 1143 mp0->Close(0); | 1143 mp0->Close(0); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1159 // passing that end back. | 1159 // passing that end back. |
| 1160 // TODO(vtl): Also test passing a message pipe across two remote message pipes. | 1160 // TODO(vtl): Also test passing a message pipe across two remote message pipes. |
| 1161 TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) { | 1161 TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) { |
| 1162 static const char kHello[] = "hello"; | 1162 static const char kHello[] = "hello"; |
| 1163 static const char kWorld[] = "world"; | 1163 static const char kWorld[] = "world"; |
| 1164 Waiter waiter; | 1164 Waiter waiter; |
| 1165 HandleSignalsState hss; | 1165 HandleSignalsState hss; |
| 1166 uint32_t context = 0; | 1166 uint32_t context = 0; |
| 1167 | 1167 |
| 1168 RefPtr<ChannelEndpoint> ep0; | 1168 RefPtr<ChannelEndpoint> ep0; |
| 1169 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 1169 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 1170 RefPtr<ChannelEndpoint> ep1; | 1170 RefPtr<ChannelEndpoint> ep1; |
| 1171 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 1171 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 1172 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 1172 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 1173 | 1173 |
| 1174 // We'll try to pass this dispatcher. | 1174 // We'll try to pass this dispatcher. |
| 1175 scoped_refptr<MessagePipeDispatcher> dispatcher = | 1175 scoped_refptr<MessagePipeDispatcher> dispatcher = |
| 1176 MessagePipeDispatcher::Create( | 1176 MessagePipeDispatcher::Create( |
| 1177 MessagePipeDispatcher::kDefaultCreateOptions); | 1177 MessagePipeDispatcher::kDefaultCreateOptions); |
| 1178 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); | 1178 auto local_mp = MessagePipe::CreateLocalLocal(); |
| 1179 dispatcher->Init(local_mp, 0); | 1179 dispatcher->Init(local_mp.Clone(), 0); |
| 1180 | 1180 |
| 1181 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 1181 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 1182 // it later, it might already be readable.) | 1182 // it later, it might already be readable.) |
| 1183 waiter.Init(); | 1183 waiter.Init(); |
| 1184 ASSERT_EQ( | 1184 ASSERT_EQ( |
| 1185 MOJO_RESULT_OK, | 1185 MOJO_RESULT_OK, |
| 1186 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 1186 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 1187 | 1187 |
| 1188 // Write to MP 0, port 0. | 1188 // Write to MP 0, port 0. |
| 1189 { | 1189 { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 mp0->Close(0); | 1360 mp0->Close(0); |
| 1361 mp1->Close(1); | 1361 mp1->Close(1); |
| 1362 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1362 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 1363 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 1363 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
| 1364 local_mp->Close(1); | 1364 local_mp->Close(1); |
| 1365 } | 1365 } |
| 1366 | 1366 |
| 1367 } // namespace | 1367 } // namespace |
| 1368 } // namespace system | 1368 } // namespace system |
| 1369 } // namespace mojo | 1369 } // namespace mojo |
| OLD | NEW |