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

Unified Diff: minidump/minidump_memory_writer_test.cc

Issue 641603006: Add MinidumpMemoryListWriter::AddFromSnapshot(), everything downstream and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Correctly look for the last memory range at EOF Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « minidump/minidump_memory_writer.cc ('k') | minidump/minidump_module_crashpad_info_writer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: minidump/minidump_memory_writer_test.cc
diff --git a/minidump/minidump_memory_writer_test.cc b/minidump/minidump_memory_writer_test.cc
index af7018b21c9074e60ecc3a89583db0c570483ec4..f29a185266ec19c0b0d5ffc389c9c86969ed31e6 100644
--- a/minidump/minidump_memory_writer_test.cc
+++ b/minidump/minidump_memory_writer_test.cc
@@ -18,6 +18,7 @@
#include <stdint.h>
#include "base/basictypes.h"
+#include "base/strings/stringprintf.h"
#include "gtest/gtest.h"
#include "minidump/minidump_extensions.h"
#include "minidump/minidump_file_writer.h"
@@ -25,7 +26,9 @@
#include "minidump/test/minidump_file_writer_test_util.h"
#include "minidump/test/minidump_memory_writer_test_util.h"
#include "minidump/test/minidump_writable_test_util.h"
+#include "snapshot/test/test_memory_snapshot.h"
#include "util/file/string_file_writer.h"
+#include "util/stdlib/pointer_container.h"
namespace crashpad {
namespace test {
@@ -235,7 +238,7 @@ TEST(MinidumpMemoryWriter, ExtraMemory) {
MinidumpFileWriter minidump_file_writer;
const uint64_t kBaseAddress0 = 0x1000;
- const uint64_t kSize0 = 0x0400;
+ const size_t kSize0 = 0x0400;
const uint8_t kValue0 = '1';
auto test_memory_stream =
make_scoped_ptr(new TestMemoryStream(kBaseAddress0, kSize0, kValue0));
@@ -246,7 +249,7 @@ TEST(MinidumpMemoryWriter, ExtraMemory) {
minidump_file_writer.AddStream(test_memory_stream.Pass());
const uint64_t kBaseAddress1 = 0x2000;
- const uint64_t kSize1 = 0x0400;
+ const size_t kSize1 = 0x0400;
const uint8_t kValue1 = 'm';
auto memory_writer = make_scoped_ptr(
@@ -297,6 +300,62 @@ TEST(MinidumpMemoryWriter, ExtraMemory) {
}
}
+TEST(MinidumpMemoryWriter, AddFromSnapshot) {
+ MINIDUMP_MEMORY_DESCRIPTOR expect_memory_descriptors[3] = {};
+ uint8_t values[arraysize(expect_memory_descriptors)] = {};
+
+ expect_memory_descriptors[0].StartOfMemoryRange = 0;
+ expect_memory_descriptors[0].Memory.DataSize = 0x1000;
+ values[0] = 0x01;
+
+ expect_memory_descriptors[1].StartOfMemoryRange = 0x1000;
+ expect_memory_descriptors[1].Memory.DataSize = 0x2000;
+ values[1] = 0xf4;
+
+ expect_memory_descriptors[2].StartOfMemoryRange = 0x7654321000000000;
+ expect_memory_descriptors[2].Memory.DataSize = 0x800;
+ values[2] = 0xa9;
+
+ PointerVector<TestMemorySnapshot> memory_snapshots_owner;
+ std::vector<const MemorySnapshot*> memory_snapshots;
+ for (size_t index = 0;
+ index < arraysize(expect_memory_descriptors);
+ ++index) {
+ TestMemorySnapshot* memory_snapshot = new TestMemorySnapshot();
+ memory_snapshots_owner.push_back(memory_snapshot);
+ memory_snapshot->SetAddress(
+ expect_memory_descriptors[index].StartOfMemoryRange);
+ memory_snapshot->SetSize(expect_memory_descriptors[index].Memory.DataSize);
+ memory_snapshot->SetValue(values[index]);
+ memory_snapshots.push_back(memory_snapshot);
+ }
+
+ auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter());
+ memory_list_writer->AddFromSnapshot(memory_snapshots);
+
+ MinidumpFileWriter minidump_file_writer;
+ minidump_file_writer.AddStream(memory_list_writer.Pass());
+
+ StringFileWriter file_writer;
+ ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
+
+ const MINIDUMP_MEMORY_LIST* memory_list;
+ ASSERT_NO_FATAL_FAILURE(
+ GetMemoryListStream(file_writer.string(), &memory_list, 1));
+
+ ASSERT_EQ(3u, memory_list->NumberOfMemoryRanges);
+
+ for (size_t index = 0; index < memory_list->NumberOfMemoryRanges; ++index) {
+ SCOPED_TRACE(base::StringPrintf("index %zu", index));
+ ExpectMinidumpMemoryDescriptorAndContents(
+ &expect_memory_descriptors[index],
+ &memory_list->MemoryRanges[index],
+ file_writer.string(),
+ values[index],
+ index == memory_list->NumberOfMemoryRanges - 1);
+ }
+}
+
} // namespace
} // namespace test
} // namespace crashpad
« no previous file with comments | « minidump/minidump_memory_writer.cc ('k') | minidump/minidump_module_crashpad_info_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698