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/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 <signal.h> | |
19 #include <string.h> | 18 #include <string.h> |
20 | 19 |
21 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
22 #include "gmock/gmock.h" | 21 #include "gmock/gmock.h" |
23 #include "gtest/gtest.h" | 22 #include "gtest/gtest.h" |
24 #include "test/mac/mach_errors.h" | 23 #include "test/mac/mach_errors.h" |
25 #include "test/mac/mach_multiprocess.h" | 24 #include "test/mac/mach_multiprocess.h" |
26 #include "util/mach/exception_behaviors.h" | 25 #include "util/mach/exception_behaviors.h" |
| 26 #include "util/mach/exception_types.h" |
27 #include "util/mach/mach_message.h" | 27 #include "util/mach/mach_message.h" |
28 | 28 |
29 namespace crashpad { | 29 namespace crashpad { |
30 namespace test { | 30 namespace test { |
31 namespace { | 31 namespace { |
32 | 32 |
33 using testing::DefaultValue; | 33 using testing::DefaultValue; |
34 using testing::Eq; | 34 using testing::Eq; |
35 using testing::Pointee; | 35 using testing::Pointee; |
36 using testing::Return; | 36 using testing::Return; |
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 base::StringPrintf("index %zu, flavor %d", index, test.flavor)); | 1178 base::StringPrintf("index %zu, flavor %d", index, test.flavor)); |
1179 | 1179 |
1180 TestExcServerVariants test_exc_server_variants( | 1180 TestExcServerVariants test_exc_server_variants( |
1181 MACH_EXCEPTION_CODES | EXCEPTION_STATE_IDENTITY, | 1181 MACH_EXCEPTION_CODES | EXCEPTION_STATE_IDENTITY, |
1182 test.flavor, | 1182 test.flavor, |
1183 test.count); | 1183 test.count); |
1184 test_exc_server_variants.Run(); | 1184 test_exc_server_variants.Run(); |
1185 } | 1185 } |
1186 } | 1186 } |
1187 | 1187 |
1188 TEST(ExcServerVariants, ExcCrashRecoverOriginalException) { | |
1189 struct TestData { | |
1190 mach_exception_code_t code_0; | |
1191 exception_type_t exception; | |
1192 mach_exception_code_t original_code_0; | |
1193 int signal; | |
1194 }; | |
1195 const TestData kTestData[] = { | |
1196 {0xb100001, EXC_BAD_ACCESS, KERN_INVALID_ADDRESS, SIGSEGV}, | |
1197 {0xb100002, EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE, SIGSEGV}, | |
1198 {0xa100002, EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE, SIGBUS}, | |
1199 {0x4200001, EXC_BAD_INSTRUCTION, 1, SIGILL}, | |
1200 {0x8300001, EXC_ARITHMETIC, 1, SIGFPE}, | |
1201 {0x5600002, EXC_BREAKPOINT, 2, SIGTRAP}, | |
1202 {0x3000000, 0, 0, SIGQUIT}, | |
1203 {0x6000000, 0, 0, SIGABRT}, | |
1204 {0xc000000, 0, 0, SIGSYS}, | |
1205 {0, 0, 0, 0}, | |
1206 }; | |
1207 | |
1208 for (size_t index = 0; index < arraysize(kTestData); ++index) { | |
1209 const TestData& test_data = kTestData[index]; | |
1210 SCOPED_TRACE(base::StringPrintf( | |
1211 "index %zu, code_0 0x%llx", index, test_data.code_0)); | |
1212 | |
1213 mach_exception_code_t original_code_0; | |
1214 int signal; | |
1215 exception_type_t exception = ExcCrashRecoverOriginalException( | |
1216 test_data.code_0, &original_code_0, &signal); | |
1217 | |
1218 EXPECT_EQ(test_data.exception, exception); | |
1219 EXPECT_EQ(test_data.original_code_0, original_code_0); | |
1220 EXPECT_EQ(test_data.signal, signal); | |
1221 } | |
1222 | |
1223 // Now make sure that ExcCrashRecoverOriginalException() properly ignores | |
1224 // optional arguments. | |
1225 static_assert(arraysize(kTestData) >= 1, "must have something to test"); | |
1226 const TestData& test_data = kTestData[0]; | |
1227 EXPECT_EQ( | |
1228 test_data.exception, | |
1229 ExcCrashRecoverOriginalException(test_data.code_0, nullptr, nullptr)); | |
1230 | |
1231 mach_exception_code_t original_code_0; | |
1232 EXPECT_EQ(test_data.exception, | |
1233 ExcCrashRecoverOriginalException( | |
1234 test_data.code_0, &original_code_0, nullptr)); | |
1235 EXPECT_EQ(test_data.original_code_0, original_code_0); | |
1236 | |
1237 int signal; | |
1238 EXPECT_EQ( | |
1239 test_data.exception, | |
1240 ExcCrashRecoverOriginalException(test_data.code_0, nullptr, &signal)); | |
1241 EXPECT_EQ(test_data.signal, signal); | |
1242 } | |
1243 | |
1244 TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) { | 1188 TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) { |
1245 struct TestData { | 1189 struct TestData { |
1246 exception_behavior_t behavior; | 1190 exception_behavior_t behavior; |
1247 bool set_thread_state; | 1191 bool set_thread_state; |
1248 kern_return_t kr; | 1192 kern_return_t kr; |
1249 }; | 1193 }; |
1250 const TestData kTestData[] = { | 1194 const TestData kTestData[] = { |
1251 {EXCEPTION_DEFAULT, false, KERN_SUCCESS}, | 1195 {EXCEPTION_DEFAULT, false, KERN_SUCCESS}, |
1252 {EXCEPTION_STATE, false, MACH_RCV_PORT_DIED}, | 1196 {EXCEPTION_STATE, false, MACH_RCV_PORT_DIED}, |
1253 {EXCEPTION_STATE_IDENTITY, false, MACH_RCV_PORT_DIED}, | 1197 {EXCEPTION_STATE_IDENTITY, false, MACH_RCV_PORT_DIED}, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 EXPECT_EQ(old_state[i], new_state[i]) << "i " << i; | 1292 EXPECT_EQ(old_state[i], new_state[i]) << "i " << i; |
1349 } | 1293 } |
1350 for (size_t i = arraysize(old_state); i < arraysize(new_state); ++i) { | 1294 for (size_t i = arraysize(old_state); i < arraysize(new_state); ++i) { |
1351 EXPECT_EQ(0u, new_state[i]) << "i " << i; | 1295 EXPECT_EQ(0u, new_state[i]) << "i " << i; |
1352 } | 1296 } |
1353 } | 1297 } |
1354 | 1298 |
1355 } // namespace | 1299 } // namespace |
1356 } // namespace test | 1300 } // namespace test |
1357 } // namespace crashpad | 1301 } // namespace crashpad |
OLD | NEW |