| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
| 16 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/threading/platform_thread.h" // For |Sleep()|. | |
| 21 #include "build/build_config.h" // TODO(vtl): Remove this. | 20 #include "build/build_config.h" // TODO(vtl): Remove this. |
| 22 #include "mojo/common/test/multiprocess_test_helper.h" | |
| 23 #include "mojo/common/test/test_utils.h" | 21 #include "mojo/common/test/test_utils.h" |
| 24 #include "mojo/embedder/platform_shared_buffer.h" | 22 #include "mojo/embedder/platform_shared_buffer.h" |
| 25 #include "mojo/embedder/scoped_platform_handle.h" | 23 #include "mojo/embedder/scoped_platform_handle.h" |
| 26 #include "mojo/embedder/simple_platform_support.h" | |
| 27 #include "mojo/system/channel.h" | 24 #include "mojo/system/channel.h" |
| 28 #include "mojo/system/dispatcher.h" | 25 #include "mojo/system/dispatcher.h" |
| 29 #include "mojo/system/message_pipe.h" | 26 #include "mojo/system/message_pipe.h" |
| 27 #include "mojo/system/message_pipe_test_utils.h" |
| 30 #include "mojo/system/platform_handle_dispatcher.h" | 28 #include "mojo/system/platform_handle_dispatcher.h" |
| 31 #include "mojo/system/raw_channel.h" | 29 #include "mojo/system/raw_channel.h" |
| 32 #include "mojo/system/shared_buffer_dispatcher.h" | 30 #include "mojo/system/shared_buffer_dispatcher.h" |
| 33 #include "mojo/system/test_utils.h" | 31 #include "mojo/system/test_utils.h" |
| 34 #include "mojo/system/waiter.h" | |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 36 | 33 |
| 37 namespace mojo { | 34 namespace mojo { |
| 38 namespace system { | 35 namespace system { |
| 39 namespace { | 36 namespace { |
| 40 | 37 |
| 41 class ChannelThread { | 38 class MultiprocessMessagePipeTest |
| 42 public: | 39 : public test::MultiprocessMessagePipeTestBase {}; |
| 43 explicit ChannelThread(embedder::PlatformSupport* platform_support) | |
| 44 : platform_support_(platform_support), | |
| 45 test_io_thread_(test::TestIOThread::kManualStart) {} | |
| 46 ~ChannelThread() { Stop(); } | |
| 47 | |
| 48 void Start(embedder::ScopedPlatformHandle platform_handle, | |
| 49 scoped_refptr<MessagePipe> message_pipe) { | |
| 50 test_io_thread_.Start(); | |
| 51 test_io_thread_.PostTaskAndWait( | |
| 52 FROM_HERE, | |
| 53 base::Bind(&ChannelThread::InitChannelOnIOThread, | |
| 54 base::Unretained(this), | |
| 55 base::Passed(&platform_handle), | |
| 56 message_pipe)); | |
| 57 } | |
| 58 | |
| 59 void Stop() { | |
| 60 if (channel_.get()) { | |
| 61 // Hack to flush write buffers before quitting. | |
| 62 // TODO(vtl): Remove this once |Channel| has a | |
| 63 // |FlushWriteBufferAndShutdown()| (or whatever). | |
| 64 while (!channel_->IsWriteBufferEmpty()) | |
| 65 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); | |
| 66 | |
| 67 test_io_thread_.PostTaskAndWait( | |
| 68 FROM_HERE, | |
| 69 base::Bind(&ChannelThread::ShutdownChannelOnIOThread, | |
| 70 base::Unretained(this))); | |
| 71 } | |
| 72 test_io_thread_.Stop(); | |
| 73 } | |
| 74 | |
| 75 private: | |
| 76 void InitChannelOnIOThread(embedder::ScopedPlatformHandle platform_handle, | |
| 77 scoped_refptr<MessagePipe> message_pipe) { | |
| 78 CHECK_EQ(base::MessageLoop::current(), test_io_thread_.message_loop()); | |
| 79 CHECK(platform_handle.is_valid()); | |
| 80 | |
| 81 // Create and initialize |Channel|. | |
| 82 channel_ = new Channel(platform_support_); | |
| 83 CHECK(channel_->Init(RawChannel::Create(platform_handle.Pass()))); | |
| 84 | |
| 85 // Attach the message pipe endpoint. | |
| 86 // Note: On the "server" (parent process) side, we need not attach the | |
| 87 // message pipe endpoint immediately. However, on the "client" (child | |
| 88 // process) side, this *must* be done here -- otherwise, the |Channel| may | |
| 89 // receive/process messages (which it can do as soon as it's hooked up to | |
| 90 // the IO thread message loop, and that message loop runs) before the | |
| 91 // message pipe endpoint is attached. | |
| 92 CHECK_EQ(channel_->AttachMessagePipeEndpoint(message_pipe, 1), | |
| 93 Channel::kBootstrapEndpointId); | |
| 94 CHECK(channel_->RunMessagePipeEndpoint(Channel::kBootstrapEndpointId, | |
| 95 Channel::kBootstrapEndpointId)); | |
| 96 } | |
| 97 | |
| 98 void ShutdownChannelOnIOThread() { | |
| 99 CHECK(channel_.get()); | |
| 100 channel_->Shutdown(); | |
| 101 channel_ = NULL; | |
| 102 } | |
| 103 | |
| 104 embedder::PlatformSupport* const platform_support_; | |
| 105 test::TestIOThread test_io_thread_; | |
| 106 scoped_refptr<Channel> channel_; | |
| 107 | |
| 108 DISALLOW_COPY_AND_ASSIGN(ChannelThread); | |
| 109 }; | |
| 110 | |
| 111 class MultiprocessMessagePipeTest : public testing::Test { | |
| 112 public: | |
| 113 MultiprocessMessagePipeTest() : channel_thread_(&platform_support_) {} | |
| 114 virtual ~MultiprocessMessagePipeTest() {} | |
| 115 | |
| 116 protected: | |
| 117 void Init(scoped_refptr<MessagePipe> mp) { | |
| 118 channel_thread_.Start(helper_.server_platform_handle.Pass(), mp); | |
| 119 } | |
| 120 | |
| 121 embedder::PlatformSupport* platform_support() { return &platform_support_; } | |
| 122 mojo::test::MultiprocessTestHelper* helper() { return &helper_; } | |
| 123 | |
| 124 private: | |
| 125 embedder::SimplePlatformSupport platform_support_; | |
| 126 ChannelThread channel_thread_; | |
| 127 mojo::test::MultiprocessTestHelper helper_; | |
| 128 | |
| 129 DISALLOW_COPY_AND_ASSIGN(MultiprocessMessagePipeTest); | |
| 130 }; | |
| 131 | |
| 132 MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp, | |
| 133 MojoHandleSignals signals, | |
| 134 HandleSignalsState* signals_state) { | |
| 135 Waiter waiter; | |
| 136 waiter.Init(); | |
| 137 | |
| 138 MojoResult add_result = mp->AddWaiter(0, &waiter, signals, 0, signals_state); | |
| 139 if (add_result != MOJO_RESULT_OK) { | |
| 140 return (add_result == MOJO_RESULT_ALREADY_EXISTS) ? MOJO_RESULT_OK | |
| 141 : add_result; | |
| 142 } | |
| 143 | |
| 144 MojoResult wait_result = waiter.Wait(MOJO_DEADLINE_INDEFINITE, NULL); | |
| 145 mp->RemoveWaiter(0, &waiter, signals_state); | |
| 146 return wait_result; | |
| 147 } | |
| 148 | 40 |
| 149 // For each message received, sends a reply message with the same contents | 41 // For each message received, sends a reply message with the same contents |
| 150 // repeated twice, until the other end is closed or it receives "quitquitquit" | 42 // repeated twice, until the other end is closed or it receives "quitquitquit" |
| 151 // (which it doesn't reply to). It'll return the number of messages received, | 43 // (which it doesn't reply to). It'll return the number of messages received, |
| 152 // not including any "quitquitquit" message, modulo 100. | 44 // not including any "quitquitquit" message, modulo 100. |
| 153 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) { | 45 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) { |
| 154 embedder::SimplePlatformSupport platform_support; | 46 embedder::SimplePlatformSupport platform_support; |
| 155 ChannelThread channel_thread(&platform_support); | 47 test::ChannelThread channel_thread(&platform_support); |
| 156 embedder::ScopedPlatformHandle client_platform_handle = | 48 embedder::ScopedPlatformHandle client_platform_handle = |
| 157 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 49 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 158 CHECK(client_platform_handle.is_valid()); | 50 CHECK(client_platform_handle.is_valid()); |
| 159 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); | 51 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); |
| 160 channel_thread.Start(client_platform_handle.Pass(), mp); | 52 channel_thread.Start(client_platform_handle.Pass(), mp); |
| 161 | 53 |
| 162 const std::string quitquitquit("quitquitquit"); | 54 const std::string quitquitquit("quitquitquit"); |
| 163 int rv = 0; | 55 int rv = 0; |
| 164 for (;; rv = (rv + 1) % 100) { | 56 for (;; rv = (rv + 1) % 100) { |
| 165 // Wait for our end of the message pipe to be readable. | 57 // Wait for our end of the message pipe to be readable. |
| 166 HandleSignalsState hss; | 58 HandleSignalsState hss; |
| 167 MojoResult result = WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss); | 59 MojoResult result = |
| 60 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss); |
| 168 if (result != MOJO_RESULT_OK) { | 61 if (result != MOJO_RESULT_OK) { |
| 169 // It was closed, probably. | 62 // It was closed, probably. |
| 170 CHECK_EQ(result, MOJO_RESULT_FAILED_PRECONDITION); | 63 CHECK_EQ(result, MOJO_RESULT_FAILED_PRECONDITION); |
| 171 CHECK_EQ(hss.satisfied_signals, 0u); | 64 CHECK_EQ(hss.satisfied_signals, 0u); |
| 172 CHECK_EQ(hss.satisfiable_signals, 0u); | 65 CHECK_EQ(hss.satisfiable_signals, 0u); |
| 173 break; | 66 break; |
| 174 } else { | 67 } else { |
| 175 CHECK((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 68 CHECK((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
| 176 CHECK((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 69 CHECK((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
| 177 } | 70 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 std::string hello("hello"); | 109 std::string hello("hello"); |
| 217 EXPECT_EQ(MOJO_RESULT_OK, | 110 EXPECT_EQ(MOJO_RESULT_OK, |
| 218 mp->WriteMessage(0, | 111 mp->WriteMessage(0, |
| 219 UserPointer<const void>(hello.data()), | 112 UserPointer<const void>(hello.data()), |
| 220 static_cast<uint32_t>(hello.size()), | 113 static_cast<uint32_t>(hello.size()), |
| 221 NULL, | 114 NULL, |
| 222 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 115 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 223 | 116 |
| 224 HandleSignalsState hss; | 117 HandleSignalsState hss; |
| 225 EXPECT_EQ(MOJO_RESULT_OK, | 118 EXPECT_EQ(MOJO_RESULT_OK, |
| 226 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 119 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
| 227 // The child may or may not have closed its end of the message pipe and died | 120 // The child may or may not have closed its end of the message pipe and died |
| 228 // (and we may or may not know it yet), so our end may or may not appear as | 121 // (and we may or may not know it yet), so our end may or may not appear as |
| 229 // writable. | 122 // writable. |
| 230 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 123 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
| 231 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 124 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
| 232 | 125 |
| 233 std::string read_buffer(1000, '\0'); | 126 std::string read_buffer(1000, '\0'); |
| 234 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); | 127 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); |
| 235 CHECK_EQ(mp->ReadMessage(0, | 128 CHECK_EQ(mp->ReadMessage(0, |
| 236 UserPointer<void>(&read_buffer[0]), | 129 UserPointer<void>(&read_buffer[0]), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 EXPECT_EQ(MOJO_RESULT_OK, | 165 EXPECT_EQ(MOJO_RESULT_OK, |
| 273 mp->WriteMessage(0, | 166 mp->WriteMessage(0, |
| 274 UserPointer<const void>(quitquitquit.data()), | 167 UserPointer<const void>(quitquitquit.data()), |
| 275 static_cast<uint32_t>(quitquitquit.size()), | 168 static_cast<uint32_t>(quitquitquit.size()), |
| 276 NULL, | 169 NULL, |
| 277 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 170 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 278 | 171 |
| 279 for (size_t i = 0; i < kNumMessages; i++) { | 172 for (size_t i = 0; i < kNumMessages; i++) { |
| 280 HandleSignalsState hss; | 173 HandleSignalsState hss; |
| 281 EXPECT_EQ(MOJO_RESULT_OK, | 174 EXPECT_EQ(MOJO_RESULT_OK, |
| 282 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 175 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
| 283 // The child may or may not have closed its end of the message pipe and died | 176 // The child may or may not have closed its end of the message pipe and died |
| 284 // (and we may or may not know it yet), so our end may or may not appear as | 177 // (and we may or may not know it yet), so our end may or may not appear as |
| 285 // writable. | 178 // writable. |
| 286 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 179 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
| 287 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 180 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
| 288 | 181 |
| 289 std::string read_buffer(kNumMessages * 2, '\0'); | 182 std::string read_buffer(kNumMessages * 2, '\0'); |
| 290 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); | 183 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); |
| 291 CHECK_EQ(mp->ReadMessage(0, | 184 CHECK_EQ(mp->ReadMessage(0, |
| 292 UserPointer<void>(&read_buffer[0]), | 185 UserPointer<void>(&read_buffer[0]), |
| 293 MakeUserPointer(&read_buffer_size), | 186 MakeUserPointer(&read_buffer_size), |
| 294 NULL, | 187 NULL, |
| 295 NULL, | 188 NULL, |
| 296 MOJO_READ_MESSAGE_FLAG_NONE), | 189 MOJO_READ_MESSAGE_FLAG_NONE), |
| 297 MOJO_RESULT_OK); | 190 MOJO_RESULT_OK); |
| 298 read_buffer.resize(read_buffer_size); | 191 read_buffer.resize(read_buffer_size); |
| 299 | 192 |
| 300 EXPECT_EQ(std::string(i * 2, 'A' + (i % 26)), read_buffer); | 193 EXPECT_EQ(std::string(i * 2, 'A' + (i % 26)), read_buffer); |
| 301 } | 194 } |
| 302 | 195 |
| 303 // Wait for it to become readable, which should fail (since we sent | 196 // Wait for it to become readable, which should fail (since we sent |
| 304 // "quitquitquit"). | 197 // "quitquitquit"). |
| 305 HandleSignalsState hss; | 198 HandleSignalsState hss; |
| 306 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 199 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
| 307 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 200 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
| 308 EXPECT_EQ(0u, hss.satisfied_signals); | 201 EXPECT_EQ(0u, hss.satisfied_signals); |
| 309 EXPECT_EQ(0u, hss.satisfiable_signals); | 202 EXPECT_EQ(0u, hss.satisfiable_signals); |
| 310 | 203 |
| 311 mp->Close(0); | 204 mp->Close(0); |
| 312 | 205 |
| 313 EXPECT_EQ(static_cast<int>(kNumMessages % 100), | 206 EXPECT_EQ(static_cast<int>(kNumMessages % 100), |
| 314 helper()->WaitForChildShutdown()); | 207 helper()->WaitForChildShutdown()); |
| 315 } | 208 } |
| 316 | 209 |
| 317 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) { | 210 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) { |
| 318 embedder::SimplePlatformSupport platform_support; | 211 embedder::SimplePlatformSupport platform_support; |
| 319 ChannelThread channel_thread(&platform_support); | 212 test::ChannelThread channel_thread(&platform_support); |
| 320 embedder::ScopedPlatformHandle client_platform_handle = | 213 embedder::ScopedPlatformHandle client_platform_handle = |
| 321 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 214 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 322 CHECK(client_platform_handle.is_valid()); | 215 CHECK(client_platform_handle.is_valid()); |
| 323 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); | 216 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); |
| 324 channel_thread.Start(client_platform_handle.Pass(), mp); | 217 channel_thread.Start(client_platform_handle.Pass(), mp); |
| 325 | 218 |
| 326 // Wait for the first message from our parent. | 219 // Wait for the first message from our parent. |
| 327 HandleSignalsState hss; | 220 HandleSignalsState hss; |
| 328 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), | 221 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), |
| 329 MOJO_RESULT_OK); | 222 MOJO_RESULT_OK); |
| 330 // In this test, the parent definitely doesn't close its end of the message | 223 // In this test, the parent definitely doesn't close its end of the message |
| 331 // pipe before we do. | 224 // pipe before we do. |
| 332 CHECK_EQ(hss.satisfied_signals, | 225 CHECK_EQ(hss.satisfied_signals, |
| 333 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 226 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
| 334 CHECK_EQ(hss.satisfiable_signals, | 227 CHECK_EQ(hss.satisfiable_signals, |
| 335 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 228 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
| 336 | 229 |
| 337 // It should have a shared buffer. | 230 // It should have a shared buffer. |
| 338 std::string read_buffer(100, '\0'); | 231 std::string read_buffer(100, '\0'); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 const std::string go2("go 2"); | 267 const std::string go2("go 2"); |
| 375 CHECK_EQ(mp->WriteMessage(0, | 268 CHECK_EQ(mp->WriteMessage(0, |
| 376 UserPointer<const void>(&go2[0]), | 269 UserPointer<const void>(&go2[0]), |
| 377 static_cast<uint32_t>(go2.size()), | 270 static_cast<uint32_t>(go2.size()), |
| 378 NULL, | 271 NULL, |
| 379 MOJO_WRITE_MESSAGE_FLAG_NONE), | 272 MOJO_WRITE_MESSAGE_FLAG_NONE), |
| 380 MOJO_RESULT_OK); | 273 MOJO_RESULT_OK); |
| 381 | 274 |
| 382 // Now wait for our parent to send us a message. | 275 // Now wait for our parent to send us a message. |
| 383 hss = HandleSignalsState(); | 276 hss = HandleSignalsState(); |
| 384 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), | 277 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), |
| 385 MOJO_RESULT_OK); | 278 MOJO_RESULT_OK); |
| 386 CHECK_EQ(hss.satisfied_signals, | 279 CHECK_EQ(hss.satisfied_signals, |
| 387 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 280 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
| 388 CHECK_EQ(hss.satisfiable_signals, | 281 CHECK_EQ(hss.satisfiable_signals, |
| 389 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 282 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
| 390 | 283 |
| 391 read_buffer = std::string(100, '\0'); | 284 read_buffer = std::string(100, '\0'); |
| 392 num_bytes = static_cast<uint32_t>(read_buffer.size()); | 285 num_bytes = static_cast<uint32_t>(read_buffer.size()); |
| 393 CHECK_EQ(mp->ReadMessage(0, | 286 CHECK_EQ(mp->ReadMessage(0, |
| 394 UserPointer<void>(&read_buffer[0]), | 287 UserPointer<void>(&read_buffer[0]), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 &transports, | 348 &transports, |
| 456 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 349 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 457 transport.End(); | 350 transport.End(); |
| 458 | 351 |
| 459 EXPECT_TRUE(dispatcher->HasOneRef()); | 352 EXPECT_TRUE(dispatcher->HasOneRef()); |
| 460 dispatcher = NULL; | 353 dispatcher = NULL; |
| 461 | 354 |
| 462 // Wait for a message from the child. | 355 // Wait for a message from the child. |
| 463 HandleSignalsState hss; | 356 HandleSignalsState hss; |
| 464 EXPECT_EQ(MOJO_RESULT_OK, | 357 EXPECT_EQ(MOJO_RESULT_OK, |
| 465 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 358 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
| 466 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 359 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
| 467 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 360 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
| 468 | 361 |
| 469 std::string read_buffer(100, '\0'); | 362 std::string read_buffer(100, '\0'); |
| 470 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); | 363 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); |
| 471 EXPECT_EQ(MOJO_RESULT_OK, | 364 EXPECT_EQ(MOJO_RESULT_OK, |
| 472 mp->ReadMessage(0, | 365 mp->ReadMessage(0, |
| 473 UserPointer<void>(&read_buffer[0]), | 366 UserPointer<void>(&read_buffer[0]), |
| 474 MakeUserPointer(&num_bytes), | 367 MakeUserPointer(&num_bytes), |
| 475 NULL, | 368 NULL, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 492 EXPECT_EQ(MOJO_RESULT_OK, | 385 EXPECT_EQ(MOJO_RESULT_OK, |
| 493 mp->WriteMessage(0, | 386 mp->WriteMessage(0, |
| 494 UserPointer<const void>(&go3[0]), | 387 UserPointer<const void>(&go3[0]), |
| 495 static_cast<uint32_t>(go3.size()), | 388 static_cast<uint32_t>(go3.size()), |
| 496 NULL, | 389 NULL, |
| 497 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 390 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 498 | 391 |
| 499 // Wait for |mp| to become readable, which should fail. | 392 // Wait for |mp| to become readable, which should fail. |
| 500 hss = HandleSignalsState(); | 393 hss = HandleSignalsState(); |
| 501 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 394 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
| 502 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 395 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
| 503 EXPECT_EQ(0u, hss.satisfied_signals); | 396 EXPECT_EQ(0u, hss.satisfied_signals); |
| 504 EXPECT_EQ(0u, hss.satisfiable_signals); | 397 EXPECT_EQ(0u, hss.satisfiable_signals); |
| 505 | 398 |
| 506 mp->Close(0); | 399 mp->Close(0); |
| 507 | 400 |
| 508 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | 401 EXPECT_EQ(0, helper()->WaitForChildShutdown()); |
| 509 } | 402 } |
| 510 | 403 |
| 511 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) { | 404 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) { |
| 512 embedder::SimplePlatformSupport platform_support; | 405 embedder::SimplePlatformSupport platform_support; |
| 513 ChannelThread channel_thread(&platform_support); | 406 test::ChannelThread channel_thread(&platform_support); |
| 514 embedder::ScopedPlatformHandle client_platform_handle = | 407 embedder::ScopedPlatformHandle client_platform_handle = |
| 515 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 408 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 516 CHECK(client_platform_handle.is_valid()); | 409 CHECK(client_platform_handle.is_valid()); |
| 517 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); | 410 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); |
| 518 channel_thread.Start(client_platform_handle.Pass(), mp); | 411 channel_thread.Start(client_platform_handle.Pass(), mp); |
| 519 | 412 |
| 520 HandleSignalsState hss; | 413 HandleSignalsState hss; |
| 521 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), | 414 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), |
| 522 MOJO_RESULT_OK); | 415 MOJO_RESULT_OK); |
| 523 CHECK_EQ(hss.satisfied_signals, | 416 CHECK_EQ(hss.satisfied_signals, |
| 524 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 417 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
| 525 CHECK_EQ(hss.satisfiable_signals, | 418 CHECK_EQ(hss.satisfiable_signals, |
| 526 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 419 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
| 527 | 420 |
| 528 std::string read_buffer(100, '\0'); | 421 std::string read_buffer(100, '\0'); |
| 529 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); | 422 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); |
| 530 DispatcherVector dispatchers; | 423 DispatcherVector dispatchers; |
| 531 uint32_t num_dispatchers = 10; // Maximum number to receive. | 424 uint32_t num_dispatchers = 10; // Maximum number to receive. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 &transports, | 495 &transports, |
| 603 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 496 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 604 transport.End(); | 497 transport.End(); |
| 605 | 498 |
| 606 EXPECT_TRUE(dispatcher->HasOneRef()); | 499 EXPECT_TRUE(dispatcher->HasOneRef()); |
| 607 dispatcher = NULL; | 500 dispatcher = NULL; |
| 608 | 501 |
| 609 // Wait for it to become readable, which should fail. | 502 // Wait for it to become readable, which should fail. |
| 610 HandleSignalsState hss; | 503 HandleSignalsState hss; |
| 611 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 504 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
| 612 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 505 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
| 613 EXPECT_EQ(0u, hss.satisfied_signals); | 506 EXPECT_EQ(0u, hss.satisfied_signals); |
| 614 EXPECT_EQ(0u, hss.satisfiable_signals); | 507 EXPECT_EQ(0u, hss.satisfiable_signals); |
| 615 | 508 |
| 616 mp->Close(0); | 509 mp->Close(0); |
| 617 | 510 |
| 618 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | 511 EXPECT_EQ(0, helper()->WaitForChildShutdown()); |
| 619 } | 512 } |
| 620 | 513 |
| 621 } // namespace | 514 } // namespace |
| 622 } // namespace system | 515 } // namespace system |
| 623 } // namespace mojo | 516 } // namespace mojo |
| OLD | NEW |