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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 82 minidump_file_writer.AddStream(memory_list_writer.Pass()); |
83 | 83 |
84 StringFileWriter file_writer; | 84 StringFileWriter file_writer; |
85 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 85 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
86 | 86 |
87 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 87 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
88 sizeof(MINIDUMP_MEMORY_LIST), | 88 sizeof(MINIDUMP_MEMORY_LIST), |
89 file_writer.string().size()); | 89 file_writer.string().size()); |
90 | 90 |
91 const MINIDUMP_MEMORY_LIST* memory_list; | 91 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
92 ASSERT_NO_FATAL_FAILURE( | 92 ASSERT_NO_FATAL_FAILURE( |
93 GetMemoryListStream(file_writer.string(), &memory_list, 1)); | 93 GetMemoryListStream(file_writer.string(), &memory_list, 1)); |
94 | 94 |
95 EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges); | 95 EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges); |
96 } | 96 } |
97 | 97 |
98 TEST(MinidumpMemoryWriter, OneMemoryRegion) { | 98 TEST(MinidumpMemoryWriter, OneMemoryRegion) { |
99 MinidumpFileWriter minidump_file_writer; | 99 MinidumpFileWriter minidump_file_writer; |
100 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 100 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
101 | 101 |
102 const uint64_t kBaseAddress = 0xfedcba9876543210; | 102 const uint64_t kBaseAddress = 0xfedcba9876543210; |
103 const uint64_t kSize = 0x1000; | 103 const uint64_t kSize = 0x1000; |
104 const uint8_t kValue = 'm'; | 104 const uint8_t kValue = 'm'; |
105 | 105 |
106 auto memory_writer = make_scoped_ptr( | 106 auto memory_writer = make_scoped_ptr( |
107 new TestMinidumpMemoryWriter(kBaseAddress, kSize, kValue)); | 107 new TestMinidumpMemoryWriter(kBaseAddress, kSize, kValue)); |
108 memory_list_writer->AddMemory(memory_writer.Pass()); | 108 memory_list_writer->AddMemory(memory_writer.Pass()); |
109 | 109 |
110 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 110 minidump_file_writer.AddStream(memory_list_writer.Pass()); |
111 | 111 |
112 StringFileWriter file_writer; | 112 StringFileWriter file_writer; |
113 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 113 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
114 | 114 |
115 const MINIDUMP_MEMORY_LIST* memory_list; | 115 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
116 ASSERT_NO_FATAL_FAILURE( | 116 ASSERT_NO_FATAL_FAILURE( |
117 GetMemoryListStream(file_writer.string(), &memory_list, 1)); | 117 GetMemoryListStream(file_writer.string(), &memory_list, 1)); |
118 | 118 |
119 MINIDUMP_MEMORY_DESCRIPTOR expected; | 119 MINIDUMP_MEMORY_DESCRIPTOR expected; |
120 expected.StartOfMemoryRange = kBaseAddress; | 120 expected.StartOfMemoryRange = kBaseAddress; |
121 expected.Memory.DataSize = kSize; | 121 expected.Memory.DataSize = kSize; |
122 expected.Memory.Rva = | 122 expected.Memory.Rva = |
123 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 123 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
124 sizeof(MINIDUMP_MEMORY_LIST) + | 124 sizeof(MINIDUMP_MEMORY_LIST) + |
125 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR); | 125 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR); |
(...skipping 20 matching lines...) Expand all Loading... |
146 memory_list_writer->AddMemory(memory_writer_0.Pass()); | 146 memory_list_writer->AddMemory(memory_writer_0.Pass()); |
147 auto memory_writer_1 = make_scoped_ptr( | 147 auto memory_writer_1 = make_scoped_ptr( |
148 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); | 148 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); |
149 memory_list_writer->AddMemory(memory_writer_1.Pass()); | 149 memory_list_writer->AddMemory(memory_writer_1.Pass()); |
150 | 150 |
151 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 151 minidump_file_writer.AddStream(memory_list_writer.Pass()); |
152 | 152 |
153 StringFileWriter file_writer; | 153 StringFileWriter file_writer; |
154 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 154 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
155 | 155 |
156 const MINIDUMP_MEMORY_LIST* memory_list; | 156 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
157 ASSERT_NO_FATAL_FAILURE( | 157 ASSERT_NO_FATAL_FAILURE( |
158 GetMemoryListStream(file_writer.string(), &memory_list, 1)); | 158 GetMemoryListStream(file_writer.string(), &memory_list, 1)); |
159 | 159 |
160 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); | 160 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); |
161 | 161 |
162 MINIDUMP_MEMORY_DESCRIPTOR expected; | 162 MINIDUMP_MEMORY_DESCRIPTOR expected; |
163 | 163 |
164 { | 164 { |
165 SCOPED_TRACE("region 0"); | 165 SCOPED_TRACE("region 0"); |
166 | 166 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 255 |
256 auto memory_writer = make_scoped_ptr( | 256 auto memory_writer = make_scoped_ptr( |
257 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); | 257 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); |
258 memory_list_writer->AddMemory(memory_writer.Pass()); | 258 memory_list_writer->AddMemory(memory_writer.Pass()); |
259 | 259 |
260 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 260 minidump_file_writer.AddStream(memory_list_writer.Pass()); |
261 | 261 |
262 StringFileWriter file_writer; | 262 StringFileWriter file_writer; |
263 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 263 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
264 | 264 |
265 const MINIDUMP_MEMORY_LIST* memory_list; | 265 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
266 ASSERT_NO_FATAL_FAILURE( | 266 ASSERT_NO_FATAL_FAILURE( |
267 GetMemoryListStream(file_writer.string(), &memory_list, 2)); | 267 GetMemoryListStream(file_writer.string(), &memory_list, 2)); |
268 | 268 |
269 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); | 269 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); |
270 | 270 |
271 MINIDUMP_MEMORY_DESCRIPTOR expected; | 271 MINIDUMP_MEMORY_DESCRIPTOR expected; |
272 | 272 |
273 { | 273 { |
274 SCOPED_TRACE("region 0"); | 274 SCOPED_TRACE("region 0"); |
275 | 275 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 333 |
334 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 334 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
335 memory_list_writer->AddFromSnapshot(memory_snapshots); | 335 memory_list_writer->AddFromSnapshot(memory_snapshots); |
336 | 336 |
337 MinidumpFileWriter minidump_file_writer; | 337 MinidumpFileWriter minidump_file_writer; |
338 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 338 minidump_file_writer.AddStream(memory_list_writer.Pass()); |
339 | 339 |
340 StringFileWriter file_writer; | 340 StringFileWriter file_writer; |
341 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 341 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
342 | 342 |
343 const MINIDUMP_MEMORY_LIST* memory_list; | 343 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
344 ASSERT_NO_FATAL_FAILURE( | 344 ASSERT_NO_FATAL_FAILURE( |
345 GetMemoryListStream(file_writer.string(), &memory_list, 1)); | 345 GetMemoryListStream(file_writer.string(), &memory_list, 1)); |
346 | 346 |
347 ASSERT_EQ(3u, memory_list->NumberOfMemoryRanges); | 347 ASSERT_EQ(3u, memory_list->NumberOfMemoryRanges); |
348 | 348 |
349 for (size_t index = 0; index < memory_list->NumberOfMemoryRanges; ++index) { | 349 for (size_t index = 0; index < memory_list->NumberOfMemoryRanges; ++index) { |
350 SCOPED_TRACE(base::StringPrintf("index %zu", index)); | 350 SCOPED_TRACE(base::StringPrintf("index %zu", index)); |
351 ExpectMinidumpMemoryDescriptorAndContents( | 351 ExpectMinidumpMemoryDescriptorAndContents( |
352 &expect_memory_descriptors[index], | 352 &expect_memory_descriptors[index], |
353 &memory_list->MemoryRanges[index], | 353 &memory_list->MemoryRanges[index], |
354 file_writer.string(), | 354 file_writer.string(), |
355 values[index], | 355 values[index], |
356 index == memory_list->NumberOfMemoryRanges - 1); | 356 index == memory_list->NumberOfMemoryRanges - 1); |
357 } | 357 } |
358 } | 358 } |
359 | 359 |
360 } // namespace | 360 } // namespace |
361 } // namespace test | 361 } // namespace test |
362 } // namespace crashpad | 362 } // namespace crashpad |
OLD | NEW |