OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "util/mach/mach_message_server.h" | 15 #include "util/mach/mach_message_server.h" |
16 | 16 |
17 #include <mach/mach.h> | 17 #include <mach/mach.h> |
18 #include <string.h> | 18 #include <string.h> |
19 | 19 |
20 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
21 #include "base/mac/scoped_mach_port.h" | 21 #include "base/mac/scoped_mach_port.h" |
22 #include "gtest/gtest.h" | 22 #include "gtest/gtest.h" |
23 #include "util/file/fd_io.h" | 23 #include "util/file/fd_io.h" |
| 24 #include "util/mach/mach_extensions.h" |
24 #include "util/test/errors.h" | 25 #include "util/test/errors.h" |
25 #include "util/test/mac/mach_errors.h" | 26 #include "util/test/mac/mach_errors.h" |
26 #include "util/test/mac/mach_multiprocess.h" | 27 #include "util/test/mac/mach_multiprocess.h" |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 using namespace crashpad; | 31 using namespace crashpad; |
31 using namespace crashpad::test; | 32 using namespace crashpad::test; |
32 | 33 |
33 class TestMachMessageServer : public MachMessageServer::Interface, | 34 class TestMachMessageServer : public MachMessageServer::Interface, |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 EXPECT_EQ(options_.client_send_large ? sizeof(LargeRequestMessage) : | 208 EXPECT_EQ(options_.client_send_large ? sizeof(LargeRequestMessage) : |
208 sizeof(RequestMessage), | 209 sizeof(RequestMessage), |
209 request->header.msgh_size); | 210 request->header.msgh_size); |
210 if (options_.client_reply_port_type == Options::kReplyPortNormal) { | 211 if (options_.client_reply_port_type == Options::kReplyPortNormal) { |
211 EXPECT_EQ(RemotePort(), request->header.msgh_remote_port); | 212 EXPECT_EQ(RemotePort(), request->header.msgh_remote_port); |
212 } | 213 } |
213 EXPECT_EQ(LocalPort(), request->header.msgh_local_port); | 214 EXPECT_EQ(LocalPort(), request->header.msgh_local_port); |
214 EXPECT_EQ(kRequestMessageId, request->header.msgh_id); | 215 EXPECT_EQ(kRequestMessageId, request->header.msgh_id); |
215 if (options_.client_send_complex) { | 216 if (options_.client_send_complex) { |
216 EXPECT_EQ(1u, request->body.msgh_descriptor_count); | 217 EXPECT_EQ(1u, request->body.msgh_descriptor_count); |
217 EXPECT_NE(static_cast<mach_port_t>(MACH_PORT_NULL), | 218 EXPECT_NE(kMachPortNull, request->port_descriptor.name); |
218 request->port_descriptor.name); | |
219 parent_complex_message_port_ = request->port_descriptor.name; | 219 parent_complex_message_port_ = request->port_descriptor.name; |
220 EXPECT_EQ(static_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_MOVE_SEND), | 220 EXPECT_EQ(static_cast<mach_msg_type_name_t>(MACH_MSG_TYPE_MOVE_SEND), |
221 request->port_descriptor.disposition); | 221 request->port_descriptor.disposition); |
222 EXPECT_EQ( | 222 EXPECT_EQ( |
223 static_cast<mach_msg_descriptor_type_t>(MACH_MSG_PORT_DESCRIPTOR), | 223 static_cast<mach_msg_descriptor_type_t>(MACH_MSG_PORT_DESCRIPTOR), |
224 request->port_descriptor.type); | 224 request->port_descriptor.type); |
225 } else { | 225 } else { |
226 EXPECT_EQ(0u, request->body.msgh_descriptor_count); | 226 EXPECT_EQ(0u, request->body.msgh_descriptor_count); |
227 EXPECT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL), | 227 EXPECT_EQ(kMachPortNull, request->port_descriptor.name); |
228 request->port_descriptor.name); | |
229 EXPECT_EQ(0u, request->port_descriptor.disposition); | 228 EXPECT_EQ(0u, request->port_descriptor.disposition); |
230 EXPECT_EQ(0u, request->port_descriptor.type); | 229 EXPECT_EQ(0u, request->port_descriptor.type); |
231 } | 230 } |
232 EXPECT_EQ(0, memcmp(&request->ndr, &NDR_record, sizeof(NDR_record))); | 231 EXPECT_EQ(0, memcmp(&request->ndr, &NDR_record, sizeof(NDR_record))); |
233 EXPECT_EQ(requests_, request->number); | 232 EXPECT_EQ(requests_, request->number); |
234 | 233 |
235 // Look for the trailer in the right spot, depending on whether the request | 234 // Look for the trailer in the right spot, depending on whether the request |
236 // message was a RequestMessage or a LargeRequestMessage. | 235 // message was a RequestMessage or a LargeRequestMessage. |
237 const mach_msg_trailer_t* trailer; | 236 const mach_msg_trailer_t* trailer; |
238 if (options_.client_send_large) { | 237 if (options_.client_send_large) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 ASSERT_EQ(options_.expect_server_result, | 310 ASSERT_EQ(options_.expect_server_result, |
312 (kr = MachMessageServer::Run(this, | 311 (kr = MachMessageServer::Run(this, |
313 LocalPort(), | 312 LocalPort(), |
314 options_.server_options, | 313 options_.server_options, |
315 options_.server_persistent, | 314 options_.server_persistent, |
316 options_.server_nonblocking, | 315 options_.server_nonblocking, |
317 options_.server_timeout_ms))) | 316 options_.server_timeout_ms))) |
318 << MachErrorMessage(kr, "MachMessageServer"); | 317 << MachErrorMessage(kr, "MachMessageServer"); |
319 | 318 |
320 if (options_.client_send_complex) { | 319 if (options_.client_send_complex) { |
321 EXPECT_NE(static_cast<mach_port_t>(MACH_PORT_NULL), | 320 EXPECT_NE(kMachPortNull, parent_complex_message_port_); |
322 parent_complex_message_port_); | |
323 mach_port_type_t type; | 321 mach_port_type_t type; |
324 | 322 |
325 if (!options_.expect_server_destroyed_complex) { | 323 if (!options_.expect_server_destroyed_complex) { |
326 // MachMessageServer should not have destroyed the resources sent in the | 324 // MachMessageServer should not have destroyed the resources sent in the |
327 // complex request message. | 325 // complex request message. |
328 kr = mach_port_type( | 326 kr = mach_port_type( |
329 mach_task_self(), parent_complex_message_port_, &type); | 327 mach_task_self(), parent_complex_message_port_, &type); |
330 EXPECT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "mach_port_type"); | 328 EXPECT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "mach_port_type"); |
331 EXPECT_EQ(MACH_PORT_TYPE_SEND, type); | 329 EXPECT_EQ(MACH_PORT_TYPE_SEND, type); |
332 | 330 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 0, | 496 0, |
499 sizeof(reply), | 497 sizeof(reply), |
500 LocalPort(), | 498 LocalPort(), |
501 MACH_MSG_TIMEOUT_NONE, | 499 MACH_MSG_TIMEOUT_NONE, |
502 MACH_PORT_NULL); | 500 MACH_PORT_NULL); |
503 ASSERT_EQ(MACH_MSG_SUCCESS, kr) << MachErrorMessage(kr, "mach_msg"); | 501 ASSERT_EQ(MACH_MSG_SUCCESS, kr) << MachErrorMessage(kr, "mach_msg"); |
504 | 502 |
505 ASSERT_EQ(static_cast<mach_msg_bits_t>( | 503 ASSERT_EQ(static_cast<mach_msg_bits_t>( |
506 MACH_MSGH_BITS(0, MACH_MSG_TYPE_MOVE_SEND)), reply.Head.msgh_bits); | 504 MACH_MSGH_BITS(0, MACH_MSG_TYPE_MOVE_SEND)), reply.Head.msgh_bits); |
507 ASSERT_EQ(sizeof(ReplyMessage), reply.Head.msgh_size); | 505 ASSERT_EQ(sizeof(ReplyMessage), reply.Head.msgh_size); |
508 ASSERT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL), | 506 ASSERT_EQ(kMachPortNull, reply.Head.msgh_remote_port); |
509 reply.Head.msgh_remote_port); | |
510 ASSERT_EQ(LocalPort(), reply.Head.msgh_local_port); | 507 ASSERT_EQ(LocalPort(), reply.Head.msgh_local_port); |
511 ASSERT_EQ(kReplyMessageId, reply.Head.msgh_id); | 508 ASSERT_EQ(kReplyMessageId, reply.Head.msgh_id); |
512 ASSERT_EQ(0, memcmp(&reply.NDR, &NDR_record, sizeof(NDR_record))); | 509 ASSERT_EQ(0, memcmp(&reply.NDR, &NDR_record, sizeof(NDR_record))); |
513 ASSERT_EQ(options_.server_mig_retcode, reply.RetCode); | 510 ASSERT_EQ(options_.server_mig_retcode, reply.RetCode); |
514 ASSERT_EQ(replies_, reply.number); | 511 ASSERT_EQ(replies_, reply.number); |
515 ASSERT_EQ(static_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0), | 512 ASSERT_EQ(static_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0), |
516 reply.trailer.msgh_trailer_type); | 513 reply.trailer.msgh_trailer_type); |
517 ASSERT_EQ(MACH_MSG_TRAILER_MINIMUM_SIZE, reply.trailer.msgh_trailer_size); | 514 ASSERT_EQ(MACH_MSG_TRAILER_MINIMUM_SIZE, reply.trailer.msgh_trailer_size); |
518 | 515 |
519 ++replies_; | 516 ++replies_; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 // so a new buffer is allocated to receive the message. The server receives | 798 // so a new buffer is allocated to receive the message. The server receives |
802 // the large request message, processes it, and returns a reply to the client. | 799 // the large request message, processes it, and returns a reply to the client. |
803 TestMachMessageServer::Options options; | 800 TestMachMessageServer::Options options; |
804 options.server_options = MACH_RCV_LARGE; | 801 options.server_options = MACH_RCV_LARGE; |
805 options.client_send_large = true; | 802 options.client_send_large = true; |
806 TestMachMessageServer test_mach_message_server(options); | 803 TestMachMessageServer test_mach_message_server(options); |
807 test_mach_message_server.Test(); | 804 test_mach_message_server.Test(); |
808 } | 805 } |
809 | 806 |
810 } // namespace | 807 } // namespace |
OLD | NEW |