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

Side by Side Diff: mojo/edk/system/ipc_support_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
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 #include "mojo/edk/system/ipc_support.h" 5 #include "mojo/edk/system/ipc_support.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "mojo/edk/embedder/master_process_delegate.h" 12 #include "mojo/edk/embedder/master_process_delegate.h"
13 #include "mojo/edk/embedder/simple_platform_support.h" 13 #include "mojo/edk/embedder/simple_platform_support.h"
14 #include "mojo/edk/embedder/slave_process_delegate.h" 14 #include "mojo/edk/embedder/slave_process_delegate.h"
15 #include "mojo/edk/platform/platform_pipe.h" 15 #include "mojo/edk/platform/platform_pipe.h"
16 #include "mojo/edk/system/channel_manager.h" 16 #include "mojo/edk/system/channel_manager.h"
17 #include "mojo/edk/system/connection_identifier.h" 17 #include "mojo/edk/system/connection_identifier.h"
18 #include "mojo/edk/system/dispatcher.h" 18 #include "mojo/edk/system/dispatcher.h"
19 #include "mojo/edk/system/handle.h"
19 #include "mojo/edk/system/handle_transport.h" 20 #include "mojo/edk/system/handle_transport.h"
20 #include "mojo/edk/system/message_pipe.h" 21 #include "mojo/edk/system/message_pipe.h"
21 #include "mojo/edk/system/message_pipe_dispatcher.h" 22 #include "mojo/edk/system/message_pipe_dispatcher.h"
22 #include "mojo/edk/system/process_identifier.h" 23 #include "mojo/edk/system/process_identifier.h"
23 #include "mojo/edk/system/test/test_command_line.h" 24 #include "mojo/edk/system/test/test_command_line.h"
24 #include "mojo/edk/system/test/test_io_thread.h" 25 #include "mojo/edk/system/test/test_io_thread.h"
25 #include "mojo/edk/system/test/timeouts.h" 26 #include "mojo/edk/system/test/timeouts.h"
26 #include "mojo/edk/system/waiter.h" 27 #include "mojo/edk/system/waiter.h"
27 #include "mojo/edk/test/multiprocess_test_helper.h" 28 #include "mojo/edk/test/multiprocess_test_helper.h"
28 #include "mojo/edk/test/test_utils.h" 29 #include "mojo/edk/test/test_utils.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 read_mp->ReadMessage(UserPointer<void>(buffer), 72 read_mp->ReadMessage(UserPointer<void>(buffer),
72 MakeUserPointer(&buffer_size), 0, nullptr, 73 MakeUserPointer(&buffer_size), 0, nullptr,
73 MOJO_READ_MESSAGE_FLAG_NONE)); 74 MOJO_READ_MESSAGE_FLAG_NONE));
74 EXPECT_EQ(1u, buffer_size); 75 EXPECT_EQ(1u, buffer_size);
75 EXPECT_EQ('x', buffer[0]); 76 EXPECT_EQ('x', buffer[0]);
76 } 77 }
77 78
78 // Writes a message pipe dispatcher (in a message) to |write_mp| and reads it 79 // Writes a message pipe dispatcher (in a message) to |write_mp| and reads it
79 // from |read_mp| (it should be the next message, i.e., there should be no other 80 // from |read_mp| (it should be the next message, i.e., there should be no other
80 // other messages already enqueued in that direction). 81 // other messages already enqueued in that direction).
82 // TODO(vtl): Probably |mp_to_send| should be a |Handle|, and so should the
83 // return value.
81 RefPtr<MessagePipeDispatcher> SendMessagePipeDispatcher( 84 RefPtr<MessagePipeDispatcher> SendMessagePipeDispatcher(
82 MessagePipeDispatcher* write_mp, 85 MessagePipeDispatcher* write_mp,
83 MessagePipeDispatcher* read_mp, 86 MessagePipeDispatcher* read_mp,
84 RefPtr<MessagePipeDispatcher>&& mp_to_send) { 87 RefPtr<MessagePipeDispatcher>&& mp_to_send) {
85 CHECK_NE(mp_to_send.get(), write_mp); 88 CHECK_NE(mp_to_send.get(), write_mp);
86 CHECK_NE(mp_to_send.get(), read_mp); 89 CHECK_NE(mp_to_send.get(), read_mp);
90 Handle mp_handle_to_send(std::move(mp_to_send), MOJO_HANDLE_RIGHT_TRANSFER |
91 MOJO_HANDLE_RIGHT_READ |
92 MOJO_HANDLE_RIGHT_WRITE);
87 93
88 // Set up waiting on the read end first (to avoid racing). 94 // Set up waiting on the read end first (to avoid racing).
89 Waiter waiter; 95 Waiter waiter;
90 waiter.Init(); 96 waiter.Init();
91 CHECK_EQ( 97 CHECK_EQ(
92 read_mp->AddAwakable(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 0, nullptr), 98 read_mp->AddAwakable(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 0, nullptr),
93 MOJO_RESULT_OK); 99 MOJO_RESULT_OK);
94 100
95 // Write a message with just |mp_to_send| through the write end. 101 // Write a message with just |mp_handle_to_send| through the write end.
96 DispatcherTransport transport( 102 DispatcherTransport transport(
97 test::DispatcherTryStartTransport(mp_to_send.get())); 103 test::HandleTryStartTransport(mp_handle_to_send));
98 CHECK(transport.is_valid()); 104 CHECK(transport.is_valid());
99 std::vector<DispatcherTransport> transports; 105 std::vector<DispatcherTransport> transports;
100 transports.push_back(transport); 106 transports.push_back(transport);
101 CHECK_EQ(write_mp->WriteMessage(NullUserPointer(), 0, &transports, 107 CHECK_EQ(write_mp->WriteMessage(NullUserPointer(), 0, &transports,
102 MOJO_WRITE_MESSAGE_FLAG_NONE), 108 MOJO_WRITE_MESSAGE_FLAG_NONE),
103 MOJO_RESULT_OK); 109 MOJO_RESULT_OK);
104 transport.End(); 110 transport.End();
105 mp_to_send = nullptr; 111 mp_handle_to_send.reset();
106 112
107 // Wait for it to arrive. 113 // Wait for it to arrive.
108 CHECK_EQ(waiter.Wait(test::ActionTimeout(), nullptr), MOJO_RESULT_OK); 114 CHECK_EQ(waiter.Wait(test::ActionTimeout(), nullptr), MOJO_RESULT_OK);
109 read_mp->RemoveAwakable(&waiter, nullptr); 115 read_mp->RemoveAwakable(&waiter, nullptr);
110 116
111 // Read the message from the read end. 117 // Read the message from the read end.
112 DispatcherVector dispatchers; 118 DispatcherVector dispatchers;
113 uint32_t num_dispatchers = 10; 119 uint32_t num_dispatchers = 10;
114 CHECK_EQ( 120 CHECK_EQ(
115 read_mp->ReadMessage(NullUserPointer(), NullUserPointer(), &dispatchers, 121 read_mp->ReadMessage(NullUserPointer(), NullUserPointer(), &dispatchers,
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 410
405 // All tests require a master. 411 // All tests require a master.
406 TestMasterProcessDelegate master_process_delegate_; 412 TestMasterProcessDelegate master_process_delegate_;
407 IPCSupport master_ipc_support_; 413 IPCSupport master_ipc_support_;
408 414
409 MOJO_DISALLOW_COPY_AND_ASSIGN(IPCSupportTest); 415 MOJO_DISALLOW_COPY_AND_ASSIGN(IPCSupportTest);
410 }; 416 };
411 417
412 using MessagePipeDispatcherPair = 418 using MessagePipeDispatcherPair =
413 std::pair<RefPtr<MessagePipeDispatcher>, RefPtr<MessagePipeDispatcher>>; 419 std::pair<RefPtr<MessagePipeDispatcher>, RefPtr<MessagePipeDispatcher>>;
420
414 MessagePipeDispatcherPair CreateMessagePipe() { 421 MessagePipeDispatcherPair CreateMessagePipe() {
415 MessagePipeDispatcherPair rv; 422 MessagePipeDispatcherPair rv;
416 rv.first = MessagePipeDispatcher::Create( 423 rv.first = MessagePipeDispatcher::Create(
417 MessagePipeDispatcher::kDefaultCreateOptions); 424 MessagePipeDispatcher::kDefaultCreateOptions);
418 rv.second = MessagePipeDispatcher::Create( 425 rv.second = MessagePipeDispatcher::Create(
419 MessagePipeDispatcher::kDefaultCreateOptions); 426 MessagePipeDispatcher::kDefaultCreateOptions);
420 auto mp = MessagePipe::CreateLocalLocal(); 427 auto mp = MessagePipe::CreateLocalLocal();
421 rv.first->Init(mp.Clone(), 0); 428 rv.first->Init(mp.Clone(), 0);
422 rv.second->Init(std::move(mp), 1); 429 rv.second->Init(std::move(mp), 1);
423 return rv; 430 return rv;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 718
712 test_io_thread.PostTaskAndWait( 719 test_io_thread.PostTaskAndWait(
713 [&ipc_support]() { ipc_support.ShutdownOnIOThread(); }); 720 [&ipc_support]() { ipc_support.ShutdownOnIOThread(); });
714 } 721 }
715 722
716 // TODO(vtl): Also test the case of the master "dying" before the slave. (The 723 // TODO(vtl): Also test the case of the master "dying" before the slave. (The
717 // slave should get OnMasterDisconnect(), which we currently don't test.) 724 // slave should get OnMasterDisconnect(), which we currently don't test.)
718 725
719 } // namespace system 726 } // namespace system
720 } // namespace mojo 727 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/handle_transport.h ('k') | mojo/edk/system/multiprocess_message_pipe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698