Chromium Code Reviews

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

Issue 1651183003: Make PlatformChannelPair "dumb". (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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
(...skipping 157 matching lines...)
168 connection_id_(master_ipc_support_->GenerateConnectionIdentifier()), 168 connection_id_(master_ipc_support_->GenerateConnectionIdentifier()),
169 slave_id_(kInvalidProcessIdentifier) {} 169 slave_id_(kInvalidProcessIdentifier) {}
170 ~TestSlaveConnection() {} 170 ~TestSlaveConnection() {}
171 171
172 // After this is called, |ShutdownChannelToSlave()| must be called (possibly 172 // After this is called, |ShutdownChannelToSlave()| must be called (possibly
173 // after |WaitForChannelToSlave()|) before destruction. 173 // after |WaitForChannelToSlave()|) before destruction.
174 RefPtr<MessagePipeDispatcher> ConnectToSlave() { 174 RefPtr<MessagePipeDispatcher> ConnectToSlave() {
175 embedder::PlatformChannelPair channel_pair; 175 embedder::PlatformChannelPair channel_pair;
176 // Note: |ChannelId|s and |ProcessIdentifier|s are interchangeable. 176 // Note: |ChannelId|s and |ProcessIdentifier|s are interchangeable.
177 RefPtr<MessagePipeDispatcher> mp = master_ipc_support_->ConnectToSlave( 177 RefPtr<MessagePipeDispatcher> mp = master_ipc_support_->ConnectToSlave(
178 connection_id_, nullptr, channel_pair.PassServerHandle(), 178 connection_id_, nullptr, channel_pair.handle0.Pass(),
179 [this]() { event_.Signal(); }, nullptr, &slave_id_); 179 [this]() { event_.Signal(); }, nullptr, &slave_id_);
180 EXPECT_TRUE(mp); 180 EXPECT_TRUE(mp);
181 EXPECT_NE(slave_id_, kInvalidProcessIdentifier); 181 EXPECT_NE(slave_id_, kInvalidProcessIdentifier);
182 EXPECT_NE(slave_id_, kMasterProcessIdentifier); 182 EXPECT_NE(slave_id_, kMasterProcessIdentifier);
183 slave_platform_handle_ = channel_pair.PassClientHandle(); 183 slave_platform_handle_ = channel_pair.handle1.Pass();
184 return mp; 184 return mp;
185 } 185 }
186 186
187 void WaitForChannelToSlave() { 187 void WaitForChannelToSlave() {
188 EXPECT_FALSE(event_.WaitWithTimeout(test::ActionTimeout())); 188 EXPECT_FALSE(event_.WaitWithTimeout(test::ActionTimeout()));
189 } 189 }
190 190
191 void ShutdownChannelToSlave() { 191 void ShutdownChannelToSlave() {
192 // Since |event_| is manual-reset, calling this multiple times is OK. 192 // Since |event_| is manual-reset, calling this multiple times is OK.
193 WaitForChannelToSlave(); 193 WaitForChannelToSlave();
(...skipping 378 matching lines...)
572 // Note: This test isn't in an anonymous namespace, since it needs to be 572 // Note: This test isn't in an anonymous namespace, since it needs to be
573 // friended by |IPCSupport|. 573 // friended by |IPCSupport|.
574 TEST_F(IPCSupportTest, MasterSlaveInternal) { 574 TEST_F(IPCSupportTest, MasterSlaveInternal) {
575 ConnectionIdentifier connection_id = 575 ConnectionIdentifier connection_id =
576 master_ipc_support().GenerateConnectionIdentifier(); 576 master_ipc_support().GenerateConnectionIdentifier();
577 577
578 embedder::PlatformChannelPair channel_pair; 578 embedder::PlatformChannelPair channel_pair;
579 ProcessIdentifier slave_id = kInvalidProcessIdentifier; 579 ProcessIdentifier slave_id = kInvalidProcessIdentifier;
580 ScopedPlatformHandle master_second_platform_handle = 580 ScopedPlatformHandle master_second_platform_handle =
581 master_ipc_support().ConnectToSlaveInternal( 581 master_ipc_support().ConnectToSlaveInternal(
582 connection_id, nullptr, channel_pair.PassServerHandle(), &slave_id); 582 connection_id, nullptr, channel_pair.handle0.Pass(), &slave_id);
583 ASSERT_TRUE(master_second_platform_handle.is_valid()); 583 ASSERT_TRUE(master_second_platform_handle.is_valid());
584 EXPECT_NE(slave_id, kInvalidProcessIdentifier); 584 EXPECT_NE(slave_id, kInvalidProcessIdentifier);
585 EXPECT_NE(slave_id, kMasterProcessIdentifier); 585 EXPECT_NE(slave_id, kMasterProcessIdentifier);
586 586
587 TestSlaveProcessDelegate slave_process_delegate; 587 TestSlaveProcessDelegate slave_process_delegate;
588 // Note: Run process delegate methods on the I/O thread. 588 // Note: Run process delegate methods on the I/O thread.
589 IPCSupport slave_ipc_support( 589 IPCSupport slave_ipc_support(
590 &platform_support(), embedder::ProcessType::SLAVE, 590 &platform_support(), embedder::ProcessType::SLAVE,
591 test_io_thread().task_runner().Clone(), &slave_process_delegate, 591 test_io_thread().task_runner().Clone(), &slave_process_delegate,
592 test_io_thread().task_runner().Clone(), 592 test_io_thread().task_runner().Clone(),
593 test_io_thread().platform_handle_watcher(), 593 test_io_thread().platform_handle_watcher(), channel_pair.handle1.Pass());
594 channel_pair.PassClientHandle());
595 594
596 ScopedPlatformHandle slave_second_platform_handle = 595 ScopedPlatformHandle slave_second_platform_handle =
597 slave_ipc_support.ConnectToMasterInternal(connection_id); 596 slave_ipc_support.ConnectToMasterInternal(connection_id);
598 ASSERT_TRUE(slave_second_platform_handle.is_valid()); 597 ASSERT_TRUE(slave_second_platform_handle.is_valid());
599 598
600 // Write an 'x' through the master's end. 599 // Write an 'x' through the master's end.
601 size_t n = 0; 600 size_t n = 0;
602 EXPECT_TRUE(mojo::test::BlockingWrite(master_second_platform_handle.get(), 601 EXPECT_TRUE(mojo::test::BlockingWrite(master_second_platform_handle.get(),
603 "x", 1, &n)); 602 "x", 1, &n));
604 EXPECT_EQ(1u, n); 603 EXPECT_EQ(1u, n);
(...skipping 103 matching lines...)
708 707
709 test_io_thread.PostTaskAndWait( 708 test_io_thread.PostTaskAndWait(
710 [&ipc_support]() { ipc_support.ShutdownOnIOThread(); }); 709 [&ipc_support]() { ipc_support.ShutdownOnIOThread(); });
711 } 710 }
712 711
713 // TODO(vtl): Also test the case of the master "dying" before the slave. (The 712 // TODO(vtl): Also test the case of the master "dying" before the slave. (The
714 // slave should get OnMasterDisconnect(), which we currently don't test.) 713 // slave should get OnMasterDisconnect(), which we currently don't test.)
715 714
716 } // namespace system 715 } // namespace system
717 } // namespace mojo 716 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe_impl_unittest.cc ('k') | mojo/edk/system/master_connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine