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.h" | 15 #include "util/mach/mach_message.h" |
16 | 16 |
| 17 #include <unistd.h> |
| 18 |
17 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
| 20 #include "base/mac/scoped_mach_port.h" |
18 #include "gtest/gtest.h" | 21 #include "gtest/gtest.h" |
19 #include "util/mach/mach_extensions.h" | 22 #include "util/mach/mach_extensions.h" |
| 23 #include "util/test/mac/mach_errors.h" |
20 | 24 |
21 namespace crashpad { | 25 namespace crashpad { |
22 namespace test { | 26 namespace test { |
23 namespace { | 27 namespace { |
24 | 28 |
25 TEST(MachMessage, MachMessageDeadlineFromTimeout) { | 29 TEST(MachMessage, MachMessageDeadlineFromTimeout) { |
26 MachMessageDeadline deadline_0 = | 30 MachMessageDeadline deadline_0 = |
27 MachMessageDeadlineFromTimeout(kMachMessageTimeoutNonblocking); | 31 MachMessageDeadlineFromTimeout(kMachMessageTimeoutNonblocking); |
28 EXPECT_EQ(kMachMessageDeadlineNonblocking, deadline_0); | 32 EXPECT_EQ(kMachMessageDeadlineNonblocking, deadline_0); |
29 | 33 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 union TestMessage { | 101 union TestMessage { |
98 TestSendMessage send; | 102 TestSendMessage send; |
99 TestReceiveMessage receive; | 103 TestReceiveMessage receive; |
100 }; | 104 }; |
101 | 105 |
102 TestMessage test; | 106 TestMessage test; |
103 test.send.msgh_size = sizeof(TestSendMessage); | 107 test.send.msgh_size = sizeof(TestSendMessage); |
104 EXPECT_EQ(&test.receive.trailer, MachMessageTrailerFromHeader(&test.receive)); | 108 EXPECT_EQ(&test.receive.trailer, MachMessageTrailerFromHeader(&test.receive)); |
105 } | 109 } |
106 | 110 |
| 111 TEST(MachMessage, AuditPIDFromMachMessageTrailer) { |
| 112 base::mac::ScopedMachReceiveRight port(NewMachPort(MACH_PORT_RIGHT_RECEIVE)); |
| 113 ASSERT_NE(kMachPortNull, port); |
| 114 |
| 115 mach_msg_empty_send_t send = {}; |
| 116 send.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND_ONCE, 0); |
| 117 send.header.msgh_size = sizeof(send); |
| 118 send.header.msgh_remote_port = port; |
| 119 mach_msg_return_t mr = |
| 120 MachMessageWithDeadline(&send.header, |
| 121 MACH_SEND_MSG, |
| 122 0, |
| 123 MACH_PORT_NULL, |
| 124 kMachMessageDeadlineNonblocking, |
| 125 MACH_PORT_NULL, |
| 126 false); |
| 127 ASSERT_EQ(MACH_MSG_SUCCESS, mr) |
| 128 << MachErrorMessage(mr, "MachMessageWithDeadline send"); |
| 129 |
| 130 struct EmptyReceiveMessageWithAuditTrailer : public mach_msg_empty_send_t { |
| 131 union { |
| 132 mach_msg_trailer_t trailer; |
| 133 mach_msg_audit_trailer_t audit_trailer; |
| 134 }; |
| 135 }; |
| 136 |
| 137 EmptyReceiveMessageWithAuditTrailer receive; |
| 138 mr = MachMessageWithDeadline(&receive.header, |
| 139 MACH_RCV_MSG | kMachMessageReceiveAuditTrailer, |
| 140 sizeof(receive), |
| 141 port, |
| 142 kMachMessageDeadlineNonblocking, |
| 143 MACH_PORT_NULL, |
| 144 false); |
| 145 ASSERT_EQ(MACH_MSG_SUCCESS, mr) |
| 146 << MachErrorMessage(mr, "MachMessageWithDeadline receive"); |
| 147 |
| 148 EXPECT_EQ(getpid(), AuditPIDFromMachMessageTrailer(&receive.trailer)); |
| 149 } |
| 150 |
107 } // namespace | 151 } // namespace |
108 } // namespace test | 152 } // namespace test |
109 } // namespace crashpad | 153 } // namespace crashpad |
OLD | NEW |