| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/mac/mach_port_broker.h" | 5 #include "base/mac/mach_port_broker.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/test/multiprocess_test.h" | 10 #include "base/test/multiprocess_test.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 MULTIPROCESS_TEST_MAIN(MachPortBrokerTestChild) { | 88 MULTIPROCESS_TEST_MAIN(MachPortBrokerTestChild) { |
| 89 CHECK(base::MachPortBroker::ChildSendTaskPortToParent(kBootstrapPortName)); | 89 CHECK(base::MachPortBroker::ChildSendTaskPortToParent(kBootstrapPortName)); |
| 90 return 0; | 90 return 0; |
| 91 } | 91 } |
| 92 | 92 |
| 93 TEST_F(MachPortBrokerTest, ReceivePortFromChild) { | 93 TEST_F(MachPortBrokerTest, ReceivePortFromChild) { |
| 94 ASSERT_TRUE(broker_.Init()); | 94 ASSERT_TRUE(broker_.Init()); |
| 95 CommandLine command_line( | 95 CommandLine command_line( |
| 96 base::GetMultiProcessTestChildBaseCommandLine()); | 96 base::GetMultiProcessTestChildBaseCommandLine()); |
| 97 broker_.GetLock().Acquire(); | 97 broker_.GetLock().Acquire(); |
| 98 base::Process test_child_process = base::SpawnMultiProcessTestChild( | 98 base::SpawnChildResult spawn_result = base::SpawnMultiProcessTestChild( |
| 99 "MachPortBrokerTestChild", command_line, LaunchOptions()); | 99 "MachPortBrokerTestChild", command_line, LaunchOptions()); |
| 100 base::Process test_child_process = std::move(spawn_result.process); |
| 100 broker_.AddPlaceholderForPid(test_child_process.Handle()); | 101 broker_.AddPlaceholderForPid(test_child_process.Handle()); |
| 101 broker_.GetLock().Release(); | 102 broker_.GetLock().Release(); |
| 102 | 103 |
| 103 WaitForTaskPort(); | 104 WaitForTaskPort(); |
| 104 EXPECT_EQ(test_child_process.Handle(), received_process_); | 105 EXPECT_EQ(test_child_process.Handle(), received_process_); |
| 105 | 106 |
| 106 int rv = -1; | 107 int rv = -1; |
| 107 ASSERT_TRUE(test_child_process.WaitForExitWithTimeout( | 108 ASSERT_TRUE(test_child_process.WaitForExitWithTimeout( |
| 108 TestTimeouts::action_timeout(), &rv)); | 109 TestTimeouts::action_timeout(), &rv)); |
| 109 EXPECT_EQ(0, rv); | 110 EXPECT_EQ(0, rv); |
| 110 | 111 |
| 111 EXPECT_NE(static_cast<mach_port_t>(MACH_PORT_NULL), | 112 EXPECT_NE(static_cast<mach_port_t>(MACH_PORT_NULL), |
| 112 broker_.TaskForPid(test_child_process.Handle())); | 113 broker_.TaskForPid(test_child_process.Handle())); |
| 113 } | 114 } |
| 114 | 115 |
| 115 TEST_F(MachPortBrokerTest, ReceivePortFromChildWithoutAdding) { | 116 TEST_F(MachPortBrokerTest, ReceivePortFromChildWithoutAdding) { |
| 116 ASSERT_TRUE(broker_.Init()); | 117 ASSERT_TRUE(broker_.Init()); |
| 117 CommandLine command_line( | 118 CommandLine command_line( |
| 118 base::GetMultiProcessTestChildBaseCommandLine()); | 119 base::GetMultiProcessTestChildBaseCommandLine()); |
| 119 broker_.GetLock().Acquire(); | 120 broker_.GetLock().Acquire(); |
| 120 base::Process test_child_process = base::SpawnMultiProcessTestChild( | 121 base::SpawnChildResult spawn_result = base::SpawnMultiProcessTestChild( |
| 121 "MachPortBrokerTestChild", command_line, LaunchOptions()); | 122 "MachPortBrokerTestChild", command_line, LaunchOptions()); |
| 123 base::Process test_child_process = std::move(spawn_result.process); |
| 124 |
| 122 broker_.GetLock().Release(); | 125 broker_.GetLock().Release(); |
| 123 | 126 |
| 124 int rv = -1; | 127 int rv = -1; |
| 125 ASSERT_TRUE(test_child_process.WaitForExitWithTimeout( | 128 ASSERT_TRUE(test_child_process.WaitForExitWithTimeout( |
| 126 TestTimeouts::action_timeout(), &rv)); | 129 TestTimeouts::action_timeout(), &rv)); |
| 127 EXPECT_EQ(0, rv); | 130 EXPECT_EQ(0, rv); |
| 128 | 131 |
| 129 EXPECT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL), | 132 EXPECT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL), |
| 130 broker_.TaskForPid(test_child_process.Handle())); | 133 broker_.TaskForPid(test_child_process.Handle())); |
| 131 } | 134 } |
| 132 | 135 |
| 133 } // namespace base | 136 } // namespace base |
| OLD | NEW |