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 "minidump/minidump_crashpad_info_writer.h" | 15 #include "minidump/minidump_crashpad_info_writer.h" |
16 | 16 |
17 #include <windows.h> | 17 #include <windows.h> |
18 #include <dbghelp.h> | 18 #include <dbghelp.h> |
19 | 19 |
20 #include <map> | 20 #include <map> |
21 #include <string> | 21 #include <string> |
| 22 #include <utility> |
22 | 23 |
23 #include "gtest/gtest.h" | 24 #include "gtest/gtest.h" |
24 #include "minidump/minidump_extensions.h" | 25 #include "minidump/minidump_extensions.h" |
25 #include "minidump/minidump_file_writer.h" | 26 #include "minidump/minidump_file_writer.h" |
26 #include "minidump/minidump_module_crashpad_info_writer.h" | 27 #include "minidump/minidump_module_crashpad_info_writer.h" |
27 #include "minidump/minidump_simple_string_dictionary_writer.h" | 28 #include "minidump/minidump_simple_string_dictionary_writer.h" |
28 #include "minidump/test/minidump_file_writer_test_util.h" | 29 #include "minidump/test/minidump_file_writer_test_util.h" |
29 #include "minidump/test/minidump_string_writer_test_util.h" | 30 #include "minidump/test/minidump_string_writer_test_util.h" |
30 #include "minidump/test/minidump_writable_test_util.h" | 31 #include "minidump/test/minidump_writable_test_util.h" |
31 #include "snapshot/test/test_module_snapshot.h" | 32 #include "snapshot/test/test_module_snapshot.h" |
32 #include "snapshot/test/test_process_snapshot.h" | 33 #include "snapshot/test/test_process_snapshot.h" |
33 #include "util/file/string_file.h" | 34 #include "util/file/string_file.h" |
34 #include "util/stdlib/move.h" | |
35 | 35 |
36 namespace crashpad { | 36 namespace crashpad { |
37 namespace test { | 37 namespace test { |
38 namespace { | 38 namespace { |
39 | 39 |
40 void GetCrashpadInfoStream( | 40 void GetCrashpadInfoStream( |
41 const std::string& file_contents, | 41 const std::string& file_contents, |
42 const MinidumpCrashpadInfo** crashpad_info, | 42 const MinidumpCrashpadInfo** crashpad_info, |
43 const MinidumpSimpleStringDictionary** simple_annotations, | 43 const MinidumpSimpleStringDictionary** simple_annotations, |
44 const MinidumpModuleCrashpadInfoList** module_list) { | 44 const MinidumpModuleCrashpadInfoList** module_list) { |
(...skipping 16 matching lines...) Expand all Loading... |
61 *module_list = | 61 *module_list = |
62 MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfoList>( | 62 MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfoList>( |
63 file_contents, (*crashpad_info)->module_list); | 63 file_contents, (*crashpad_info)->module_list); |
64 } | 64 } |
65 | 65 |
66 TEST(MinidumpCrashpadInfoWriter, Empty) { | 66 TEST(MinidumpCrashpadInfoWriter, Empty) { |
67 MinidumpFileWriter minidump_file_writer; | 67 MinidumpFileWriter minidump_file_writer; |
68 auto crashpad_info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); | 68 auto crashpad_info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); |
69 EXPECT_FALSE(crashpad_info_writer->IsUseful()); | 69 EXPECT_FALSE(crashpad_info_writer->IsUseful()); |
70 | 70 |
71 minidump_file_writer.AddStream(crashpad::move(crashpad_info_writer)); | 71 minidump_file_writer.AddStream(std::move(crashpad_info_writer)); |
72 | 72 |
73 StringFile string_file; | 73 StringFile string_file; |
74 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 74 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
75 | 75 |
76 const MinidumpCrashpadInfo* crashpad_info = nullptr; | 76 const MinidumpCrashpadInfo* crashpad_info = nullptr; |
77 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; | 77 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; |
78 const MinidumpModuleCrashpadInfoList* module_list = nullptr; | 78 const MinidumpModuleCrashpadInfoList* module_list = nullptr; |
79 | 79 |
80 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( | 80 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( |
81 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); | 81 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); |
(...skipping 14 matching lines...) Expand all Loading... |
96 report_id.InitializeFromString("01234567-89ab-cdef-0123-456789abcdef")); | 96 report_id.InitializeFromString("01234567-89ab-cdef-0123-456789abcdef")); |
97 crashpad_info_writer->SetReportID(report_id); | 97 crashpad_info_writer->SetReportID(report_id); |
98 | 98 |
99 UUID client_id; | 99 UUID client_id; |
100 ASSERT_TRUE( | 100 ASSERT_TRUE( |
101 client_id.InitializeFromString("00112233-4455-6677-8899-aabbccddeeff")); | 101 client_id.InitializeFromString("00112233-4455-6677-8899-aabbccddeeff")); |
102 crashpad_info_writer->SetClientID(client_id); | 102 crashpad_info_writer->SetClientID(client_id); |
103 | 103 |
104 EXPECT_TRUE(crashpad_info_writer->IsUseful()); | 104 EXPECT_TRUE(crashpad_info_writer->IsUseful()); |
105 | 105 |
106 minidump_file_writer.AddStream(crashpad::move(crashpad_info_writer)); | 106 minidump_file_writer.AddStream(std::move(crashpad_info_writer)); |
107 | 107 |
108 StringFile string_file; | 108 StringFile string_file; |
109 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 109 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
110 | 110 |
111 const MinidumpCrashpadInfo* crashpad_info = nullptr; | 111 const MinidumpCrashpadInfo* crashpad_info = nullptr; |
112 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; | 112 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; |
113 const MinidumpModuleCrashpadInfoList* module_list = nullptr; | 113 const MinidumpModuleCrashpadInfoList* module_list = nullptr; |
114 | 114 |
115 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( | 115 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( |
116 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); | 116 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); |
(...skipping 14 matching lines...) Expand all Loading... |
131 "something"; | 131 "something"; |
132 const char kValue[] = | 132 const char kValue[] = |
133 "the numerical amount denoted by an algebraic term; a magnitude, " | 133 "the numerical amount denoted by an algebraic term; a magnitude, " |
134 "quantity, or number"; | 134 "quantity, or number"; |
135 auto simple_string_dictionary_writer = | 135 auto simple_string_dictionary_writer = |
136 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); | 136 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); |
137 auto simple_string_dictionary_entry_writer = | 137 auto simple_string_dictionary_entry_writer = |
138 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); | 138 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); |
139 simple_string_dictionary_entry_writer->SetKeyValue(kKey, kValue); | 139 simple_string_dictionary_entry_writer->SetKeyValue(kKey, kValue); |
140 simple_string_dictionary_writer->AddEntry( | 140 simple_string_dictionary_writer->AddEntry( |
141 crashpad::move(simple_string_dictionary_entry_writer)); | 141 std::move(simple_string_dictionary_entry_writer)); |
142 crashpad_info_writer->SetSimpleAnnotations( | 142 crashpad_info_writer->SetSimpleAnnotations( |
143 crashpad::move(simple_string_dictionary_writer)); | 143 std::move(simple_string_dictionary_writer)); |
144 | 144 |
145 EXPECT_TRUE(crashpad_info_writer->IsUseful()); | 145 EXPECT_TRUE(crashpad_info_writer->IsUseful()); |
146 | 146 |
147 minidump_file_writer.AddStream(crashpad::move(crashpad_info_writer)); | 147 minidump_file_writer.AddStream(std::move(crashpad_info_writer)); |
148 | 148 |
149 StringFile string_file; | 149 StringFile string_file; |
150 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 150 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
151 | 151 |
152 const MinidumpCrashpadInfo* crashpad_info = nullptr; | 152 const MinidumpCrashpadInfo* crashpad_info = nullptr; |
153 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; | 153 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; |
154 const MinidumpModuleCrashpadInfoList* module_list = nullptr; | 154 const MinidumpModuleCrashpadInfoList* module_list = nullptr; |
155 | 155 |
156 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( | 156 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( |
157 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); | 157 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); |
(...skipping 13 matching lines...) Expand all Loading... |
171 | 171 |
172 TEST(MinidumpCrashpadInfoWriter, CrashpadModuleList) { | 172 TEST(MinidumpCrashpadInfoWriter, CrashpadModuleList) { |
173 const uint32_t kMinidumpModuleListIndex = 3; | 173 const uint32_t kMinidumpModuleListIndex = 3; |
174 | 174 |
175 MinidumpFileWriter minidump_file_writer; | 175 MinidumpFileWriter minidump_file_writer; |
176 auto crashpad_info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); | 176 auto crashpad_info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); |
177 | 177 |
178 auto module_list_writer = | 178 auto module_list_writer = |
179 make_scoped_ptr(new MinidumpModuleCrashpadInfoListWriter()); | 179 make_scoped_ptr(new MinidumpModuleCrashpadInfoListWriter()); |
180 auto module_writer = make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); | 180 auto module_writer = make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); |
181 module_list_writer->AddModule(crashpad::move(module_writer), kMinidumpModuleLi
stIndex); | 181 module_list_writer->AddModule(std::move(module_writer), |
182 crashpad_info_writer->SetModuleList(crashpad::move(module_list_writer)); | 182 kMinidumpModuleListIndex); |
| 183 crashpad_info_writer->SetModuleList(std::move(module_list_writer)); |
183 | 184 |
184 EXPECT_TRUE(crashpad_info_writer->IsUseful()); | 185 EXPECT_TRUE(crashpad_info_writer->IsUseful()); |
185 | 186 |
186 minidump_file_writer.AddStream(crashpad::move(crashpad_info_writer)); | 187 minidump_file_writer.AddStream(std::move(crashpad_info_writer)); |
187 | 188 |
188 StringFile string_file; | 189 StringFile string_file; |
189 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 190 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
190 | 191 |
191 const MinidumpCrashpadInfo* crashpad_info = nullptr; | 192 const MinidumpCrashpadInfo* crashpad_info = nullptr; |
192 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; | 193 const MinidumpSimpleStringDictionary* simple_annotations = nullptr; |
193 const MinidumpModuleCrashpadInfoList* module_list = nullptr; | 194 const MinidumpModuleCrashpadInfoList* module_list = nullptr; |
194 | 195 |
195 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( | 196 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( |
196 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); | 197 string_file.string(), &crashpad_info, &simple_annotations, &module_list)); |
(...skipping 29 matching lines...) Expand all Loading... |
226 | 227 |
227 const char kKey[] = "version"; | 228 const char kKey[] = "version"; |
228 const char kValue[] = "40.0.2214.111"; | 229 const char kValue[] = "40.0.2214.111"; |
229 const char kEntry[] = "This is a simple annotation in a list."; | 230 const char kEntry[] = "This is a simple annotation in a list."; |
230 | 231 |
231 // Test with a useless module, one that doesn’t carry anything that would | 232 // Test with a useless module, one that doesn’t carry anything that would |
232 // require MinidumpCrashpadInfo or any child object. | 233 // require MinidumpCrashpadInfo or any child object. |
233 auto process_snapshot = make_scoped_ptr(new TestProcessSnapshot()); | 234 auto process_snapshot = make_scoped_ptr(new TestProcessSnapshot()); |
234 | 235 |
235 auto module_snapshot = make_scoped_ptr(new TestModuleSnapshot()); | 236 auto module_snapshot = make_scoped_ptr(new TestModuleSnapshot()); |
236 process_snapshot->AddModule(crashpad::move(module_snapshot)); | 237 process_snapshot->AddModule(std::move(module_snapshot)); |
237 | 238 |
238 auto info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); | 239 auto info_writer = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); |
239 info_writer->InitializeFromSnapshot(process_snapshot.get()); | 240 info_writer->InitializeFromSnapshot(process_snapshot.get()); |
240 EXPECT_FALSE(info_writer->IsUseful()); | 241 EXPECT_FALSE(info_writer->IsUseful()); |
241 | 242 |
242 // Try again with a useful module. | 243 // Try again with a useful module. |
243 process_snapshot.reset(new TestProcessSnapshot()); | 244 process_snapshot.reset(new TestProcessSnapshot()); |
244 | 245 |
245 process_snapshot->SetReportID(report_id); | 246 process_snapshot->SetReportID(report_id); |
246 process_snapshot->SetClientID(client_id); | 247 process_snapshot->SetClientID(client_id); |
247 | 248 |
248 std::map<std::string, std::string> annotations_simple_map; | 249 std::map<std::string, std::string> annotations_simple_map; |
249 annotations_simple_map[kKey] = kValue; | 250 annotations_simple_map[kKey] = kValue; |
250 process_snapshot->SetAnnotationsSimpleMap(annotations_simple_map); | 251 process_snapshot->SetAnnotationsSimpleMap(annotations_simple_map); |
251 | 252 |
252 module_snapshot.reset(new TestModuleSnapshot()); | 253 module_snapshot.reset(new TestModuleSnapshot()); |
253 std::vector<std::string> annotations_list(1, std::string(kEntry)); | 254 std::vector<std::string> annotations_list(1, std::string(kEntry)); |
254 module_snapshot->SetAnnotationsVector(annotations_list); | 255 module_snapshot->SetAnnotationsVector(annotations_list); |
255 process_snapshot->AddModule(crashpad::move(module_snapshot)); | 256 process_snapshot->AddModule(std::move(module_snapshot)); |
256 | 257 |
257 info_writer.reset(new MinidumpCrashpadInfoWriter()); | 258 info_writer.reset(new MinidumpCrashpadInfoWriter()); |
258 info_writer->InitializeFromSnapshot(process_snapshot.get()); | 259 info_writer->InitializeFromSnapshot(process_snapshot.get()); |
259 EXPECT_TRUE(info_writer->IsUseful()); | 260 EXPECT_TRUE(info_writer->IsUseful()); |
260 | 261 |
261 MinidumpFileWriter minidump_file_writer; | 262 MinidumpFileWriter minidump_file_writer; |
262 minidump_file_writer.AddStream(crashpad::move(info_writer)); | 263 minidump_file_writer.AddStream(std::move(info_writer)); |
263 | 264 |
264 StringFile string_file; | 265 StringFile string_file; |
265 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 266 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
266 | 267 |
267 const MinidumpCrashpadInfo* info = nullptr; | 268 const MinidumpCrashpadInfo* info = nullptr; |
268 const MinidumpSimpleStringDictionary* simple_annotations; | 269 const MinidumpSimpleStringDictionary* simple_annotations; |
269 const MinidumpModuleCrashpadInfoList* module_list; | 270 const MinidumpModuleCrashpadInfoList* module_list; |
270 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( | 271 ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( |
271 string_file.string(), &info, &simple_annotations, &module_list)); | 272 string_file.string(), &info, &simple_annotations, &module_list)); |
272 | 273 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 308 |
308 const MinidumpSimpleStringDictionary* module_simple_annotations = | 309 const MinidumpSimpleStringDictionary* module_simple_annotations = |
309 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>( | 310 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>( |
310 string_file.string(), module->simple_annotations); | 311 string_file.string(), module->simple_annotations); |
311 EXPECT_FALSE(module_simple_annotations); | 312 EXPECT_FALSE(module_simple_annotations); |
312 } | 313 } |
313 | 314 |
314 } // namespace | 315 } // namespace |
315 } // namespace test | 316 } // namespace test |
316 } // namespace crashpad | 317 } // namespace crashpad |
OLD | NEW |