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_module_crashpad_info_writer.h" | 15 #include "minidump/minidump_module_crashpad_info_writer.h" |
16 | 16 |
17 #include <dbghelp.h> | 17 #include <dbghelp.h> |
18 | 18 |
19 #include "gtest/gtest.h" | 19 #include "gtest/gtest.h" |
20 #include "minidump/minidump_extensions.h" | 20 #include "minidump/minidump_extensions.h" |
21 #include "minidump/minidump_simple_string_dictionary_writer.h" | 21 #include "minidump/minidump_simple_string_dictionary_writer.h" |
22 #include "minidump/test/minidump_file_writer_test_util.h" | 22 #include "minidump/test/minidump_file_writer_test_util.h" |
23 #include "minidump/test/minidump_string_writer_test_util.h" | 23 #include "minidump/test/minidump_string_writer_test_util.h" |
24 #include "minidump/test/minidump_writable_test_util.h" | 24 #include "minidump/test/minidump_writable_test_util.h" |
| 25 #include "snapshot/test/test_module_snapshot.h" |
25 #include "util/file/string_file_writer.h" | 26 #include "util/file/string_file_writer.h" |
26 | 27 |
27 namespace crashpad { | 28 namespace crashpad { |
28 namespace test { | 29 namespace test { |
29 namespace { | 30 namespace { |
30 | 31 |
31 const MinidumpModuleCrashpadInfoList* MinidumpModuleCrashpadInfoListAtStart( | 32 const MinidumpModuleCrashpadInfoList* MinidumpModuleCrashpadInfoListAtStart( |
32 const std::string& file_contents, | 33 const std::string& file_contents, |
33 size_t count) { | 34 size_t count) { |
34 MINIDUMP_LOCATION_DESCRIPTOR location_descriptor; | 35 MINIDUMP_LOCATION_DESCRIPTOR location_descriptor; |
(...skipping 19 matching lines...) Expand all Loading... |
54 | 55 |
55 EXPECT_EQ(0u, module_list->count); | 56 EXPECT_EQ(0u, module_list->count); |
56 } | 57 } |
57 | 58 |
58 TEST(MinidumpModuleCrashpadInfoWriter, EmptyModule) { | 59 TEST(MinidumpModuleCrashpadInfoWriter, EmptyModule) { |
59 StringFileWriter file_writer; | 60 StringFileWriter file_writer; |
60 | 61 |
61 MinidumpModuleCrashpadInfoListWriter module_list_writer; | 62 MinidumpModuleCrashpadInfoListWriter module_list_writer; |
62 auto module_writer = | 63 auto module_writer = |
63 make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); | 64 make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); |
| 65 EXPECT_FALSE(module_writer->IsUseful()); |
64 module_list_writer.AddModule(module_writer.Pass()); | 66 module_list_writer.AddModule(module_writer.Pass()); |
65 | 67 |
66 EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer)); | 68 EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer)); |
67 ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList) + | 69 ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList) + |
68 sizeof(MINIDUMP_LOCATION_DESCRIPTOR) + | 70 sizeof(MINIDUMP_LOCATION_DESCRIPTOR) + |
69 sizeof(MinidumpModuleCrashpadInfo), | 71 sizeof(MinidumpModuleCrashpadInfo), |
70 file_writer.string().size()); | 72 file_writer.string().size()); |
71 | 73 |
72 const MinidumpModuleCrashpadInfoList* module_list = | 74 const MinidumpModuleCrashpadInfoList* module_list = |
73 MinidumpModuleCrashpadInfoListAtStart(file_writer.string(), 1); | 75 MinidumpModuleCrashpadInfoListAtStart(file_writer.string(), 1); |
(...skipping 25 matching lines...) Expand all Loading... |
99 make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); | 101 make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); |
100 module_writer->SetMinidumpModuleListIndex(kMinidumpModuleListIndex); | 102 module_writer->SetMinidumpModuleListIndex(kMinidumpModuleListIndex); |
101 auto simple_string_dictionary_writer = | 103 auto simple_string_dictionary_writer = |
102 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); | 104 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); |
103 auto simple_string_dictionary_entry_writer = | 105 auto simple_string_dictionary_entry_writer = |
104 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); | 106 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); |
105 simple_string_dictionary_entry_writer->SetKeyValue(kKey, kValue); | 107 simple_string_dictionary_entry_writer->SetKeyValue(kKey, kValue); |
106 simple_string_dictionary_writer->AddEntry( | 108 simple_string_dictionary_writer->AddEntry( |
107 simple_string_dictionary_entry_writer.Pass()); | 109 simple_string_dictionary_entry_writer.Pass()); |
108 module_writer->SetSimpleAnnotations(simple_string_dictionary_writer.Pass()); | 110 module_writer->SetSimpleAnnotations(simple_string_dictionary_writer.Pass()); |
| 111 EXPECT_TRUE(module_writer->IsUseful()); |
109 module_list_writer.AddModule(module_writer.Pass()); | 112 module_list_writer.AddModule(module_writer.Pass()); |
110 | 113 |
111 EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer)); | 114 EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer)); |
112 ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList) + | 115 ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList) + |
113 sizeof(MINIDUMP_LOCATION_DESCRIPTOR) + | 116 sizeof(MINIDUMP_LOCATION_DESCRIPTOR) + |
114 sizeof(MinidumpModuleCrashpadInfo) + | 117 sizeof(MinidumpModuleCrashpadInfo) + |
115 sizeof(MinidumpSimpleStringDictionary) + | 118 sizeof(MinidumpSimpleStringDictionary) + |
116 sizeof(MinidumpSimpleStringDictionaryEntry) + | 119 sizeof(MinidumpSimpleStringDictionaryEntry) + |
117 sizeof(MinidumpUTF8String) + arraysize(kKey) + | 120 sizeof(MinidumpUTF8String) + arraysize(kKey) + |
118 sizeof(MinidumpUTF8String) + arraysize(kValue), | 121 sizeof(MinidumpUTF8String) + arraysize(kValue), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 module_writer_0->SetMinidumpModuleListIndex(kMinidumpModuleListIndex0); | 171 module_writer_0->SetMinidumpModuleListIndex(kMinidumpModuleListIndex0); |
169 auto simple_string_dictionary_writer_0 = | 172 auto simple_string_dictionary_writer_0 = |
170 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); | 173 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); |
171 auto simple_string_dictionary_entry_writer_0 = | 174 auto simple_string_dictionary_entry_writer_0 = |
172 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); | 175 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); |
173 simple_string_dictionary_entry_writer_0->SetKeyValue(kKey0, kValue0); | 176 simple_string_dictionary_entry_writer_0->SetKeyValue(kKey0, kValue0); |
174 simple_string_dictionary_writer_0->AddEntry( | 177 simple_string_dictionary_writer_0->AddEntry( |
175 simple_string_dictionary_entry_writer_0.Pass()); | 178 simple_string_dictionary_entry_writer_0.Pass()); |
176 module_writer_0->SetSimpleAnnotations( | 179 module_writer_0->SetSimpleAnnotations( |
177 simple_string_dictionary_writer_0.Pass()); | 180 simple_string_dictionary_writer_0.Pass()); |
| 181 EXPECT_TRUE(module_writer_0->IsUseful()); |
178 module_list_writer.AddModule(module_writer_0.Pass()); | 182 module_list_writer.AddModule(module_writer_0.Pass()); |
179 | 183 |
180 auto module_writer_1 = | 184 auto module_writer_1 = |
181 make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); | 185 make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); |
182 module_writer_1->SetMinidumpModuleListIndex(kMinidumpModuleListIndex1); | 186 module_writer_1->SetMinidumpModuleListIndex(kMinidumpModuleListIndex1); |
| 187 EXPECT_FALSE(module_writer_1->IsUseful()); |
183 module_list_writer.AddModule(module_writer_1.Pass()); | 188 module_list_writer.AddModule(module_writer_1.Pass()); |
184 | 189 |
185 auto module_writer_2 = | 190 auto module_writer_2 = |
186 make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); | 191 make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); |
187 module_writer_2->SetMinidumpModuleListIndex(kMinidumpModuleListIndex2); | 192 module_writer_2->SetMinidumpModuleListIndex(kMinidumpModuleListIndex2); |
188 auto simple_string_dictionary_writer_2 = | 193 auto simple_string_dictionary_writer_2 = |
189 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); | 194 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); |
190 auto simple_string_dictionary_entry_writer_2a = | 195 auto simple_string_dictionary_entry_writer_2a = |
191 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); | 196 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); |
192 simple_string_dictionary_entry_writer_2a->SetKeyValue(kKey2A, kValue2A); | 197 simple_string_dictionary_entry_writer_2a->SetKeyValue(kKey2A, kValue2A); |
193 simple_string_dictionary_writer_2->AddEntry( | 198 simple_string_dictionary_writer_2->AddEntry( |
194 simple_string_dictionary_entry_writer_2a.Pass()); | 199 simple_string_dictionary_entry_writer_2a.Pass()); |
195 auto simple_string_dictionary_entry_writer_2b = | 200 auto simple_string_dictionary_entry_writer_2b = |
196 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); | 201 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); |
197 simple_string_dictionary_entry_writer_2b->SetKeyValue(kKey2B, kValue2B); | 202 simple_string_dictionary_entry_writer_2b->SetKeyValue(kKey2B, kValue2B); |
198 simple_string_dictionary_writer_2->AddEntry( | 203 simple_string_dictionary_writer_2->AddEntry( |
199 simple_string_dictionary_entry_writer_2b.Pass()); | 204 simple_string_dictionary_entry_writer_2b.Pass()); |
200 module_writer_2->SetSimpleAnnotations( | 205 module_writer_2->SetSimpleAnnotations( |
201 simple_string_dictionary_writer_2.Pass()); | 206 simple_string_dictionary_writer_2.Pass()); |
| 207 EXPECT_TRUE(module_writer_2->IsUseful()); |
202 module_list_writer.AddModule(module_writer_2.Pass()); | 208 module_list_writer.AddModule(module_writer_2.Pass()); |
203 | 209 |
204 EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer)); | 210 EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer)); |
205 | 211 |
206 const MinidumpModuleCrashpadInfoList* module_list = | 212 const MinidumpModuleCrashpadInfoList* module_list = |
207 MinidumpModuleCrashpadInfoListAtStart(file_writer.string(), 3); | 213 MinidumpModuleCrashpadInfoListAtStart(file_writer.string(), 3); |
208 ASSERT_TRUE(module_list); | 214 ASSERT_TRUE(module_list); |
209 | 215 |
210 ASSERT_EQ(3u, module_list->count); | 216 ASSERT_EQ(3u, module_list->count); |
211 | 217 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 MinidumpUTF8StringAtRVAAsString( | 270 MinidumpUTF8StringAtRVAAsString( |
265 file_writer.string(), simple_annotations_2->entries[0].value)); | 271 file_writer.string(), simple_annotations_2->entries[0].value)); |
266 EXPECT_EQ(kKey2B, | 272 EXPECT_EQ(kKey2B, |
267 MinidumpUTF8StringAtRVAAsString( | 273 MinidumpUTF8StringAtRVAAsString( |
268 file_writer.string(), simple_annotations_2->entries[1].key)); | 274 file_writer.string(), simple_annotations_2->entries[1].key)); |
269 EXPECT_EQ(kValue2B, | 275 EXPECT_EQ(kValue2B, |
270 MinidumpUTF8StringAtRVAAsString( | 276 MinidumpUTF8StringAtRVAAsString( |
271 file_writer.string(), simple_annotations_2->entries[1].value)); | 277 file_writer.string(), simple_annotations_2->entries[1].value)); |
272 } | 278 } |
273 | 279 |
| 280 TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) { |
| 281 const char kKey0A[] = "k"; |
| 282 const char kValue0A[] = "value"; |
| 283 const char kKey0B[] = "hudson"; |
| 284 const char kValue0B[] = "estuary"; |
| 285 const char kKey2[] = "k"; |
| 286 const char kValue2[] = "different_value"; |
| 287 |
| 288 std::vector<const ModuleSnapshot*> module_snapshots; |
| 289 |
| 290 TestModuleSnapshot module_snapshot_0; |
| 291 std::map<std::string, std::string> annotations_simple_map_0; |
| 292 annotations_simple_map_0[kKey0A] = kValue0A; |
| 293 annotations_simple_map_0[kKey0B] = kValue0B; |
| 294 module_snapshot_0.SetAnnotationsSimpleMap(annotations_simple_map_0); |
| 295 module_snapshots.push_back(&module_snapshot_0); |
| 296 |
| 297 // module_snapshot_1 is not expected to be written because it would not carry |
| 298 // any MinidumpModuleCrashpadInfo data. |
| 299 TestModuleSnapshot module_snapshot_1; |
| 300 module_snapshots.push_back(&module_snapshot_1); |
| 301 |
| 302 TestModuleSnapshot module_snapshot_2; |
| 303 std::map<std::string, std::string> annotations_simple_map_2; |
| 304 annotations_simple_map_2[kKey2] = kValue2; |
| 305 module_snapshot_2.SetAnnotationsSimpleMap(annotations_simple_map_2); |
| 306 module_snapshots.push_back(&module_snapshot_2); |
| 307 |
| 308 MinidumpModuleCrashpadInfoListWriter module_list_writer; |
| 309 module_list_writer.InitializeFromSnapshot(module_snapshots); |
| 310 |
| 311 StringFileWriter file_writer; |
| 312 ASSERT_TRUE(module_list_writer.WriteEverything(&file_writer)); |
| 313 |
| 314 const MinidumpModuleCrashpadInfoList* module_list = |
| 315 MinidumpModuleCrashpadInfoListAtStart(file_writer.string(), 2); |
| 316 ASSERT_TRUE(module_list); |
| 317 |
| 318 ASSERT_EQ(2u, module_list->count); |
| 319 |
| 320 const MinidumpModuleCrashpadInfo* module_0 = |
| 321 MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>( |
| 322 file_writer.string(), module_list->modules[0]); |
| 323 ASSERT_TRUE(module_0); |
| 324 |
| 325 EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_0->version); |
| 326 EXPECT_EQ(0u, module_0->minidump_module_list_index); |
| 327 |
| 328 const MinidumpSimpleStringDictionary* simple_annotations_0 = |
| 329 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>( |
| 330 file_writer.string(), module_0->simple_annotations); |
| 331 ASSERT_TRUE(simple_annotations_0); |
| 332 |
| 333 ASSERT_EQ(annotations_simple_map_0.size(), simple_annotations_0->count); |
| 334 EXPECT_EQ(kKey0B, |
| 335 MinidumpUTF8StringAtRVAAsString( |
| 336 file_writer.string(), simple_annotations_0->entries[0].key)); |
| 337 EXPECT_EQ(kValue0B, |
| 338 MinidumpUTF8StringAtRVAAsString( |
| 339 file_writer.string(), simple_annotations_0->entries[0].value)); |
| 340 EXPECT_EQ(kKey0A, |
| 341 MinidumpUTF8StringAtRVAAsString( |
| 342 file_writer.string(), simple_annotations_0->entries[1].key)); |
| 343 EXPECT_EQ(kValue0A, |
| 344 MinidumpUTF8StringAtRVAAsString( |
| 345 file_writer.string(), simple_annotations_0->entries[1].value)); |
| 346 |
| 347 const MinidumpModuleCrashpadInfo* module_2 = |
| 348 MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>( |
| 349 file_writer.string(), module_list->modules[1]); |
| 350 ASSERT_TRUE(module_2); |
| 351 |
| 352 EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_2->version); |
| 353 EXPECT_EQ(2u, module_2->minidump_module_list_index); |
| 354 |
| 355 const MinidumpSimpleStringDictionary* simple_annotations_2 = |
| 356 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>( |
| 357 file_writer.string(), module_2->simple_annotations); |
| 358 ASSERT_TRUE(simple_annotations_2); |
| 359 |
| 360 ASSERT_EQ(annotations_simple_map_2.size(), simple_annotations_2->count); |
| 361 EXPECT_EQ(kKey2, |
| 362 MinidumpUTF8StringAtRVAAsString( |
| 363 file_writer.string(), simple_annotations_2->entries[0].key)); |
| 364 EXPECT_EQ(kValue2, |
| 365 MinidumpUTF8StringAtRVAAsString( |
| 366 file_writer.string(), simple_annotations_2->entries[0].value)); |
| 367 } |
| 368 |
274 } // namespace | 369 } // namespace |
275 } // namespace test | 370 } // namespace test |
276 } // namespace crashpad | 371 } // namespace crashpad |
OLD | NEW |