Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: mojo/edk/system/data_pipe_impl_unittest.cc

Issue 1946763002: EDK: Add MojoHandleRights to DispatcherTransport. (Closed) Base URL: https://github.com/domokit/mojo.git@work788_edk_handle_10
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/edk/system/dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 contains tests that are shared between different implementations of 5 // This file contains tests that are shared between different implementations of
6 // |DataPipeImpl|. 6 // |DataPipeImpl|.
7 7
8 #include "mojo/edk/system/data_pipe_impl.h" 8 #include "mojo/edk/system/data_pipe_impl.h"
9 9
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 258 }
259 259
260 void Create(const MojoCreateDataPipeOptions& validated_options) override { 260 void Create(const MojoCreateDataPipeOptions& validated_options) override {
261 CHECK(!dp_); 261 CHECK(!dp_);
262 dp_ = DataPipe::CreateLocal(validated_options); 262 dp_ = DataPipe::CreateLocal(validated_options);
263 } 263 }
264 264
265 bool IsStrictCircularBuffer() const override { return false; } 265 bool IsStrictCircularBuffer() const override { return false; }
266 266
267 protected: 267 protected:
268 void SendDispatcher(size_t source_i, 268 // TODO(vtl): |to_receive| should be a |Handle*| too.
269 RefPtr<Dispatcher> to_send, 269 void SendHandle(size_t source_i,
270 RefPtr<Dispatcher>* to_receive) { 270 const Handle& to_send,
271 RefPtr<Dispatcher>* to_receive) {
271 DCHECK(source_i == 0 || source_i == 1); 272 DCHECK(source_i == 0 || source_i == 1);
272 size_t dest_i = source_i ^ 1; 273 size_t dest_i = source_i ^ 1;
273 274
274 // Write the dispatcher to MP |source_i| (port 0). Wait and receive on MP 275 // Write the dispatcher to MP |source_i| (port 0). Wait and receive on MP
275 // |dest_i| (port 0). (Add the waiter first, to avoid any handling the case 276 // |dest_i| (port 0). (Add the waiter first, to avoid any handling the case
276 // where it's already readable.) 277 // where it's already readable.)
277 Waiter waiter; 278 Waiter waiter;
278 waiter.Init(); 279 waiter.Init();
279 ASSERT_EQ(MOJO_RESULT_OK, 280 ASSERT_EQ(MOJO_RESULT_OK,
280 message_pipe(dest_i)->AddAwakable( 281 message_pipe(dest_i)->AddAwakable(
281 0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 987, nullptr)); 282 0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 987, nullptr));
282 { 283 {
283 DispatcherTransport transport( 284 DispatcherTransport transport(test::HandleTryStartTransport(to_send));
284 test::DispatcherTryStartTransport(to_send.get()));
285 ASSERT_TRUE(transport.is_valid()); 285 ASSERT_TRUE(transport.is_valid());
286 286
287 std::vector<DispatcherTransport> transports; 287 std::vector<DispatcherTransport> transports;
288 transports.push_back(transport); 288 transports.push_back(transport);
289 ASSERT_EQ(MOJO_RESULT_OK, message_pipe(source_i)->WriteMessage( 289 ASSERT_EQ(MOJO_RESULT_OK, message_pipe(source_i)->WriteMessage(
290 0, NullUserPointer(), 0, &transports, 290 0, NullUserPointer(), 0, &transports,
291 MOJO_WRITE_MESSAGE_FLAG_NONE)); 291 MOJO_WRITE_MESSAGE_FLAG_NONE));
292 transport.End(); 292 transport.End();
293 } 293 }
294 uint32_t context = 0; 294 uint32_t context = 0;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 class RemoteProducerDataPipeImplTestHelper 378 class RemoteProducerDataPipeImplTestHelper
379 : public RemoteDataPipeImplTestHelper { 379 : public RemoteDataPipeImplTestHelper {
380 public: 380 public:
381 RemoteProducerDataPipeImplTestHelper() {} 381 RemoteProducerDataPipeImplTestHelper() {}
382 ~RemoteProducerDataPipeImplTestHelper() override {} 382 ~RemoteProducerDataPipeImplTestHelper() override {}
383 383
384 void DoTransfer() override { 384 void DoTransfer() override {
385 // This is the producer dispatcher we'll send. 385 // This is the producer dispatcher we'll send.
386 auto to_send = DataPipeProducerDispatcher::Create(); 386 auto to_send = DataPipeProducerDispatcher::Create();
387 to_send->Init(dp()); 387 to_send->Init(dp());
388 Handle handle_to_send(std::move(to_send), MOJO_HANDLE_RIGHT_TRANSFER |
389 MOJO_HANDLE_RIGHT_READ |
390 MOJO_HANDLE_RIGHT_WRITE);
388 RefPtr<Dispatcher> to_receive; 391 RefPtr<Dispatcher> to_receive;
389 SendDispatcher(0, to_send, &to_receive); 392 SendHandle(0, handle_to_send, &to_receive);
390 // |to_send| should have been closed. This is |DCHECK()|ed when it is 393 // |handle_to_send.dispatcher| should have been closed. This is |DCHECK()|ed
391 // destroyed. 394 // when it is destroyed.
392 EXPECT_TRUE(to_send->HasOneRef()); 395 EXPECT_TRUE(handle_to_send.dispatcher->HasOneRef());
393 to_send = nullptr; 396 handle_to_send.reset();
394 397
395 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_PRODUCER, to_receive->GetType()); 398 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_PRODUCER, to_receive->GetType());
396 producer_dispatcher_ = RefPtr<DataPipeProducerDispatcher>( 399 producer_dispatcher_ = RefPtr<DataPipeProducerDispatcher>(
397 static_cast<DataPipeProducerDispatcher*>(to_receive.get())); 400 static_cast<DataPipeProducerDispatcher*>(to_receive.get()));
398 } 401 }
399 402
400 DataPipe* DataPipeForProducer() override { 403 DataPipe* DataPipeForProducer() override {
401 if (producer_dispatcher_) 404 if (producer_dispatcher_)
402 return producer_dispatcher_->GetDataPipeForTest(); 405 return producer_dispatcher_->GetDataPipeForTest();
403 return dp().get(); 406 return dp().get();
(...skipping 23 matching lines...) Expand all
427 class RemoteConsumerDataPipeImplTestHelper 430 class RemoteConsumerDataPipeImplTestHelper
428 : public RemoteDataPipeImplTestHelper { 431 : public RemoteDataPipeImplTestHelper {
429 public: 432 public:
430 RemoteConsumerDataPipeImplTestHelper() {} 433 RemoteConsumerDataPipeImplTestHelper() {}
431 ~RemoteConsumerDataPipeImplTestHelper() override {} 434 ~RemoteConsumerDataPipeImplTestHelper() override {}
432 435
433 void DoTransfer() override { 436 void DoTransfer() override {
434 // This is the consumer dispatcher we'll send. 437 // This is the consumer dispatcher we'll send.
435 auto to_send = DataPipeConsumerDispatcher::Create(); 438 auto to_send = DataPipeConsumerDispatcher::Create();
436 to_send->Init(dp()); 439 to_send->Init(dp());
440 Handle handle_to_send(std::move(to_send), MOJO_HANDLE_RIGHT_TRANSFER |
441 MOJO_HANDLE_RIGHT_READ |
442 MOJO_HANDLE_RIGHT_WRITE);
437 RefPtr<Dispatcher> to_receive; 443 RefPtr<Dispatcher> to_receive;
438 SendDispatcher(0, to_send, &to_receive); 444 SendHandle(0, handle_to_send, &to_receive);
439 // |to_send| should have been closed. This is |DCHECK()|ed when it is 445 // |handle_to_send.dispatcher| should have been closed. This is |DCHECK()|ed
440 // destroyed. 446 // when it is destroyed.
441 EXPECT_TRUE(to_send->HasOneRef()); 447 EXPECT_TRUE(handle_to_send.dispatcher->HasOneRef());
442 to_send = nullptr; 448 handle_to_send.reset();
443 449
444 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, to_receive->GetType()); 450 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, to_receive->GetType());
445 consumer_dispatcher_ = RefPtr<DataPipeConsumerDispatcher>( 451 consumer_dispatcher_ = RefPtr<DataPipeConsumerDispatcher>(
446 static_cast<DataPipeConsumerDispatcher*>(to_receive.get())); 452 static_cast<DataPipeConsumerDispatcher*>(to_receive.get()));
447 } 453 }
448 454
449 DataPipe* DataPipeForProducer() override { return dp().get(); } 455 DataPipe* DataPipeForProducer() override { return dp().get(); }
450 DataPipe* DataPipeForConsumer() override { 456 DataPipe* DataPipeForConsumer() override {
451 if (consumer_dispatcher_) 457 if (consumer_dispatcher_)
452 return consumer_dispatcher_->GetDataPipeForTest(); 458 return consumer_dispatcher_->GetDataPipeForTest();
(...skipping 28 matching lines...) Expand all
481 class RemoteProducerDataPipeImplTestHelper2 487 class RemoteProducerDataPipeImplTestHelper2
482 : public RemoteProducerDataPipeImplTestHelper { 488 : public RemoteProducerDataPipeImplTestHelper {
483 public: 489 public:
484 RemoteProducerDataPipeImplTestHelper2() {} 490 RemoteProducerDataPipeImplTestHelper2() {}
485 ~RemoteProducerDataPipeImplTestHelper2() override {} 491 ~RemoteProducerDataPipeImplTestHelper2() override {}
486 492
487 void DoTransfer() override { 493 void DoTransfer() override {
488 // This is the producer dispatcher we'll send. 494 // This is the producer dispatcher we'll send.
489 auto to_send = DataPipeProducerDispatcher::Create(); 495 auto to_send = DataPipeProducerDispatcher::Create();
490 to_send->Init(dp()); 496 to_send->Init(dp());
497 Handle handle_to_send(std::move(to_send), MOJO_HANDLE_RIGHT_TRANSFER |
498 MOJO_HANDLE_RIGHT_READ |
499 MOJO_HANDLE_RIGHT_WRITE);
491 RefPtr<Dispatcher> to_receive; 500 RefPtr<Dispatcher> to_receive;
492 SendDispatcher(0, to_send, &to_receive); 501 SendHandle(0, handle_to_send, &to_receive);
493 // |to_send| should have been closed. This is |DCHECK()|ed when it is 502 // |handle_to_send.dispatcher| should have been closed. This is |DCHECK()|ed
494 // destroyed. 503 // when it is destroyed.
495 EXPECT_TRUE(to_send->HasOneRef()); 504 EXPECT_TRUE(handle_to_send.dispatcher->HasOneRef());
496 to_send = nullptr; 505 handle_to_send.reset();
497 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_PRODUCER, to_receive->GetType()); 506 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_PRODUCER, to_receive->GetType());
498 to_send = RefPtr<DataPipeProducerDispatcher>( 507 handle_to_send = Handle(std::move(to_receive), MOJO_HANDLE_RIGHT_TRANSFER |
499 static_cast<DataPipeProducerDispatcher*>(to_receive.get())); 508 MOJO_HANDLE_RIGHT_READ |
500 to_receive = nullptr; 509 MOJO_HANDLE_RIGHT_WRITE);
501 510
502 // Now send it back the other way. 511 // Now send it back the other way.
503 SendDispatcher(1, to_send, &to_receive); 512 SendHandle(1, handle_to_send, &to_receive);
504 // |producer_dispatcher_| should have been closed. This is |DCHECK()|ed when 513 // |handle_to_send.dispatcher| should have been closed. This is |DCHECK()|ed
505 // it is destroyed. 514 // when it is destroyed.
506 EXPECT_TRUE(to_send->HasOneRef()); 515 EXPECT_TRUE(handle_to_send.dispatcher->HasOneRef());
507 to_send = nullptr; 516 handle_to_send.reset();
508 517
509 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_PRODUCER, to_receive->GetType()); 518 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_PRODUCER, to_receive->GetType());
510 producer_dispatcher_ = RefPtr<DataPipeProducerDispatcher>( 519 producer_dispatcher_ = RefPtr<DataPipeProducerDispatcher>(
511 static_cast<DataPipeProducerDispatcher*>(to_receive.get())); 520 static_cast<DataPipeProducerDispatcher*>(to_receive.get()));
512 } 521 }
513 522
514 private: 523 private:
515 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImplTestHelper2); 524 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImplTestHelper2);
516 }; 525 };
517 526
(...skipping 10 matching lines...) Expand all
528 class RemoteConsumerDataPipeImplTestHelper2 537 class RemoteConsumerDataPipeImplTestHelper2
529 : public RemoteConsumerDataPipeImplTestHelper { 538 : public RemoteConsumerDataPipeImplTestHelper {
530 public: 539 public:
531 RemoteConsumerDataPipeImplTestHelper2() {} 540 RemoteConsumerDataPipeImplTestHelper2() {}
532 ~RemoteConsumerDataPipeImplTestHelper2() override {} 541 ~RemoteConsumerDataPipeImplTestHelper2() override {}
533 542
534 void DoTransfer() override { 543 void DoTransfer() override {
535 // This is the consumer dispatcher we'll send. 544 // This is the consumer dispatcher we'll send.
536 auto to_send = DataPipeConsumerDispatcher::Create(); 545 auto to_send = DataPipeConsumerDispatcher::Create();
537 to_send->Init(dp()); 546 to_send->Init(dp());
547 Handle handle_to_send(std::move(to_send), MOJO_HANDLE_RIGHT_TRANSFER |
548 MOJO_HANDLE_RIGHT_READ |
549 MOJO_HANDLE_RIGHT_WRITE);
538 RefPtr<Dispatcher> to_receive; 550 RefPtr<Dispatcher> to_receive;
539 SendDispatcher(0, to_send, &to_receive); 551 SendHandle(0, handle_to_send, &to_receive);
540 // |to_send| should have been closed. This is |DCHECK()|ed when it is 552 // |handle_to_send.dispatcher| should have been closed. This is |DCHECK()|ed
541 // destroyed. 553 // when it is destroyed.
542 EXPECT_TRUE(to_send->HasOneRef()); 554 EXPECT_TRUE(handle_to_send.dispatcher->HasOneRef());
543 to_send = nullptr; 555 handle_to_send.reset();
544 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, to_receive->GetType()); 556 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, to_receive->GetType());
545 to_send = RefPtr<DataPipeConsumerDispatcher>( 557 handle_to_send = Handle(std::move(to_receive), MOJO_HANDLE_RIGHT_TRANSFER |
546 static_cast<DataPipeConsumerDispatcher*>(to_receive.get())); 558 MOJO_HANDLE_RIGHT_READ |
547 to_receive = nullptr; 559 MOJO_HANDLE_RIGHT_WRITE);
548 560
549 // Now send it back the other way. 561 // Now send it back the other way.
550 SendDispatcher(1, to_send, &to_receive); 562 SendHandle(1, handle_to_send, &to_receive);
551 // |consumer_dispatcher_| should have been closed. This is |DCHECK()|ed when 563 // |handle_to_send.dispatcher| should have been closed. This is |DCHECK()|ed
552 // it is destroyed. 564 // when it is destroyed.
553 EXPECT_TRUE(to_send->HasOneRef()); 565 EXPECT_TRUE(handle_to_send.dispatcher->HasOneRef());
554 to_send = nullptr; 566 handle_to_send.reset();
555 567
556 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, to_receive->GetType()); 568 ASSERT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, to_receive->GetType());
557 consumer_dispatcher_ = RefPtr<DataPipeConsumerDispatcher>( 569 consumer_dispatcher_ = RefPtr<DataPipeConsumerDispatcher>(
558 static_cast<DataPipeConsumerDispatcher*>(to_receive.get())); 570 static_cast<DataPipeConsumerDispatcher*>(to_receive.get()));
559 } 571 }
560 572
561 private: 573 private:
562 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImplTestHelper2); 574 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImplTestHelper2);
563 }; 575 };
564 576
(...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after
2929 &waiter, MOJO_HANDLE_SIGNAL_READ_THRESHOLD, 0, &hss)); 2941 &waiter, MOJO_HANDLE_SIGNAL_READ_THRESHOLD, 0, &hss));
2930 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); 2942 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals);
2931 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); 2943 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals);
2932 2944
2933 this->ConsumerClose(); 2945 this->ConsumerClose();
2934 } 2946 }
2935 2947
2936 } // namespace 2948 } // namespace
2937 } // namespace system 2949 } // namespace system
2938 } // namespace mojo 2950 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/system/dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698