| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 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 18 matching lines...) Expand all Loading... |
| 29 #include "snapshot/win/pe_image_reader.h" | 29 #include "snapshot/win/pe_image_reader.h" |
| 30 #include "snapshot/win/process_reader_win.h" | 30 #include "snapshot/win/process_reader_win.h" |
| 31 #include "test/win/win_multiprocess.h" | 31 #include "test/win/win_multiprocess.h" |
| 32 #include "util/file/file_io.h" | 32 #include "util/file/file_io.h" |
| 33 #include "util/win/process_info.h" | 33 #include "util/win/process_info.h" |
| 34 | 34 |
| 35 namespace crashpad { | 35 namespace crashpad { |
| 36 namespace test { | 36 namespace test { |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 enum TestType { |
| 40 // Don't crash, just test the CrashpadInfo interface. |
| 41 kDontCrash = 0, |
| 42 |
| 43 // The child process should crash by __debugbreak(). |
| 44 kCrashDebugBreak, |
| 45 }; |
| 46 |
| 47 template <TestType Type> |
| 39 class TestPEImageAnnotationsReader final : public WinMultiprocess { | 48 class TestPEImageAnnotationsReader final : public WinMultiprocess { |
| 40 public: | 49 public: |
| 41 enum TestType { | 50 TestPEImageAnnotationsReader() {} |
| 42 // Don't crash, just test the CrashpadInfo interface. | |
| 43 kDontCrash = 0, | |
| 44 | |
| 45 // The child process should crash by __debugbreak(). | |
| 46 kCrashDebugBreak, | |
| 47 }; | |
| 48 | |
| 49 explicit TestPEImageAnnotationsReader(TestType test_type) | |
| 50 : WinMultiprocess(), test_type_(test_type) {} | |
| 51 | |
| 52 ~TestPEImageAnnotationsReader() {} | 51 ~TestPEImageAnnotationsReader() {} |
| 53 | 52 |
| 54 private: | 53 private: |
| 55 // WinMultiprocess: | 54 // WinMultiprocess: |
| 56 | 55 |
| 57 void WinMultiprocessParent() override { | 56 void WinMultiprocessParent() override { |
| 58 ProcessReaderWin process_reader; | 57 ProcessReaderWin process_reader; |
| 59 ASSERT_TRUE(process_reader.Initialize(ChildProcess())); | 58 ASSERT_TRUE(process_reader.Initialize(ChildProcess())); |
| 60 | 59 |
| 61 // Wait for the child process to indicate that it's done setting up its | 60 // Wait for the child process to indicate that it's done setting up its |
| (...skipping 18 matching lines...) Expand all Loading... |
| 80 module_annotations_simple_map.end()); | 79 module_annotations_simple_map.end()); |
| 81 } | 80 } |
| 82 | 81 |
| 83 EXPECT_GE(all_annotations_simple_map.size(), 5u); | 82 EXPECT_GE(all_annotations_simple_map.size(), 5u); |
| 84 EXPECT_EQ("crash", all_annotations_simple_map["#TEST# pad"]); | 83 EXPECT_EQ("crash", all_annotations_simple_map["#TEST# pad"]); |
| 85 EXPECT_EQ("value", all_annotations_simple_map["#TEST# key"]); | 84 EXPECT_EQ("value", all_annotations_simple_map["#TEST# key"]); |
| 86 EXPECT_EQ("y", all_annotations_simple_map["#TEST# x"]); | 85 EXPECT_EQ("y", all_annotations_simple_map["#TEST# x"]); |
| 87 EXPECT_EQ("shorter", all_annotations_simple_map["#TEST# longer"]); | 86 EXPECT_EQ("shorter", all_annotations_simple_map["#TEST# longer"]); |
| 88 EXPECT_EQ("", all_annotations_simple_map["#TEST# empty_value"]); | 87 EXPECT_EQ("", all_annotations_simple_map["#TEST# empty_value"]); |
| 89 | 88 |
| 90 if (test_type_ == kCrashDebugBreak) | 89 if (Type == kCrashDebugBreak) |
| 91 SetExpectedChildExitCode(STATUS_BREAKPOINT); | 90 SetExpectedChildExitCode(STATUS_BREAKPOINT); |
| 92 | 91 |
| 93 // Tell the child process to continue. | 92 // Tell the child process to continue. |
| 94 CheckedWriteFile(WritePipeHandle(), &c, sizeof(c)); | 93 CheckedWriteFile(WritePipeHandle(), &c, sizeof(c)); |
| 95 } | 94 } |
| 96 | 95 |
| 97 void WinMultiprocessChild() override { | 96 void WinMultiprocessChild() override { |
| 98 CrashpadInfo* crashpad_info = CrashpadInfo::GetCrashpadInfo(); | 97 CrashpadInfo* crashpad_info = CrashpadInfo::GetCrashpadInfo(); |
| 99 | 98 |
| 100 // This is "leaked" to crashpad_info. | 99 // This is "leaked" to crashpad_info. |
| 101 SimpleStringDictionary* simple_annotations = new SimpleStringDictionary(); | 100 SimpleStringDictionary* simple_annotations = new SimpleStringDictionary(); |
| 102 simple_annotations->SetKeyValue("#TEST# pad", "break"); | 101 simple_annotations->SetKeyValue("#TEST# pad", "break"); |
| 103 simple_annotations->SetKeyValue("#TEST# key", "value"); | 102 simple_annotations->SetKeyValue("#TEST# key", "value"); |
| 104 simple_annotations->SetKeyValue("#TEST# pad", "crash"); | 103 simple_annotations->SetKeyValue("#TEST# pad", "crash"); |
| 105 simple_annotations->SetKeyValue("#TEST# x", "y"); | 104 simple_annotations->SetKeyValue("#TEST# x", "y"); |
| 106 simple_annotations->SetKeyValue("#TEST# longer", "shorter"); | 105 simple_annotations->SetKeyValue("#TEST# longer", "shorter"); |
| 107 simple_annotations->SetKeyValue("#TEST# empty_value", ""); | 106 simple_annotations->SetKeyValue("#TEST# empty_value", ""); |
| 108 | 107 |
| 109 crashpad_info->set_simple_annotations(simple_annotations); | 108 crashpad_info->set_simple_annotations(simple_annotations); |
| 110 | 109 |
| 111 // Tell the parent that the environment has been set up. | 110 // Tell the parent that the environment has been set up. |
| 112 char c = '\0'; | 111 char c = '\0'; |
| 113 CheckedWriteFile(WritePipeHandle(), &c, sizeof(c)); | 112 CheckedWriteFile(WritePipeHandle(), &c, sizeof(c)); |
| 114 | 113 |
| 115 // Wait for the parent to indicate that it's safe to continue/crash. | 114 // Wait for the parent to indicate that it's safe to continue/crash. |
| 116 CheckedReadFile(ReadPipeHandle(), &c, sizeof(c)); | 115 CheckedReadFile(ReadPipeHandle(), &c, sizeof(c)); |
| 117 | 116 |
| 118 switch (test_type_) { | 117 switch (Type) { |
| 119 case kDontCrash: | 118 case kDontCrash: |
| 120 break; | 119 break; |
| 121 | 120 |
| 122 case kCrashDebugBreak: | 121 case kCrashDebugBreak: |
| 123 __debugbreak(); | 122 __debugbreak(); |
| 124 break; | 123 break; |
| 125 } | 124 } |
| 126 } | 125 } |
| 127 | 126 |
| 128 TestType test_type_; | |
| 129 | |
| 130 DISALLOW_COPY_AND_ASSIGN(TestPEImageAnnotationsReader); | 127 DISALLOW_COPY_AND_ASSIGN(TestPEImageAnnotationsReader); |
| 131 }; | 128 }; |
| 132 | 129 |
| 133 TEST(PEImageAnnotationsReader, DontCrash) { | 130 TEST(PEImageAnnotationsReader, DontCrash) { |
| 134 TestPEImageAnnotationsReader test_pe_image_annotations_reader( | 131 WinMultiprocess::Run<TestPEImageAnnotationsReader<kDontCrash>>(); |
| 135 TestPEImageAnnotationsReader::kDontCrash); | |
| 136 test_pe_image_annotations_reader.Run(); | |
| 137 } | 132 } |
| 138 | 133 |
| 139 TEST(PEImageAnnotationsReader, CrashDebugBreak) { | 134 TEST(PEImageAnnotationsReader, CrashDebugBreak) { |
| 140 TestPEImageAnnotationsReader test_pe_image_annotations_reader( | 135 WinMultiprocess::Run<TestPEImageAnnotationsReader<kCrashDebugBreak>>(); |
| 141 TestPEImageAnnotationsReader::kCrashDebugBreak); | |
| 142 test_pe_image_annotations_reader.Run(); | |
| 143 } | 136 } |
| 144 | 137 |
| 145 } // namespace | 138 } // namespace |
| 146 } // namespace test | 139 } // namespace test |
| 147 } // namespace crashpad | 140 } // namespace crashpad |
| OLD | NEW |