| 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 virtual void TearDown() OVERRIDE { | 55 virtual void TearDown() OVERRIDE { |
| 56 io_thread_.PostTaskAndWait( | 56 io_thread_.PostTaskAndWait( |
| 57 FROM_HERE, | 57 FROM_HERE, |
| 58 base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread, | 58 base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread, |
| 59 base::Unretained(this))); | 59 base::Unretained(this))); |
| 60 } | 60 } |
| 61 | 61 |
| 62 protected: | 62 protected: |
| 63 // This connects MP 0, port 1 and MP 1, port 0 (leaving MP 0, port 0 and MP 1, | 63 // This connects the two given |ChannelEndpoint|s. |
| 64 // port 1 as the user-visible endpoints) to channel 0 and 1, respectively. MP | 64 void ConnectChannelEndpoints(scoped_refptr<ChannelEndpoint> ep0, |
| 65 // 0, port 1 and MP 1, port 0 must have |ProxyMessagePipeEndpoint|s. | 65 scoped_refptr<ChannelEndpoint> ep1) { |
| 66 void ConnectMessagePipes(scoped_refptr<MessagePipe> mp0, | |
| 67 scoped_refptr<MessagePipe> mp1) { | |
| 68 io_thread_.PostTaskAndWait( | 66 io_thread_.PostTaskAndWait( |
| 69 FROM_HERE, | 67 FROM_HERE, |
| 70 base::Bind(&RemoteMessagePipeTest::ConnectMessagePipesOnIOThread, | 68 base::Bind(&RemoteMessagePipeTest::ConnectChannelEndpointsOnIOThread, |
| 71 base::Unretained(this), | 69 base::Unretained(this), |
| 72 mp0, | 70 ep0, |
| 73 mp1)); | 71 ep1)); |
| 74 } | 72 } |
| 75 | 73 |
| 76 // This connects |mp|'s port |channel_index ^ 1| to channel |channel_index|. | 74 // This bootstraps |ep| on |channels_[channel_index]|. It assumes/requires |
| 77 // It assumes/requires that this is the bootstrap case, i.e., that the | 75 // that this is the bootstrap case, i.e., that the endpoint IDs are both/will |
| 78 // endpoint IDs are both/will both be |Channel::kBootstrapEndpointId|. This | 76 // both be |Channel::kBootstrapEndpointId|. This returns *without* waiting for |
| 79 // returns *without* waiting for it to finish connecting. | 77 // it to finish connecting. |
| 80 void BootstrapMessagePipeNoWait(unsigned channel_index, | 78 void BootstrapChannelEndpointNoWait(unsigned channel_index, |
| 81 scoped_refptr<MessagePipe> mp) { | 79 scoped_refptr<ChannelEndpoint> ep) { |
| 82 io_thread_.PostTask( | 80 io_thread_.PostTask( |
| 83 FROM_HERE, | 81 FROM_HERE, |
| 84 base::Bind(&RemoteMessagePipeTest::BootstrapMessagePipeOnIOThread, | 82 base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointOnIOThread, |
| 85 base::Unretained(this), | 83 base::Unretained(this), |
| 86 channel_index, | 84 channel_index, |
| 87 mp)); | 85 ep)); |
| 88 } | 86 } |
| 89 | 87 |
| 90 void RestoreInitialState() { | 88 void RestoreInitialState() { |
| 91 io_thread_.PostTaskAndWait( | 89 io_thread_.PostTaskAndWait( |
| 92 FROM_HERE, | 90 FROM_HERE, |
| 93 base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread, | 91 base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread, |
| 94 base::Unretained(this))); | 92 base::Unretained(this))); |
| 95 } | 93 } |
| 96 | 94 |
| 97 embedder::PlatformSupport* platform_support() { return &platform_support_; } | 95 embedder::PlatformSupport* platform_support() { return &platform_support_; } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 122 void CreateAndInitChannel(unsigned channel_index) { | 120 void CreateAndInitChannel(unsigned channel_index) { |
| 123 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 121 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
| 124 CHECK(channel_index == 0 || channel_index == 1); | 122 CHECK(channel_index == 0 || channel_index == 1); |
| 125 CHECK(!channels_[channel_index].get()); | 123 CHECK(!channels_[channel_index].get()); |
| 126 | 124 |
| 127 channels_[channel_index] = new Channel(&platform_support_); | 125 channels_[channel_index] = new Channel(&platform_support_); |
| 128 CHECK(channels_[channel_index]->Init( | 126 CHECK(channels_[channel_index]->Init( |
| 129 RawChannel::Create(platform_handles_[channel_index].Pass()))); | 127 RawChannel::Create(platform_handles_[channel_index].Pass()))); |
| 130 } | 128 } |
| 131 | 129 |
| 132 void ConnectMessagePipesOnIOThread(scoped_refptr<MessagePipe> mp0, | 130 void ConnectChannelEndpointsOnIOThread(scoped_refptr<ChannelEndpoint> ep0, |
| 133 scoped_refptr<MessagePipe> mp1) { | 131 scoped_refptr<ChannelEndpoint> ep1) { |
| 134 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 132 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
| 135 | 133 |
| 136 if (!channels_[0].get()) | 134 if (!channels_[0].get()) |
| 137 CreateAndInitChannel(0); | 135 CreateAndInitChannel(0); |
| 138 if (!channels_[1].get()) | 136 if (!channels_[1].get()) |
| 139 CreateAndInitChannel(1); | 137 CreateAndInitChannel(1); |
| 140 | 138 |
| 141 MessageInTransit::EndpointId local_id0 = channels_[0]->AttachEndpoint( | 139 MessageInTransit::EndpointId local_id0 = channels_[0]->AttachEndpoint(ep0); |
| 142 make_scoped_refptr(new ChannelEndpoint(mp0.get(), 1))); | 140 MessageInTransit::EndpointId local_id1 = channels_[1]->AttachEndpoint(ep1); |
| 143 MessageInTransit::EndpointId local_id1 = channels_[1]->AttachEndpoint( | |
| 144 make_scoped_refptr(new ChannelEndpoint(mp1.get(), 0))); | |
| 145 | 141 |
| 146 CHECK(channels_[0]->RunMessagePipeEndpoint(local_id0, local_id1)); | 142 CHECK(channels_[0]->RunMessagePipeEndpoint(local_id0, local_id1)); |
| 147 CHECK(channels_[1]->RunMessagePipeEndpoint(local_id1, local_id0)); | 143 CHECK(channels_[1]->RunMessagePipeEndpoint(local_id1, local_id0)); |
| 148 } | 144 } |
| 149 | 145 |
| 150 void BootstrapMessagePipeOnIOThread(unsigned channel_index, | 146 void BootstrapChannelEndpointOnIOThread(unsigned channel_index, |
| 151 scoped_refptr<MessagePipe> mp) { | 147 scoped_refptr<ChannelEndpoint> ep) { |
| 152 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 148 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
| 153 CHECK(channel_index == 0 || channel_index == 1); | 149 CHECK(channel_index == 0 || channel_index == 1); |
| 154 | 150 |
| 155 unsigned port = channel_index ^ 1u; | |
| 156 | |
| 157 CreateAndInitChannel(channel_index); | 151 CreateAndInitChannel(channel_index); |
| 158 MessageInTransit::EndpointId endpoint_id = | 152 MessageInTransit::EndpointId endpoint_id = |
| 159 channels_[channel_index]->AttachEndpoint( | 153 channels_[channel_index]->AttachEndpoint(ep); |
| 160 make_scoped_refptr(new ChannelEndpoint(mp.get(), port))); | |
| 161 if (endpoint_id == MessageInTransit::kInvalidEndpointId) | 154 if (endpoint_id == MessageInTransit::kInvalidEndpointId) |
| 162 return; | 155 return; |
| 163 | 156 |
| 164 CHECK_EQ(endpoint_id, Channel::kBootstrapEndpointId); | 157 CHECK_EQ(endpoint_id, Channel::kBootstrapEndpointId); |
| 165 CHECK(channels_[channel_index]->RunMessagePipeEndpoint( | 158 CHECK(channels_[channel_index]->RunMessagePipeEndpoint( |
| 166 Channel::kBootstrapEndpointId, Channel::kBootstrapEndpointId)); | 159 Channel::kBootstrapEndpointId, Channel::kBootstrapEndpointId)); |
| 167 } | 160 } |
| 168 | 161 |
| 169 void RestoreInitialStateOnIOThread() { | 162 void RestoreInitialStateOnIOThread() { |
| 170 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 163 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 187 char buffer[100] = {0}; | 180 char buffer[100] = {0}; |
| 188 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 181 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 189 Waiter waiter; | 182 Waiter waiter; |
| 190 HandleSignalsState hss; | 183 HandleSignalsState hss; |
| 191 uint32_t context = 0; | 184 uint32_t context = 0; |
| 192 | 185 |
| 193 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 186 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
| 194 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 187 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
| 195 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 188 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
| 196 | 189 |
| 197 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy()); | 190 scoped_refptr<ChannelEndpoint> ep0; |
| 198 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal()); | 191 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
| 199 ConnectMessagePipes(mp0, mp1); | 192 scoped_refptr<ChannelEndpoint> ep1; |
| 193 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
| 194 ConnectChannelEndpoints(ep0, ep1); |
| 200 | 195 |
| 201 // Write in one direction: MP 0, port 0 -> ... -> MP 1, port 1. | 196 // Write in one direction: MP 0, port 0 -> ... -> MP 1, port 1. |
| 202 | 197 |
| 203 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 198 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 204 // it later, it might already be readable.) | 199 // it later, it might already be readable.) |
| 205 waiter.Init(); | 200 waiter.Init(); |
| 206 ASSERT_EQ(MOJO_RESULT_OK, | 201 ASSERT_EQ(MOJO_RESULT_OK, |
| 207 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, NULL)); | 202 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, NULL)); |
| 208 | 203 |
| 209 // Write to MP 0, port 0. | 204 // Write to MP 0, port 0. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 static const char kHello[] = "hello"; | 291 static const char kHello[] = "hello"; |
| 297 static const char kWorld[] = "world!!!1!!!1!"; | 292 static const char kWorld[] = "world!!!1!!!1!"; |
| 298 char buffer[100] = {0}; | 293 char buffer[100] = {0}; |
| 299 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 294 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 300 Waiter waiter; | 295 Waiter waiter; |
| 301 HandleSignalsState hss; | 296 HandleSignalsState hss; |
| 302 uint32_t context = 0; | 297 uint32_t context = 0; |
| 303 | 298 |
| 304 // Connect message pipes as in the |Basic| test. | 299 // Connect message pipes as in the |Basic| test. |
| 305 | 300 |
| 306 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy()); | 301 scoped_refptr<ChannelEndpoint> ep0; |
| 307 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal()); | 302 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
| 308 ConnectMessagePipes(mp0, mp1); | 303 scoped_refptr<ChannelEndpoint> ep1; |
| 304 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
| 305 ConnectChannelEndpoints(ep0, ep1); |
| 309 | 306 |
| 310 // Now put another message pipe on the channel. | 307 // Now put another message pipe on the channel. |
| 311 | 308 |
| 312 scoped_refptr<MessagePipe> mp2(MessagePipe::CreateLocalProxy()); | 309 scoped_refptr<ChannelEndpoint> ep2; |
| 313 scoped_refptr<MessagePipe> mp3(MessagePipe::CreateProxyLocal()); | 310 scoped_refptr<MessagePipe> mp2(MessagePipe::CreateLocalProxy(&ep2)); |
| 314 ConnectMessagePipes(mp2, mp3); | 311 scoped_refptr<ChannelEndpoint> ep3; |
| 312 scoped_refptr<MessagePipe> mp3(MessagePipe::CreateProxyLocal(&ep3)); |
| 313 ConnectChannelEndpoints(ep2, ep3); |
| 315 | 314 |
| 316 // Write: MP 2, port 0 -> MP 3, port 1. | 315 // Write: MP 2, port 0 -> MP 3, port 1. |
| 317 | 316 |
| 318 waiter.Init(); | 317 waiter.Init(); |
| 319 ASSERT_EQ(MOJO_RESULT_OK, | 318 ASSERT_EQ(MOJO_RESULT_OK, |
| 320 mp3->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, NULL)); | 319 mp3->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, NULL)); |
| 321 | 320 |
| 322 EXPECT_EQ(MOJO_RESULT_OK, | 321 EXPECT_EQ(MOJO_RESULT_OK, |
| 323 mp2->WriteMessage(0, | 322 mp2->WriteMessage(0, |
| 324 UserPointer<const void>(kHello), | 323 UserPointer<const void>(kHello), |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 char buffer[100] = {0}; | 442 char buffer[100] = {0}; |
| 444 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 443 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 445 Waiter waiter; | 444 Waiter waiter; |
| 446 HandleSignalsState hss; | 445 HandleSignalsState hss; |
| 447 uint32_t context = 0; | 446 uint32_t context = 0; |
| 448 | 447 |
| 449 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 448 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
| 450 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 449 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
| 451 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 450 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
| 452 | 451 |
| 453 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy()); | 452 scoped_refptr<ChannelEndpoint> ep0; |
| 453 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
| 454 | 454 |
| 455 // Write to MP 0, port 0. | 455 // Write to MP 0, port 0. |
| 456 EXPECT_EQ(MOJO_RESULT_OK, | 456 EXPECT_EQ(MOJO_RESULT_OK, |
| 457 mp0->WriteMessage(0, | 457 mp0->WriteMessage(0, |
| 458 UserPointer<const void>(kHello), | 458 UserPointer<const void>(kHello), |
| 459 sizeof(kHello), | 459 sizeof(kHello), |
| 460 NULL, | 460 NULL, |
| 461 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 461 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 462 | 462 |
| 463 BootstrapMessagePipeNoWait(0, mp0); | 463 BootstrapChannelEndpointNoWait(0, ep0); |
| 464 | 464 |
| 465 // Close MP 0, port 0 before channel 1 is even connected. | 465 // Close MP 0, port 0 before channel 1 is even connected. |
| 466 mp0->Close(0); | 466 mp0->Close(0); |
| 467 | 467 |
| 468 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal()); | 468 scoped_refptr<ChannelEndpoint> ep1; |
| 469 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
| 469 | 470 |
| 470 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 471 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 471 // it later, it might already be readable.) | 472 // it later, it might already be readable.) |
| 472 waiter.Init(); | 473 waiter.Init(); |
| 473 ASSERT_EQ(MOJO_RESULT_OK, | 474 ASSERT_EQ(MOJO_RESULT_OK, |
| 474 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, NULL)); | 475 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, NULL)); |
| 475 | 476 |
| 476 BootstrapMessagePipeNoWait(1, mp1); | 477 BootstrapChannelEndpointNoWait(1, ep1); |
| 477 | 478 |
| 478 // Wait. | 479 // Wait. |
| 479 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 480 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
| 480 EXPECT_EQ(123u, context); | 481 EXPECT_EQ(123u, context); |
| 481 hss = HandleSignalsState(); | 482 hss = HandleSignalsState(); |
| 482 // Note: MP 1, port 1 should definitely should be readable, but it may or may | 483 // Note: MP 1, port 1 should definitely should be readable, but it may or may |
| 483 // not appear as writable (there's a race, and it may not have noticed that | 484 // not appear as writable (there's a race, and it may not have noticed that |
| 484 // the other side was closed yet -- e.g., inserting a sleep here would make it | 485 // the other side was closed yet -- e.g., inserting a sleep here would make it |
| 485 // much more likely to notice that it's no longer writable). | 486 // much more likely to notice that it's no longer writable). |
| 486 mp1->RemoveWaiter(1, &waiter, &hss); | 487 mp1->RemoveWaiter(1, &waiter, &hss); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 501 // And MP 1, port 1. | 502 // And MP 1, port 1. |
| 502 mp1->Close(1); | 503 mp1->Close(1); |
| 503 } | 504 } |
| 504 | 505 |
| 505 TEST_F(RemoteMessagePipeTest, HandlePassing) { | 506 TEST_F(RemoteMessagePipeTest, HandlePassing) { |
| 506 static const char kHello[] = "hello"; | 507 static const char kHello[] = "hello"; |
| 507 Waiter waiter; | 508 Waiter waiter; |
| 508 HandleSignalsState hss; | 509 HandleSignalsState hss; |
| 509 uint32_t context = 0; | 510 uint32_t context = 0; |
| 510 | 511 |
| 511 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy()); | 512 scoped_refptr<ChannelEndpoint> ep0; |
| 512 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal()); | 513 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
| 513 ConnectMessagePipes(mp0, mp1); | 514 scoped_refptr<ChannelEndpoint> ep1; |
| 515 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
| 516 ConnectChannelEndpoints(ep0, ep1); |
| 514 | 517 |
| 515 // We'll try to pass this dispatcher. | 518 // We'll try to pass this dispatcher. |
| 516 scoped_refptr<MessagePipeDispatcher> dispatcher( | 519 scoped_refptr<MessagePipeDispatcher> dispatcher( |
| 517 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); | 520 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); |
| 518 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); | 521 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); |
| 519 dispatcher->Init(local_mp, 0); | 522 dispatcher->Init(local_mp, 0); |
| 520 | 523 |
| 521 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 524 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 522 // it later, it might already be readable.) | 525 // it later, it might already be readable.) |
| 523 waiter.Init(); | 526 waiter.Init(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 #else | 672 #else |
| 670 // Not yet implemented (on Windows). | 673 // Not yet implemented (on Windows). |
| 671 #define MAYBE_SharedBufferPassing DISABLED_SharedBufferPassing | 674 #define MAYBE_SharedBufferPassing DISABLED_SharedBufferPassing |
| 672 #endif | 675 #endif |
| 673 TEST_F(RemoteMessagePipeTest, MAYBE_SharedBufferPassing) { | 676 TEST_F(RemoteMessagePipeTest, MAYBE_SharedBufferPassing) { |
| 674 static const char kHello[] = "hello"; | 677 static const char kHello[] = "hello"; |
| 675 Waiter waiter; | 678 Waiter waiter; |
| 676 HandleSignalsState hss; | 679 HandleSignalsState hss; |
| 677 uint32_t context = 0; | 680 uint32_t context = 0; |
| 678 | 681 |
| 679 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy()); | 682 scoped_refptr<ChannelEndpoint> ep0; |
| 680 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal()); | 683 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
| 681 ConnectMessagePipes(mp0, mp1); | 684 scoped_refptr<ChannelEndpoint> ep1; |
| 685 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
| 686 ConnectChannelEndpoints(ep0, ep1); |
| 682 | 687 |
| 683 // We'll try to pass this dispatcher. | 688 // We'll try to pass this dispatcher. |
| 684 scoped_refptr<SharedBufferDispatcher> dispatcher; | 689 scoped_refptr<SharedBufferDispatcher> dispatcher; |
| 685 EXPECT_EQ(MOJO_RESULT_OK, | 690 EXPECT_EQ(MOJO_RESULT_OK, |
| 686 SharedBufferDispatcher::Create( | 691 SharedBufferDispatcher::Create( |
| 687 platform_support(), | 692 platform_support(), |
| 688 SharedBufferDispatcher::kDefaultCreateOptions, | 693 SharedBufferDispatcher::kDefaultCreateOptions, |
| 689 100, | 694 100, |
| 690 &dispatcher)); | 695 &dispatcher)); |
| 691 ASSERT_TRUE(dispatcher.get()); | 696 ASSERT_TRUE(dispatcher.get()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 TEST_F(RemoteMessagePipeTest, MAYBE_PlatformHandlePassing) { | 808 TEST_F(RemoteMessagePipeTest, MAYBE_PlatformHandlePassing) { |
| 804 base::ScopedTempDir temp_dir; | 809 base::ScopedTempDir temp_dir; |
| 805 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 810 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 806 | 811 |
| 807 static const char kHello[] = "hello"; | 812 static const char kHello[] = "hello"; |
| 808 static const char kWorld[] = "world"; | 813 static const char kWorld[] = "world"; |
| 809 Waiter waiter; | 814 Waiter waiter; |
| 810 uint32_t context = 0; | 815 uint32_t context = 0; |
| 811 HandleSignalsState hss; | 816 HandleSignalsState hss; |
| 812 | 817 |
| 813 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy()); | 818 scoped_refptr<ChannelEndpoint> ep0; |
| 814 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal()); | 819 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
| 815 ConnectMessagePipes(mp0, mp1); | 820 scoped_refptr<ChannelEndpoint> ep1; |
| 821 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
| 822 ConnectChannelEndpoints(ep0, ep1); |
| 816 | 823 |
| 817 base::FilePath unused; | 824 base::FilePath unused; |
| 818 base::ScopedFILE fp( | 825 base::ScopedFILE fp( |
| 819 CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); | 826 CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); |
| 820 EXPECT_EQ(sizeof(kHello), fwrite(kHello, 1, sizeof(kHello), fp.get())); | 827 EXPECT_EQ(sizeof(kHello), fwrite(kHello, 1, sizeof(kHello), fp.get())); |
| 821 // We'll try to pass this dispatcher, which will cause a |PlatformHandle| to | 828 // We'll try to pass this dispatcher, which will cause a |PlatformHandle| to |
| 822 // be passed. | 829 // be passed. |
| 823 scoped_refptr<PlatformHandleDispatcher> dispatcher( | 830 scoped_refptr<PlatformHandleDispatcher> dispatcher( |
| 824 new PlatformHandleDispatcher( | 831 new PlatformHandleDispatcher( |
| 825 mojo::test::PlatformHandleFromFILE(fp.Pass()))); | 832 mojo::test::PlatformHandleFromFILE(fp.Pass()))); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 | 913 |
| 907 // Test racing closes (on each end). | 914 // Test racing closes (on each end). |
| 908 // Note: A flaky failure would almost certainly indicate a problem in the code | 915 // Note: A flaky failure would almost certainly indicate a problem in the code |
| 909 // itself (not in the test). Also, any logged warnings/errors would also | 916 // itself (not in the test). Also, any logged warnings/errors would also |
| 910 // probably be indicative of bugs. | 917 // probably be indicative of bugs. |
| 911 TEST_F(RemoteMessagePipeTest, RacingClosesStress) { | 918 TEST_F(RemoteMessagePipeTest, RacingClosesStress) { |
| 912 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(5); | 919 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(5); |
| 913 | 920 |
| 914 for (unsigned i = 0; i < 256; i++) { | 921 for (unsigned i = 0; i < 256; i++) { |
| 915 DVLOG(2) << "---------------------------------------- " << i; | 922 DVLOG(2) << "---------------------------------------- " << i; |
| 916 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy()); | 923 scoped_refptr<ChannelEndpoint> ep0; |
| 917 BootstrapMessagePipeNoWait(0, mp0); | 924 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
| 925 BootstrapChannelEndpointNoWait(0, ep0); |
| 918 | 926 |
| 919 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal()); | 927 scoped_refptr<ChannelEndpoint> ep1; |
| 920 BootstrapMessagePipeNoWait(1, mp1); | 928 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
| 929 BootstrapChannelEndpointNoWait(1, ep1); |
| 921 | 930 |
| 922 if (i & 1u) { | 931 if (i & 1u) { |
| 923 io_thread()->task_runner()->PostTask( | 932 io_thread()->task_runner()->PostTask( |
| 924 FROM_HERE, base::Bind(&base::PlatformThread::Sleep, delay)); | 933 FROM_HERE, base::Bind(&base::PlatformThread::Sleep, delay)); |
| 925 } | 934 } |
| 926 if (i & 2u) | 935 if (i & 2u) |
| 927 base::PlatformThread::Sleep(delay); | 936 base::PlatformThread::Sleep(delay); |
| 928 | 937 |
| 929 mp0->Close(0); | 938 mp0->Close(0); |
| 930 | 939 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 944 // Tests passing an end of a message pipe over a remote message pipe, and then | 953 // Tests passing an end of a message pipe over a remote message pipe, and then |
| 945 // passing that end back. | 954 // passing that end back. |
| 946 // TODO(vtl): Also test passing a message pipe across two remote message pipes. | 955 // TODO(vtl): Also test passing a message pipe across two remote message pipes. |
| 947 TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) { | 956 TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) { |
| 948 static const char kHello[] = "hello"; | 957 static const char kHello[] = "hello"; |
| 949 static const char kWorld[] = "world"; | 958 static const char kWorld[] = "world"; |
| 950 Waiter waiter; | 959 Waiter waiter; |
| 951 HandleSignalsState hss; | 960 HandleSignalsState hss; |
| 952 uint32_t context = 0; | 961 uint32_t context = 0; |
| 953 | 962 |
| 954 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy()); | 963 scoped_refptr<ChannelEndpoint> ep0; |
| 955 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal()); | 964 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
| 956 ConnectMessagePipes(mp0, mp1); | 965 scoped_refptr<ChannelEndpoint> ep1; |
| 966 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
| 967 ConnectChannelEndpoints(ep0, ep1); |
| 957 | 968 |
| 958 // We'll try to pass this dispatcher. | 969 // We'll try to pass this dispatcher. |
| 959 scoped_refptr<MessagePipeDispatcher> dispatcher( | 970 scoped_refptr<MessagePipeDispatcher> dispatcher( |
| 960 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); | 971 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); |
| 961 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); | 972 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); |
| 962 dispatcher->Init(local_mp, 0); | 973 dispatcher->Init(local_mp, 0); |
| 963 | 974 |
| 964 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 975 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
| 965 // it later, it might already be readable.) | 976 // it later, it might already be readable.) |
| 966 waiter.Init(); | 977 waiter.Init(); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 mp0->Close(0); | 1173 mp0->Close(0); |
| 1163 mp1->Close(1); | 1174 mp1->Close(1); |
| 1164 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1175 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 1165 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 1176 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
| 1166 local_mp->Close(1); | 1177 local_mp->Close(1); |
| 1167 } | 1178 } |
| 1168 | 1179 |
| 1169 } // namespace | 1180 } // namespace |
| 1170 } // namespace system | 1181 } // namespace system |
| 1171 } // namespace mojo | 1182 } // namespace mojo |
| OLD | NEW |