Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: util/mach/exc_server_variants_test.cc

Issue 1305893010: Don’t trigger EXC_CORPSE_NOTIFY on OS X 10.11 (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/exc_server_variants.h" 15 #include "util/mach/exc_server_variants.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/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "gmock/gmock.h" 21 #include "gmock/gmock.h"
22 #include "gtest/gtest.h" 22 #include "gtest/gtest.h"
23 #include "test/mac/mach_errors.h" 23 #include "test/mac/mach_errors.h"
24 #include "test/mac/mach_multiprocess.h" 24 #include "test/mac/mach_multiprocess.h"
25 #include "util/mac/mac_util.h"
25 #include "util/mach/exception_behaviors.h" 26 #include "util/mach/exception_behaviors.h"
26 #include "util/mach/exception_types.h" 27 #include "util/mach/exception_types.h"
27 #include "util/mach/mach_message.h" 28 #include "util/mach/mach_message.h"
28 29
29 namespace crashpad { 30 namespace crashpad {
30 namespace test { 31 namespace test {
31 namespace { 32 namespace {
32 33
33 using testing::DefaultValue; 34 using testing::DefaultValue;
34 using testing::Eq; 35 using testing::Eq;
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 } 1029 }
1029 1030
1030 EXPECT_EQ(implicit_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0), 1031 EXPECT_EQ(implicit_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0),
1031 trailer->msgh_trailer_type); 1032 trailer->msgh_trailer_type);
1032 EXPECT_EQ(REQUESTED_TRAILER_SIZE(kMachMessageOptions), 1033 EXPECT_EQ(REQUESTED_TRAILER_SIZE(kMachMessageOptions),
1033 trailer->msgh_trailer_size); 1034 trailer->msgh_trailer_size);
1034 1035
1035 ExcServerCopyState( 1036 ExcServerCopyState(
1036 behavior, old_state, old_state_count, new_state, new_state_count); 1037 behavior, old_state, old_state_count, new_state, new_state_count);
1037 1038
1038 return ExcServerSuccessfulReturnValue(behavior, false); 1039 return ExcServerSuccessfulReturnValue(exception, behavior, false);
1039 } 1040 }
1040 1041
1041 private: 1042 private:
1042 // MachMultiprocess: 1043 // MachMultiprocess:
1043 1044
1044 void MachMultiprocessParent() override { 1045 void MachMultiprocessParent() override {
1045 UniversalMachExcServer universal_mach_exc_server(this); 1046 UniversalMachExcServer universal_mach_exc_server(this);
1046 1047
1047 kern_return_t kr = 1048 kern_return_t kr =
1048 MachMessageServer::Run(&universal_mach_exc_server, 1049 MachMessageServer::Run(&universal_mach_exc_server,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 1180
1180 TestExcServerVariants test_exc_server_variants( 1181 TestExcServerVariants test_exc_server_variants(
1181 MACH_EXCEPTION_CODES | EXCEPTION_STATE_IDENTITY, 1182 MACH_EXCEPTION_CODES | EXCEPTION_STATE_IDENTITY,
1182 test.flavor, 1183 test.flavor,
1183 test.count); 1184 test.count);
1184 test_exc_server_variants.Run(); 1185 test_exc_server_variants.Run();
1185 } 1186 }
1186 } 1187 }
1187 1188
1188 TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) { 1189 TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) {
1190 const kern_return_t prefer_not_set_thread_state =
1191 MacOSXMinorVersion() < 11 ? MACH_RCV_PORT_DIED : KERN_SUCCESS;
1192
1189 struct TestData { 1193 struct TestData {
1194 exception_type_t exception;
1190 exception_behavior_t behavior; 1195 exception_behavior_t behavior;
1191 bool set_thread_state; 1196 bool set_thread_state;
1192 kern_return_t kr; 1197 kern_return_t kr;
1193 }; 1198 };
1194 const TestData kTestData[] = { 1199 const TestData kTestData[] = {
1195 {EXCEPTION_DEFAULT, false, KERN_SUCCESS}, 1200 {EXC_CRASH, EXCEPTION_DEFAULT, false, KERN_SUCCESS},
1196 {EXCEPTION_STATE, false, MACH_RCV_PORT_DIED}, 1201 {EXC_CRASH, EXCEPTION_STATE, false, prefer_not_set_thread_state},
1197 {EXCEPTION_STATE_IDENTITY, false, MACH_RCV_PORT_DIED}, 1202 {EXC_CRASH, EXCEPTION_STATE_IDENTITY, false, prefer_not_set_thread_state},
1198 {kMachExceptionCodes | EXCEPTION_DEFAULT, false, KERN_SUCCESS}, 1203 {EXC_CRASH, kMachExceptionCodes | EXCEPTION_DEFAULT, false, KERN_SUCCESS},
1199 {kMachExceptionCodes | EXCEPTION_STATE, false, MACH_RCV_PORT_DIED}, 1204 {EXC_CRASH,
1200 {kMachExceptionCodes | EXCEPTION_STATE_IDENTITY, 1205 kMachExceptionCodes | EXCEPTION_STATE,
1206 false,
1207 prefer_not_set_thread_state},
1208 {EXC_CRASH,
1209 kMachExceptionCodes | EXCEPTION_STATE_IDENTITY,
1210 false,
1211 prefer_not_set_thread_state},
1212 {EXC_CRASH, EXCEPTION_DEFAULT, true, KERN_SUCCESS},
1213 {EXC_CRASH, EXCEPTION_STATE, true, KERN_SUCCESS},
1214 {EXC_CRASH, EXCEPTION_STATE_IDENTITY, true, KERN_SUCCESS},
1215 {EXC_CRASH, kMachExceptionCodes | EXCEPTION_DEFAULT, true, KERN_SUCCESS},
1216 {EXC_CRASH, kMachExceptionCodes | EXCEPTION_STATE, true, KERN_SUCCESS},
1217 {EXC_CRASH,
1218 kMachExceptionCodes | EXCEPTION_STATE_IDENTITY,
1219 true,
1220 KERN_SUCCESS},
1221
Robert Sesek 2015/09/04 17:29:49 Extra blank line?
1222 {EXC_BAD_ACCESS, EXCEPTION_DEFAULT, false, KERN_SUCCESS},
1223 {EXC_BAD_INSTRUCTION, EXCEPTION_STATE, false, MACH_RCV_PORT_DIED},
1224 {EXC_ARITHMETIC, EXCEPTION_STATE_IDENTITY, false, MACH_RCV_PORT_DIED},
1225 {EXC_EMULATION,
1226 kMachExceptionCodes | EXCEPTION_DEFAULT,
1227 false,
1228 KERN_SUCCESS},
1229 {EXC_SOFTWARE,
1230 kMachExceptionCodes | EXCEPTION_STATE,
1201 false, 1231 false,
1202 MACH_RCV_PORT_DIED}, 1232 MACH_RCV_PORT_DIED},
1203 {EXCEPTION_DEFAULT, true, KERN_SUCCESS}, 1233 {EXC_BREAKPOINT,
1204 {EXCEPTION_STATE, true, KERN_SUCCESS}, 1234 kMachExceptionCodes | EXCEPTION_STATE_IDENTITY,
1205 {EXCEPTION_STATE_IDENTITY, true, KERN_SUCCESS}, 1235 false,
1206 {kMachExceptionCodes | EXCEPTION_DEFAULT, true, KERN_SUCCESS}, 1236 MACH_RCV_PORT_DIED},
1207 {kMachExceptionCodes | EXCEPTION_STATE, true, KERN_SUCCESS}, 1237 {EXC_SYSCALL, EXCEPTION_DEFAULT, true, KERN_SUCCESS},
1208 {kMachExceptionCodes | EXCEPTION_STATE_IDENTITY, true, KERN_SUCCESS}, 1238 {EXC_MACH_SYSCALL, EXCEPTION_STATE, true, KERN_SUCCESS},
1239 {EXC_RPC_ALERT, EXCEPTION_STATE_IDENTITY, true, KERN_SUCCESS},
1240 {EXC_RESOURCE,
1241 kMachExceptionCodes | EXCEPTION_DEFAULT,
1242 true,
1243 KERN_SUCCESS},
1244 {EXC_GUARD, kMachExceptionCodes | EXCEPTION_STATE, true, KERN_SUCCESS},
1245 {EXC_CORPSE_NOTIFY,
1246 kMachExceptionCodes | EXCEPTION_STATE_IDENTITY,
1247 true,
1248 KERN_SUCCESS},
1209 }; 1249 };
1210 1250
1211 for (size_t index = 0; index < arraysize(kTestData); ++index) { 1251 for (size_t index = 0; index < arraysize(kTestData); ++index) {
1212 const TestData& test_data = kTestData[index]; 1252 const TestData& test_data = kTestData[index];
1213 SCOPED_TRACE( 1253 SCOPED_TRACE(
1214 base::StringPrintf("index %zu, behavior %d, set_thread_state %s", 1254 base::StringPrintf("index %zu, behavior %d, set_thread_state %s",
1215 index, 1255 index,
1216 test_data.behavior, 1256 test_data.behavior,
1217 test_data.set_thread_state ? "true" : "false")); 1257 test_data.set_thread_state ? "true" : "false"));
1218 1258
1219 EXPECT_EQ(test_data.kr, 1259 EXPECT_EQ(test_data.kr,
1220 ExcServerSuccessfulReturnValue(test_data.behavior, 1260 ExcServerSuccessfulReturnValue(test_data.exception,
1261 test_data.behavior,
1221 test_data.set_thread_state)); 1262 test_data.set_thread_state));
1222 } 1263 }
1223 } 1264 }
1224 1265
1225 TEST(ExcServerVariants, ExcServerCopyState) { 1266 TEST(ExcServerVariants, ExcServerCopyState) {
1226 const natural_t old_state[] = {1, 2, 3, 4, 5}; 1267 const natural_t old_state[] = {1, 2, 3, 4, 5};
1227 natural_t new_state[10] = {}; 1268 natural_t new_state[10] = {};
1228 1269
1229 const mach_msg_type_number_t old_state_count = arraysize(old_state); 1270 const mach_msg_type_number_t old_state_count = arraysize(old_state);
1230 mach_msg_type_number_t new_state_count = arraysize(new_state); 1271 mach_msg_type_number_t new_state_count = arraysize(new_state);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 EXPECT_EQ(old_state[i], new_state[i]) << "i " << i; 1333 EXPECT_EQ(old_state[i], new_state[i]) << "i " << i;
1293 } 1334 }
1294 for (size_t i = arraysize(old_state); i < arraysize(new_state); ++i) { 1335 for (size_t i = arraysize(old_state); i < arraysize(new_state); ++i) {
1295 EXPECT_EQ(0u, new_state[i]) << "i " << i; 1336 EXPECT_EQ(0u, new_state[i]) << "i " << i;
1296 } 1337 }
1297 } 1338 }
1298 1339
1299 } // namespace 1340 } // namespace
1300 } // namespace test 1341 } // namespace test
1301 } // namespace crashpad 1342 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698