OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sandbox/mac/xpc_message_server.h" | 5 #include "sandbox/mac/xpc_message_server.h" |
6 | 6 |
7 #include <Block.h> | 7 #include <Block.h> |
8 #include <mach/mach.h> | 8 #include <mach/mach.h> |
9 #include <servers/bootstrap.h> | 9 #include <servers/bootstrap.h> |
10 | 10 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 child_pid = xpc_dictionary_get_int64(request.xpc, "child_pid"); | 142 child_pid = xpc_dictionary_get_int64(request.xpc, "child_pid"); |
143 })); | 143 })); |
144 | 144 |
145 #pragma GCC diagnostic push | 145 #pragma GCC diagnostic push |
146 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | 146 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
147 kern_return_t kr = bootstrap_register(bootstrap_port, kGetSenderPID, | 147 kern_return_t kr = bootstrap_register(bootstrap_port, kGetSenderPID, |
148 server->GetServerPort()); | 148 server->GetServerPort()); |
149 #pragma GCC diagnostic pop | 149 #pragma GCC diagnostic pop |
150 ASSERT_EQ(KERN_SUCCESS, kr); | 150 ASSERT_EQ(KERN_SUCCESS, kr); |
151 | 151 |
152 base::ProcessHandle child_handle = base::SpawnMultiProcessTestChild( | 152 base::Process child = base::SpawnMultiProcessTestChild( |
153 "GetSenderPID", | 153 "GetSenderPID", |
154 base::GetMultiProcessTestChildBaseCommandLine(), | 154 base::GetMultiProcessTestChildBaseCommandLine(), |
155 base::LaunchOptions()); | 155 base::LaunchOptions()); |
156 ASSERT_NE(base::kNullProcessHandle, child_handle); | 156 ASSERT_TRUE(child.IsValid()); |
157 | 157 |
158 int exit_code = -1; | 158 int exit_code = -1; |
159 ASSERT_TRUE(base::WaitForExitCode(child_handle, &exit_code)); | 159 ASSERT_TRUE(child.WaitForExit(&exit_code)); |
160 EXPECT_EQ(0, exit_code); | 160 EXPECT_EQ(0, exit_code); |
161 | 161 |
162 EXPECT_EQ(base::GetProcId(child_handle), sender_pid); | 162 EXPECT_EQ(child.pid(), sender_pid); |
163 EXPECT_EQ(base::GetProcId(child_handle), child_pid); | 163 EXPECT_EQ(child.pid(), child_pid); |
164 EXPECT_EQ(sender_pid, child_pid); | 164 EXPECT_EQ(sender_pid, child_pid); |
165 | |
166 base::CloseProcessHandle(child_handle); | |
167 } | 165 } |
168 | 166 |
169 MULTIPROCESS_TEST_MAIN(GetSenderPID) { | 167 MULTIPROCESS_TEST_MAIN(GetSenderPID) { |
170 CHECK(sandbox::InitializeXPC()); | 168 CHECK(sandbox::InitializeXPC()); |
171 | 169 |
172 mach_port_t port = MACH_PORT_NULL; | 170 mach_port_t port = MACH_PORT_NULL; |
173 CHECK_EQ(KERN_SUCCESS, bootstrap_look_up(bootstrap_port, kGetSenderPID, | 171 CHECK_EQ(KERN_SUCCESS, bootstrap_look_up(bootstrap_port, kGetSenderPID, |
174 &port)); | 172 &port)); |
175 base::mac::ScopedMachSendRight scoped_port(port); | 173 base::mac::ScopedMachSendRight scoped_port(port); |
176 | 174 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 ASSERT_EQ(0, xpc_pipe_routine(first.pipe(), request, &reply)); | 208 ASSERT_EQ(0, xpc_pipe_routine(first.pipe(), request, &reply)); |
211 | 209 |
212 EXPECT_EQ(1, xpc_dictionary_get_int64(reply, "seen_by_first")); | 210 EXPECT_EQ(1, xpc_dictionary_get_int64(reply, "seen_by_first")); |
213 EXPECT_EQ(2, xpc_dictionary_get_int64(reply, "seen_by_second")); | 211 EXPECT_EQ(2, xpc_dictionary_get_int64(reply, "seen_by_second")); |
214 | 212 |
215 xpc_release(request); | 213 xpc_release(request); |
216 xpc_release(reply); | 214 xpc_release(reply); |
217 } | 215 } |
218 | 216 |
219 } // namespace sandbox | 217 } // namespace sandbox |
OLD | NEW |