| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This file tests both |RemoteProducerDataPipeImpl| and | 5 // This file tests both |RemoteProducerDataPipeImpl| and |
| 6 // |RemoteConsumerDataPipeImpl|. | 6 // |RemoteConsumerDataPipeImpl|. |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 DispatcherVector read_dispatchers; | 170 DispatcherVector read_dispatchers; |
| 171 uint32_t read_num_dispatchers = 10; // Maximum to get. | 171 uint32_t read_num_dispatchers = 10; // Maximum to get. |
| 172 Waiter waiter; | 172 Waiter waiter; |
| 173 HandleSignalsState hss; | 173 HandleSignalsState hss; |
| 174 uint32_t context = 0; | 174 uint32_t context = 0; |
| 175 | 175 |
| 176 RefPtr<DataPipe> dp(CreateLocal(sizeof(int32_t), 1000)); | 176 RefPtr<DataPipe> dp(CreateLocal(sizeof(int32_t), 1000)); |
| 177 // This is the consumer dispatcher we'll send. | 177 // This is the consumer dispatcher we'll send. |
| 178 auto consumer = DataPipeConsumerDispatcher::Create(); | 178 auto consumer = DataPipeConsumerDispatcher::Create(); |
| 179 consumer->Init(dp.Clone()); | 179 consumer->Init(dp.Clone()); |
| 180 Handle consumer_handle(std::move(consumer), MOJO_HANDLE_RIGHT_TRANSFER | | 180 Handle consumer_handle(std::move(consumer), |
| 181 MOJO_HANDLE_RIGHT_READ | | 181 DataPipeConsumerDispatcher::kDefaultHandleRights); |
| 182 MOJO_HANDLE_RIGHT_WRITE); | |
| 183 | 182 |
| 184 // Write to the producer and close it, before sending the consumer. | 183 // Write to the producer and close it, before sending the consumer. |
| 185 int32_t elements[10] = {123}; | 184 int32_t elements[10] = {123}; |
| 186 uint32_t num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); | 185 uint32_t num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); |
| 187 EXPECT_EQ(MOJO_RESULT_OK, | 186 EXPECT_EQ(MOJO_RESULT_OK, |
| 188 dp->ProducerWriteData(UserPointer<const void>(elements), | 187 dp->ProducerWriteData(UserPointer<const void>(elements), |
| 189 MakeUserPointer(&num_bytes), false)); | 188 MakeUserPointer(&num_bytes), false)); |
| 190 EXPECT_EQ(1u * sizeof(elements[0]), num_bytes); | 189 EXPECT_EQ(1u * sizeof(elements[0]), num_bytes); |
| 191 dp->ProducerClose(); | 190 dp->ProducerClose(); |
| 192 | 191 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 DispatcherVector read_dispatchers; | 292 DispatcherVector read_dispatchers; |
| 294 uint32_t read_num_dispatchers = 10; // Maximum to get. | 293 uint32_t read_num_dispatchers = 10; // Maximum to get. |
| 295 Waiter waiter; | 294 Waiter waiter; |
| 296 HandleSignalsState hss; | 295 HandleSignalsState hss; |
| 297 uint32_t context = 0; | 296 uint32_t context = 0; |
| 298 | 297 |
| 299 RefPtr<DataPipe> dp(CreateLocal(sizeof(int32_t), 1000)); | 298 RefPtr<DataPipe> dp(CreateLocal(sizeof(int32_t), 1000)); |
| 300 // This is the consumer dispatcher we'll send. | 299 // This is the consumer dispatcher we'll send. |
| 301 auto consumer = DataPipeConsumerDispatcher::Create(); | 300 auto consumer = DataPipeConsumerDispatcher::Create(); |
| 302 consumer->Init(dp.Clone()); | 301 consumer->Init(dp.Clone()); |
| 303 Handle consumer_handle(std::move(consumer), MOJO_HANDLE_RIGHT_TRANSFER | | 302 Handle consumer_handle(std::move(consumer), |
| 304 MOJO_HANDLE_RIGHT_READ | | 303 DataPipeConsumerDispatcher::kDefaultHandleRights); |
| 305 MOJO_HANDLE_RIGHT_WRITE); | |
| 306 | 304 |
| 307 void* write_ptr = nullptr; | 305 void* write_ptr = nullptr; |
| 308 uint32_t num_bytes = 0u; | 306 uint32_t num_bytes = 0u; |
| 309 EXPECT_EQ(MOJO_RESULT_OK, | 307 EXPECT_EQ(MOJO_RESULT_OK, |
| 310 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), | 308 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), |
| 311 MakeUserPointer(&num_bytes))); | 309 MakeUserPointer(&num_bytes))); |
| 312 ASSERT_GE(num_bytes, 1u * sizeof(int32_t)); | 310 ASSERT_GE(num_bytes, 1u * sizeof(int32_t)); |
| 313 | 311 |
| 314 // Write the consumer to MP 0 (port 0). Wait and receive on MP 1 (port 0). | 312 // Write the consumer to MP 0 (port 0). Wait and receive on MP 1 (port 0). |
| 315 // (Add the waiter first, to avoid any handling the case where it's already | 313 // (Add the waiter first, to avoid any handling the case where it's already |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 DispatcherVector read_dispatchers; | 406 DispatcherVector read_dispatchers; |
| 409 uint32_t read_num_dispatchers = 10; // Maximum to get. | 407 uint32_t read_num_dispatchers = 10; // Maximum to get. |
| 410 Waiter waiter; | 408 Waiter waiter; |
| 411 HandleSignalsState hss; | 409 HandleSignalsState hss; |
| 412 uint32_t context = 0; | 410 uint32_t context = 0; |
| 413 | 411 |
| 414 RefPtr<DataPipe> dp(CreateLocal(sizeof(int32_t), 1000)); | 412 RefPtr<DataPipe> dp(CreateLocal(sizeof(int32_t), 1000)); |
| 415 // This is the consumer dispatcher we'll send. | 413 // This is the consumer dispatcher we'll send. |
| 416 auto consumer = DataPipeConsumerDispatcher::Create(); | 414 auto consumer = DataPipeConsumerDispatcher::Create(); |
| 417 consumer->Init(dp.Clone()); | 415 consumer->Init(dp.Clone()); |
| 418 Handle consumer_handle(std::move(consumer), MOJO_HANDLE_RIGHT_TRANSFER | | 416 Handle consumer_handle(std::move(consumer), |
| 419 MOJO_HANDLE_RIGHT_READ | | 417 DataPipeConsumerDispatcher::kDefaultHandleRights); |
| 420 MOJO_HANDLE_RIGHT_WRITE); | |
| 421 | 418 |
| 422 void* write_ptr = nullptr; | 419 void* write_ptr = nullptr; |
| 423 uint32_t num_bytes = 0u; | 420 uint32_t num_bytes = 0u; |
| 424 EXPECT_EQ(MOJO_RESULT_OK, | 421 EXPECT_EQ(MOJO_RESULT_OK, |
| 425 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), | 422 dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr), |
| 426 MakeUserPointer(&num_bytes))); | 423 MakeUserPointer(&num_bytes))); |
| 427 ASSERT_GE(num_bytes, 1u * sizeof(int32_t)); | 424 ASSERT_GE(num_bytes, 1u * sizeof(int32_t)); |
| 428 *static_cast<int32_t*>(write_ptr) = 123456; | 425 *static_cast<int32_t*>(write_ptr) = 123456; |
| 429 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData( | 426 EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData( |
| 430 static_cast<uint32_t>(1u * sizeof(int32_t)))); | 427 static_cast<uint32_t>(1u * sizeof(int32_t)))); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 EXPECT_EQ(123456, elements[0]); | 519 EXPECT_EQ(123456, elements[0]); |
| 523 EXPECT_EQ(789012, elements[1]); | 520 EXPECT_EQ(789012, elements[1]); |
| 524 EXPECT_EQ(0, elements[2]); | 521 EXPECT_EQ(0, elements[2]); |
| 525 | 522 |
| 526 consumer->Close(); | 523 consumer->Close(); |
| 527 } | 524 } |
| 528 | 525 |
| 529 } // namespace | 526 } // namespace |
| 530 } // namespace system | 527 } // namespace system |
| 531 } // namespace mojo | 528 } // namespace mojo |
| OLD | NEW |