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

Unified Diff: minidump/minidump_module_crashpad_info_writer_test.cc

Issue 978463003: minidump: Reorganize MinidumpModuleCrashpadInfo to improve linking between structures (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Minor update Created 5 years, 10 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
Index: minidump/minidump_module_crashpad_info_writer_test.cc
diff --git a/minidump/minidump_module_crashpad_info_writer_test.cc b/minidump/minidump_module_crashpad_info_writer_test.cc
index c256ab30b1990b433f09b3d99880a571f3048ee4..f458b6a6b78021deceea88a44b5dac49e8264b81 100644
--- a/minidump/minidump_module_crashpad_info_writer_test.cc
+++ b/minidump/minidump_module_crashpad_info_writer_test.cc
@@ -21,7 +21,6 @@
#include "minidump/minidump_extensions.h"
#include "minidump/minidump_simple_string_dictionary_writer.h"
#include "minidump/test/minidump_file_writer_test_util.h"
-#include "minidump/test/minidump_location_descriptor_list_test_util.h"
#include "minidump/test/minidump_string_writer_test_util.h"
#include "minidump/test/minidump_writable_test_util.h"
#include "snapshot/test/test_module_snapshot.h"
@@ -31,49 +30,73 @@ namespace crashpad {
namespace test {
namespace {
+const MinidumpModuleCrashpadInfoList* MinidumpModuleCrashpadInfoListAtStart(
+ const std::string& file_contents,
+ size_t count) {
+ MINIDUMP_LOCATION_DESCRIPTOR location_descriptor;
+ location_descriptor.DataSize = sizeof(MinidumpModuleCrashpadInfoList) +
+ count * sizeof(MinidumpModuleCrashpadInfoLink);
+ location_descriptor.Rva = 0;
+
+ const MinidumpModuleCrashpadInfoList* list =
+ MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfoList>(
+ file_contents, location_descriptor);
+ if (!list) {
+ return nullptr;
+ }
+
+ if (list->count != count) {
+ EXPECT_EQ(count, list->count);
+ return nullptr;
+ }
+
+ return list;
+}
+
TEST(MinidumpModuleCrashpadInfoWriter, EmptyList) {
StringFile string_file;
- MinidumpModuleCrashpadInfoListWriter module_list_writer;
- EXPECT_FALSE(module_list_writer.IsUseful());
+ auto module_list_writer =
+ make_scoped_ptr(new MinidumpModuleCrashpadInfoListWriter());
+ EXPECT_FALSE(module_list_writer->IsUseful());
- EXPECT_TRUE(module_list_writer.WriteEverything(&string_file));
+ EXPECT_TRUE(module_list_writer->WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList),
string_file.string().size());
const MinidumpModuleCrashpadInfoList* module_list =
- MinidumpLocationDescriptorListAtStart(string_file.string(), 0);
+ MinidumpModuleCrashpadInfoListAtStart(string_file.string(), 0);
ASSERT_TRUE(module_list);
}
TEST(MinidumpModuleCrashpadInfoWriter, EmptyModule) {
StringFile string_file;
- MinidumpModuleCrashpadInfoListWriter module_list_writer;
- auto module_writer =
- make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter());
+ auto module_list_writer =
+ make_scoped_ptr(new MinidumpModuleCrashpadInfoListWriter());
+ auto module_writer = make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter());
EXPECT_FALSE(module_writer->IsUseful());
- module_list_writer.AddModule(module_writer.Pass());
+ module_list_writer->AddModule(module_writer.Pass(), 0);
- EXPECT_TRUE(module_list_writer.IsUseful());
+ EXPECT_TRUE(module_list_writer->IsUseful());
- EXPECT_TRUE(module_list_writer.WriteEverything(&string_file));
+ EXPECT_TRUE(module_list_writer->WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList) +
- sizeof(MINIDUMP_LOCATION_DESCRIPTOR) +
+ sizeof(MinidumpModuleCrashpadInfoLink) +
sizeof(MinidumpModuleCrashpadInfo),
string_file.string().size());
const MinidumpModuleCrashpadInfoList* module_list =
- MinidumpLocationDescriptorListAtStart(string_file.string(), 1);
+ MinidumpModuleCrashpadInfoListAtStart(string_file.string(), 1);
ASSERT_TRUE(module_list);
+ EXPECT_EQ(0u, module_list->modules[0].minidump_module_list_index);
const MinidumpModuleCrashpadInfo* module =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
- string_file.string(), module_list->children[0]);
+ string_file.string(), module_list->modules[0].location);
ASSERT_TRUE(module);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module->version);
- EXPECT_EQ(0u, module->minidump_module_list_index);
EXPECT_EQ(0u, module->list_annotations.DataSize);
EXPECT_EQ(0u, module->list_annotations.Rva);
EXPECT_EQ(0u, module->simple_annotations.DataSize);
@@ -89,11 +112,10 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
StringFile string_file;
- MinidumpModuleCrashpadInfoListWriter module_list_writer;
+ auto module_list_writer =
+ make_scoped_ptr(new MinidumpModuleCrashpadInfoListWriter());
- auto module_writer =
- make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter());
- module_writer->SetMinidumpModuleListIndex(kMinidumpModuleListIndex);
+ auto module_writer = make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter());
auto string_list_writer = make_scoped_ptr(new MinidumpUTF8StringListWriter());
string_list_writer->InitializeFromVector(vector);
module_writer->SetListAnnotations(string_list_writer.Pass());
@@ -106,13 +128,13 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
simple_string_dictionary_entry_writer.Pass());
module_writer->SetSimpleAnnotations(simple_string_dictionary_writer.Pass());
EXPECT_TRUE(module_writer->IsUseful());
- module_list_writer.AddModule(module_writer.Pass());
+ module_list_writer->AddModule(module_writer.Pass(), kMinidumpModuleListIndex);
- EXPECT_TRUE(module_list_writer.IsUseful());
+ EXPECT_TRUE(module_list_writer->IsUseful());
- EXPECT_TRUE(module_list_writer.WriteEverything(&string_file));
+ EXPECT_TRUE(module_list_writer->WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList) +
- sizeof(MINIDUMP_LOCATION_DESCRIPTOR) +
+ sizeof(MinidumpModuleCrashpadInfoLink) +
sizeof(MinidumpModuleCrashpadInfo) +
sizeof(MinidumpRVAList) +
sizeof(RVA) +
@@ -124,16 +146,17 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
string_file.string().size());
const MinidumpModuleCrashpadInfoList* module_list =
- MinidumpLocationDescriptorListAtStart(string_file.string(), 1);
+ MinidumpModuleCrashpadInfoListAtStart(string_file.string(), 1);
ASSERT_TRUE(module_list);
+ EXPECT_EQ(kMinidumpModuleListIndex,
+ module_list->modules[0].minidump_module_list_index);
const MinidumpModuleCrashpadInfo* module =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
- string_file.string(), module_list->children[0]);
+ string_file.string(), module_list->modules[0].location);
ASSERT_TRUE(module);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module->version);
- EXPECT_EQ(kMinidumpModuleListIndex, module->minidump_module_list_index);
EXPECT_NE(0u, module->list_annotations.DataSize);
EXPECT_NE(0u, module->list_annotations.Rva);
EXPECT_NE(0u, module->simple_annotations.DataSize);
@@ -145,8 +168,9 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
ASSERT_TRUE(list_annotations);
ASSERT_EQ(1u, list_annotations->count);
- EXPECT_EQ(kEntry, MinidumpUTF8StringAtRVAAsString(
- string_file.string(), list_annotations->children[0]));
+ EXPECT_EQ(kEntry,
+ MinidumpUTF8StringAtRVAAsString(string_file.string(),
+ list_annotations->children[0]));
const MinidumpSimpleStringDictionary* simple_annotations =
MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
@@ -175,11 +199,11 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
StringFile string_file;
- MinidumpModuleCrashpadInfoListWriter module_list_writer;
+ auto module_list_writer =
+ make_scoped_ptr(new MinidumpModuleCrashpadInfoListWriter());
auto module_writer_0 =
make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter());
- module_writer_0->SetMinidumpModuleListIndex(kMinidumpModuleListIndex0);
auto simple_string_dictionary_writer_0 =
make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter());
auto simple_string_dictionary_entry_writer_0 =
@@ -190,17 +214,17 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
module_writer_0->SetSimpleAnnotations(
simple_string_dictionary_writer_0.Pass());
EXPECT_TRUE(module_writer_0->IsUseful());
- module_list_writer.AddModule(module_writer_0.Pass());
+ module_list_writer->AddModule(module_writer_0.Pass(),
+ kMinidumpModuleListIndex0);
auto module_writer_1 =
make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter());
- module_writer_1->SetMinidumpModuleListIndex(kMinidumpModuleListIndex1);
EXPECT_FALSE(module_writer_1->IsUseful());
- module_list_writer.AddModule(module_writer_1.Pass());
+ module_list_writer->AddModule(module_writer_1.Pass(),
+ kMinidumpModuleListIndex1);
auto module_writer_2 =
make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter());
- module_writer_2->SetMinidumpModuleListIndex(kMinidumpModuleListIndex2);
auto simple_string_dictionary_writer_2 =
make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter());
auto simple_string_dictionary_entry_writer_2a =
@@ -216,23 +240,25 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
module_writer_2->SetSimpleAnnotations(
simple_string_dictionary_writer_2.Pass());
EXPECT_TRUE(module_writer_2->IsUseful());
- module_list_writer.AddModule(module_writer_2.Pass());
+ module_list_writer->AddModule(module_writer_2.Pass(),
+ kMinidumpModuleListIndex2);
- EXPECT_TRUE(module_list_writer.IsUseful());
+ EXPECT_TRUE(module_list_writer->IsUseful());
- EXPECT_TRUE(module_list_writer.WriteEverything(&string_file));
+ EXPECT_TRUE(module_list_writer->WriteEverything(&string_file));
const MinidumpModuleCrashpadInfoList* module_list =
- MinidumpLocationDescriptorListAtStart(string_file.string(), 3);
+ MinidumpModuleCrashpadInfoListAtStart(string_file.string(), 3);
ASSERT_TRUE(module_list);
+ EXPECT_EQ(kMinidumpModuleListIndex0,
+ module_list->modules[0].minidump_module_list_index);
const MinidumpModuleCrashpadInfo* module_0 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
- string_file.string(), module_list->children[0]);
+ string_file.string(), module_list->modules[0].location);
ASSERT_TRUE(module_0);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_0->version);
- EXPECT_EQ(kMinidumpModuleListIndex0, module_0->minidump_module_list_index);
const MinidumpRVAList* list_annotations_0 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
@@ -252,13 +278,14 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
MinidumpUTF8StringAtRVAAsString(
string_file.string(), simple_annotations_0->entries[0].value));
+ EXPECT_EQ(kMinidumpModuleListIndex1,
+ module_list->modules[1].minidump_module_list_index);
const MinidumpModuleCrashpadInfo* module_1 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
- string_file.string(), module_list->children[1]);
+ string_file.string(), module_list->modules[1].location);
ASSERT_TRUE(module_1);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_1->version);
- EXPECT_EQ(kMinidumpModuleListIndex1, module_1->minidump_module_list_index);
const MinidumpRVAList* list_annotations_1 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
@@ -270,13 +297,14 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
string_file.string(), module_1->simple_annotations);
EXPECT_FALSE(simple_annotations_1);
+ EXPECT_EQ(kMinidumpModuleListIndex2,
+ module_list->modules[2].minidump_module_list_index);
const MinidumpModuleCrashpadInfo* module_2 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
- string_file.string(), module_list->children[2]);
+ string_file.string(), module_list->modules[2].location);
ASSERT_TRUE(module_2);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_2->version);
- EXPECT_EQ(kMinidumpModuleListIndex2, module_2->minidump_module_list_index);
const MinidumpRVAList* list_annotations_2 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
@@ -340,24 +368,25 @@ TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) {
module_snapshot_3.SetAnnotationsVector(annotations_vector_3);
module_snapshots.push_back(&module_snapshot_3);
- MinidumpModuleCrashpadInfoListWriter module_list_writer;
- module_list_writer.InitializeFromSnapshot(module_snapshots);
- EXPECT_TRUE(module_list_writer.IsUseful());
+ auto module_list_writer =
+ make_scoped_ptr(new MinidumpModuleCrashpadInfoListWriter());
+ module_list_writer->InitializeFromSnapshot(module_snapshots);
+ EXPECT_TRUE(module_list_writer->IsUseful());
StringFile string_file;
- ASSERT_TRUE(module_list_writer.WriteEverything(&string_file));
+ ASSERT_TRUE(module_list_writer->WriteEverything(&string_file));
const MinidumpModuleCrashpadInfoList* module_list =
- MinidumpLocationDescriptorListAtStart(string_file.string(), 3);
+ MinidumpModuleCrashpadInfoListAtStart(string_file.string(), 3);
ASSERT_TRUE(module_list);
+ EXPECT_EQ(0u, module_list->modules[0].minidump_module_list_index);
const MinidumpModuleCrashpadInfo* module_0 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
- string_file.string(), module_list->children[0]);
+ string_file.string(), module_list->modules[0].location);
ASSERT_TRUE(module_0);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_0->version);
- EXPECT_EQ(0u, module_0->minidump_module_list_index);
const MinidumpRVAList* list_annotations_0 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
@@ -383,13 +412,13 @@ TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) {
MinidumpUTF8StringAtRVAAsString(
string_file.string(), simple_annotations_0->entries[1].value));
+ EXPECT_EQ(2u, module_list->modules[1].minidump_module_list_index);
const MinidumpModuleCrashpadInfo* module_2 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
- string_file.string(), module_list->children[1]);
+ string_file.string(), module_list->modules[1].location);
ASSERT_TRUE(module_2);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_2->version);
- EXPECT_EQ(2u, module_2->minidump_module_list_index);
const MinidumpRVAList* list_annotations_2 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
@@ -409,13 +438,13 @@ TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) {
MinidumpUTF8StringAtRVAAsString(
string_file.string(), simple_annotations_2->entries[0].value));
+ EXPECT_EQ(3u, module_list->modules[2].minidump_module_list_index);
const MinidumpModuleCrashpadInfo* module_3 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
- string_file.string(), module_list->children[2]);
+ string_file.string(), module_list->modules[2].location);
ASSERT_TRUE(module_3);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_3->version);
- EXPECT_EQ(3u, module_3->minidump_module_list_index);
const MinidumpRVAList* list_annotations_3 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
@@ -424,11 +453,11 @@ TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) {
ASSERT_EQ(annotations_vector_3.size(), list_annotations_3->count);
EXPECT_EQ(kEntry3A,
- MinidumpUTF8StringAtRVAAsString(
- string_file.string(), list_annotations_3->children[0]));
+ MinidumpUTF8StringAtRVAAsString(string_file.string(),
+ list_annotations_3->children[0]));
EXPECT_EQ(kEntry3B,
- MinidumpUTF8StringAtRVAAsString(
- string_file.string(), list_annotations_3->children[1]));
+ MinidumpUTF8StringAtRVAAsString(string_file.string(),
+ list_annotations_3->children[1]));
const MinidumpSimpleStringDictionary* simple_annotations_3 =
MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
« no previous file with comments | « minidump/minidump_module_crashpad_info_writer.cc ('k') | minidump/test/minidump_location_descriptor_list_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698