| 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, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "util/mach/exception_ports.h" | 36 #include "util/mach/exception_ports.h" |
| 37 #include "util/mach/mach_message_server.h" | 37 #include "util/mach/mach_message_server.h" |
| 38 #include "util/test/errors.h" | 38 #include "util/test/errors.h" |
| 39 #include "util/test/mac/mach_errors.h" | 39 #include "util/test/mac/mach_errors.h" |
| 40 #include "util/test/mac/mach_multiprocess.h" | 40 #include "util/test/mac/mach_multiprocess.h" |
| 41 | 41 |
| 42 namespace crashpad { | 42 namespace crashpad { |
| 43 namespace test { | 43 namespace test { |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 class TestMachOImageAnnotationsReader final : public MachMultiprocess, | 46 class TestMachOImageAnnotationsReader final |
| 47 public UniversalMachExcServer { | 47 : public MachMultiprocess, |
| 48 public UniversalMachExcServer::Interface { |
| 48 public: | 49 public: |
| 49 enum TestType { | 50 enum TestType { |
| 50 // Don’t crash, just test the CrashpadInfo interface. | 51 // Don’t crash, just test the CrashpadInfo interface. |
| 51 kDontCrash = 0, | 52 kDontCrash = 0, |
| 52 | 53 |
| 53 // The child process should crash by calling abort(). The parent verifies | 54 // The child process should crash by calling abort(). The parent verifies |
| 54 // that the system libraries set the expected annotations. | 55 // that the system libraries set the expected annotations. |
| 55 kCrashAbort, | 56 kCrashAbort, |
| 56 | 57 |
| 57 // The child process should crash by setting DYLD_INSERT_LIBRARIES to | 58 // The child process should crash by setting DYLD_INSERT_LIBRARIES to |
| 58 // contain a nonexistent library. The parent verifies that dyld sets the | 59 // contain a nonexistent library. The parent verifies that dyld sets the |
| 59 // expected annotations. | 60 // expected annotations. |
| 60 kCrashDyld, | 61 kCrashDyld, |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 explicit TestMachOImageAnnotationsReader(TestType test_type) | 64 explicit TestMachOImageAnnotationsReader(TestType test_type) |
| 64 : MachMultiprocess(), | 65 : MachMultiprocess(), |
| 65 UniversalMachExcServer(), | 66 UniversalMachExcServer::Interface(), |
| 66 test_type_(test_type) { | 67 test_type_(test_type) { |
| 67 } | 68 } |
| 68 | 69 |
| 69 ~TestMachOImageAnnotationsReader() {} | 70 ~TestMachOImageAnnotationsReader() {} |
| 70 | 71 |
| 71 // UniversalMachExcServer: | 72 // UniversalMachExcServer::Interface: |
| 72 kern_return_t CatchMachException(exception_behavior_t behavior, | 73 kern_return_t CatchMachException(exception_behavior_t behavior, |
| 73 exception_handler_t exception_port, | 74 exception_handler_t exception_port, |
| 74 thread_t thread, | 75 thread_t thread, |
| 75 task_t task, | 76 task_t task, |
| 76 exception_type_t exception, | 77 exception_type_t exception, |
| 77 const mach_exception_data_type_t* code, | 78 const mach_exception_data_type_t* code, |
| 78 mach_msg_type_number_t code_count, | 79 mach_msg_type_number_t code_count, |
| 79 thread_state_flavor_t* flavor, | 80 thread_state_flavor_t* flavor, |
| 80 const natural_t* old_state, | 81 const natural_t* old_state, |
| 81 mach_msg_type_number_t old_state_count, | 82 mach_msg_type_number_t old_state_count, |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 EXPECT_EQ("y", all_annotations_simple_map["#TEST# x"]); | 213 EXPECT_EQ("y", all_annotations_simple_map["#TEST# x"]); |
| 213 EXPECT_EQ("shorter", all_annotations_simple_map["#TEST# longer"]); | 214 EXPECT_EQ("shorter", all_annotations_simple_map["#TEST# longer"]); |
| 214 EXPECT_EQ("", all_annotations_simple_map["#TEST# empty_value"]); | 215 EXPECT_EQ("", all_annotations_simple_map["#TEST# empty_value"]); |
| 215 | 216 |
| 216 // Tell the child process that it’s permitted to crash. | 217 // Tell the child process that it’s permitted to crash. |
| 217 CheckedWriteFD(WritePipeFD(), &c, sizeof(c)); | 218 CheckedWriteFD(WritePipeFD(), &c, sizeof(c)); |
| 218 | 219 |
| 219 if (test_type_ != kDontCrash) { | 220 if (test_type_ != kDontCrash) { |
| 220 // Handle the child’s crash. Further validation will be done in | 221 // Handle the child’s crash. Further validation will be done in |
| 221 // CatchMachException(). | 222 // CatchMachException(). |
| 223 UniversalMachExcServer universal_mach_exc_server(this); |
| 224 |
| 222 mach_msg_return_t mr = | 225 mach_msg_return_t mr = |
| 223 MachMessageServer::Run(this, | 226 MachMessageServer::Run(&universal_mach_exc_server, |
| 224 LocalPort(), | 227 LocalPort(), |
| 225 MACH_MSG_OPTION_NONE, | 228 MACH_MSG_OPTION_NONE, |
| 226 MachMessageServer::kOneShot, | 229 MachMessageServer::kOneShot, |
| 227 MachMessageServer::kBlocking, | 230 MachMessageServer::kBlocking, |
| 228 MachMessageServer::kReceiveLargeError, | 231 MachMessageServer::kReceiveLargeError, |
| 229 MACH_MSG_TIMEOUT_NONE); | 232 MACH_MSG_TIMEOUT_NONE); |
| 230 EXPECT_EQ(MACH_MSG_SUCCESS, mr) | 233 EXPECT_EQ(MACH_MSG_SUCCESS, mr) |
| 231 << MachErrorMessage(mr, "MachMessageServer::Run"); | 234 << MachErrorMessage(mr, "MachMessageServer::Run"); |
| 232 | 235 |
| 233 switch (test_type_) { | 236 switch (test_type_) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 330 |
| 328 TEST(MachOImageAnnotationsReader, CrashDyld) { | 331 TEST(MachOImageAnnotationsReader, CrashDyld) { |
| 329 TestMachOImageAnnotationsReader test_mach_o_image_annotations_reader( | 332 TestMachOImageAnnotationsReader test_mach_o_image_annotations_reader( |
| 330 TestMachOImageAnnotationsReader::kCrashDyld); | 333 TestMachOImageAnnotationsReader::kCrashDyld); |
| 331 test_mach_o_image_annotations_reader.Run(); | 334 test_mach_o_image_annotations_reader.Run(); |
| 332 } | 335 } |
| 333 | 336 |
| 334 } // namespace | 337 } // namespace |
| 335 } // namespace test | 338 } // namespace test |
| 336 } // namespace crashpad | 339 } // namespace crashpad |
| OLD | NEW |