Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: minidump/minidump_memory_writer_test.cc

Issue 460933004: Add MinidumpModuleWriter, MinidumpModuleListWriter, related classes, and their test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_memory_writer.h" 15 #include "minidump/minidump_memory_writer.h"
16 16
17 #include <dbghelp.h> 17 #include <dbghelp.h>
18 #include <stdint.h> 18 #include <stdint.h>
19 19
20 #include "base/basictypes.h" 20 #include "base/basictypes.h"
21 #include "gtest/gtest.h" 21 #include "gtest/gtest.h"
22 #include "minidump/minidump_extensions.h"
22 #include "minidump/minidump_file_writer.h" 23 #include "minidump/minidump_file_writer.h"
23 #include "minidump/minidump_stream_writer.h" 24 #include "minidump/minidump_stream_writer.h"
24 #include "minidump/minidump_test_util.h" 25 #include "minidump/minidump_test_util.h"
25 #include "util/file/string_file_writer.h" 26 #include "util/file/string_file_writer.h"
26 27
27 namespace { 28 namespace {
28 29
29 using namespace crashpad; 30 using namespace crashpad;
30 using namespace crashpad::test; 31 using namespace crashpad::test;
31 32
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 242
242 const MINIDUMP_MEMORY_LIST* memory_list; 243 const MINIDUMP_MEMORY_LIST* memory_list;
243 GetMemoryListStream(file_writer.string(), &memory_list, 1); 244 GetMemoryListStream(file_writer.string(), &memory_list, 1);
244 if (Test::HasFatalFailure()) { 245 if (Test::HasFatalFailure()) {
245 return; 246 return;
246 } 247 }
247 248
248 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); 249 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
249 250
250 MINIDUMP_MEMORY_DESCRIPTOR expected; 251 MINIDUMP_MEMORY_DESCRIPTOR expected;
251 expected.StartOfMemoryRange = kBaseAddress1;
252 expected.Memory.DataSize = kSize1;
253 expected.Memory.Rva =
254 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
255 sizeof(MINIDUMP_MEMORY_LIST) +
256 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
257 ExpectMemoryDescriptorAndContents(&expected,
258 &memory_list->MemoryRanges[0],
259 file_writer.string(),
260 kValue1,
261 false);
262 252
263 expected.StartOfMemoryRange = kBaseAddress2; 253 {
264 expected.Memory.DataSize = kSize2; 254 SCOPED_TRACE("region 0");
265 expected.Memory.Rva = memory_list->MemoryRanges[0].Memory.Rva + 255
266 memory_list->MemoryRanges[0].Memory.DataSize; 256 expected.StartOfMemoryRange = kBaseAddress1;
267 ExpectMemoryDescriptorAndContents(&expected, 257 expected.Memory.DataSize = kSize1;
268 &memory_list->MemoryRanges[1], 258 expected.Memory.Rva =
269 file_writer.string(), 259 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
270 kValue2, 260 sizeof(MINIDUMP_MEMORY_LIST) +
271 true); 261 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
262 ExpectMemoryDescriptorAndContents(&expected,
263 &memory_list->MemoryRanges[0],
264 file_writer.string(),
265 kValue1,
266 false);
267 }
268
269 {
270 SCOPED_TRACE("region 1");
271
272 expected.StartOfMemoryRange = kBaseAddress2;
273 expected.Memory.DataSize = kSize2;
274 expected.Memory.Rva = memory_list->MemoryRanges[0].Memory.Rva +
275 memory_list->MemoryRanges[0].Memory.DataSize;
276 ExpectMemoryDescriptorAndContents(&expected,
277 &memory_list->MemoryRanges[1],
278 file_writer.string(),
279 kValue2,
280 true);
281 }
272 } 282 }
273 283
274 class TestMemoryStream final : public internal::MinidumpStreamWriter { 284 class TestMemoryStream final : public internal::MinidumpStreamWriter {
275 public: 285 public:
276 TestMemoryStream(uint64_t base_address, size_t size, uint8_t value) 286 TestMemoryStream(uint64_t base_address, size_t size, uint8_t value)
277 : MinidumpStreamWriter(), memory_(base_address, size, value) {} 287 : MinidumpStreamWriter(), memory_(base_address, size, value) {}
278 288
279 ~TestMemoryStream() {} 289 ~TestMemoryStream() {}
280 290
281 TestMemoryWriter* memory() { return &memory_; } 291 TestMemoryWriter* memory() { return &memory_; }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 349
340 const MINIDUMP_MEMORY_LIST* memory_list; 350 const MINIDUMP_MEMORY_LIST* memory_list;
341 GetMemoryListStream(file_writer.string(), &memory_list, 2); 351 GetMemoryListStream(file_writer.string(), &memory_list, 2);
342 if (Test::HasFatalFailure()) { 352 if (Test::HasFatalFailure()) {
343 return; 353 return;
344 } 354 }
345 355
346 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); 356 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
347 357
348 MINIDUMP_MEMORY_DESCRIPTOR expected; 358 MINIDUMP_MEMORY_DESCRIPTOR expected;
349 expected.StartOfMemoryRange = kBaseAddress1;
350 expected.Memory.DataSize = kSize1;
351 expected.Memory.Rva =
352 sizeof(MINIDUMP_HEADER) + 2 * sizeof(MINIDUMP_DIRECTORY) +
353 sizeof(MINIDUMP_MEMORY_LIST) +
354 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
355 ExpectMemoryDescriptorAndContents(&expected,
356 &memory_list->MemoryRanges[0],
357 file_writer.string(),
358 kValue1,
359 false);
360 359
361 expected.StartOfMemoryRange = kBaseAddress2; 360 {
362 expected.Memory.DataSize = kSize2; 361 SCOPED_TRACE("region 0");
363 expected.Memory.Rva = memory_list->MemoryRanges[0].Memory.Rva + 362
364 memory_list->MemoryRanges[0].Memory.DataSize; 363 expected.StartOfMemoryRange = kBaseAddress1;
365 ExpectMemoryDescriptorAndContents(&expected, 364 expected.Memory.DataSize = kSize1;
366 &memory_list->MemoryRanges[1], 365 expected.Memory.Rva =
367 file_writer.string(), 366 sizeof(MINIDUMP_HEADER) + 2 * sizeof(MINIDUMP_DIRECTORY) +
368 kValue2, 367 sizeof(MINIDUMP_MEMORY_LIST) +
369 true); 368 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
369 ExpectMemoryDescriptorAndContents(&expected,
370 &memory_list->MemoryRanges[0],
371 file_writer.string(),
372 kValue1,
373 false);
374 }
375
376 {
377 SCOPED_TRACE("region 1");
378
379 expected.StartOfMemoryRange = kBaseAddress2;
380 expected.Memory.DataSize = kSize2;
381 expected.Memory.Rva = memory_list->MemoryRanges[0].Memory.Rva +
382 memory_list->MemoryRanges[0].Memory.DataSize;
383 ExpectMemoryDescriptorAndContents(&expected,
384 &memory_list->MemoryRanges[1],
385 file_writer.string(),
386 kValue2,
387 true);
388 }
370 } 389 }
371 390
372 } // namespace 391 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698