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

Side by Side Diff: minidump/minidump_memory_writer_test.cc

Issue 674153002: minidump: Change the ownership model (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 6 years, 1 month 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
« no previous file with comments | « minidump/minidump_memory_writer.cc ('k') | minidump/minidump_misc_info_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 directory[directory_index].StreamType); 66 directory[directory_index].StreamType);
67 EXPECT_EQ(kMemoryListStreamOffset, directory[directory_index].Location.Rva); 67 EXPECT_EQ(kMemoryListStreamOffset, directory[directory_index].Location.Rva);
68 68
69 *memory_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( 69 *memory_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
70 file_contents, directory[directory_index].Location); 70 file_contents, directory[directory_index].Location);
71 ASSERT_TRUE(memory_list); 71 ASSERT_TRUE(memory_list);
72 } 72 }
73 73
74 TEST(MinidumpMemoryWriter, EmptyMemoryList) { 74 TEST(MinidumpMemoryWriter, EmptyMemoryList) {
75 MinidumpFileWriter minidump_file_writer; 75 MinidumpFileWriter minidump_file_writer;
76 MinidumpMemoryListWriter memory_list_writer; 76 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter());
77 77
78 minidump_file_writer.AddStream(&memory_list_writer); 78 minidump_file_writer.AddStream(memory_list_writer.Pass());
79 79
80 StringFileWriter file_writer; 80 StringFileWriter file_writer;
81 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 81 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
82 82
83 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 83 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
84 sizeof(MINIDUMP_MEMORY_LIST), 84 sizeof(MINIDUMP_MEMORY_LIST),
85 file_writer.string().size()); 85 file_writer.string().size());
86 86
87 const MINIDUMP_MEMORY_LIST* memory_list; 87 const MINIDUMP_MEMORY_LIST* memory_list;
88 ASSERT_NO_FATAL_FAILURE( 88 ASSERT_NO_FATAL_FAILURE(
89 GetMemoryListStream(file_writer.string(), &memory_list, 1)); 89 GetMemoryListStream(file_writer.string(), &memory_list, 1));
90 90
91 EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges); 91 EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges);
92 } 92 }
93 93
94 TEST(MinidumpMemoryWriter, OneMemoryRegion) { 94 TEST(MinidumpMemoryWriter, OneMemoryRegion) {
95 MinidumpFileWriter minidump_file_writer; 95 MinidumpFileWriter minidump_file_writer;
96 MinidumpMemoryListWriter memory_list_writer; 96 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter());
97 97
98 const uint64_t kBaseAddress = 0xfedcba9876543210; 98 const uint64_t kBaseAddress = 0xfedcba9876543210;
99 const uint64_t kSize = 0x1000; 99 const uint64_t kSize = 0x1000;
100 const uint8_t kValue = 'm'; 100 const uint8_t kValue = 'm';
101 101
102 TestMinidumpMemoryWriter memory_writer(kBaseAddress, kSize, kValue); 102 auto memory_writer = make_scoped_ptr(
103 memory_list_writer.AddMemory(&memory_writer); 103 new TestMinidumpMemoryWriter(kBaseAddress, kSize, kValue));
104 memory_list_writer->AddMemory(memory_writer.Pass());
104 105
105 minidump_file_writer.AddStream(&memory_list_writer); 106 minidump_file_writer.AddStream(memory_list_writer.Pass());
106 107
107 StringFileWriter file_writer; 108 StringFileWriter file_writer;
108 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 109 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
109 110
110 const MINIDUMP_MEMORY_LIST* memory_list; 111 const MINIDUMP_MEMORY_LIST* memory_list;
111 ASSERT_NO_FATAL_FAILURE( 112 ASSERT_NO_FATAL_FAILURE(
112 GetMemoryListStream(file_writer.string(), &memory_list, 1)); 113 GetMemoryListStream(file_writer.string(), &memory_list, 1));
113 114
114 MINIDUMP_MEMORY_DESCRIPTOR expected; 115 MINIDUMP_MEMORY_DESCRIPTOR expected;
115 expected.StartOfMemoryRange = kBaseAddress; 116 expected.StartOfMemoryRange = kBaseAddress;
116 expected.Memory.DataSize = kSize; 117 expected.Memory.DataSize = kSize;
117 expected.Memory.Rva = 118 expected.Memory.Rva =
118 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 119 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
119 sizeof(MINIDUMP_MEMORY_LIST) + 120 sizeof(MINIDUMP_MEMORY_LIST) +
120 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR); 121 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
121 ExpectMinidumpMemoryDescriptorAndContents(&expected, 122 ExpectMinidumpMemoryDescriptorAndContents(&expected,
122 &memory_list->MemoryRanges[0], 123 &memory_list->MemoryRanges[0],
123 file_writer.string(), 124 file_writer.string(),
124 kValue, 125 kValue,
125 true); 126 true);
126 } 127 }
127 128
128 TEST(MinidumpMemoryWriter, TwoMemoryRegions) { 129 TEST(MinidumpMemoryWriter, TwoMemoryRegions) {
129 MinidumpFileWriter minidump_file_writer; 130 MinidumpFileWriter minidump_file_writer;
130 MinidumpMemoryListWriter memory_list_writer; 131 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter());
131 132
132 const uint64_t kBaseAddress0 = 0xc0ffee; 133 const uint64_t kBaseAddress0 = 0xc0ffee;
133 const uint64_t kSize0 = 0x0100; 134 const uint64_t kSize0 = 0x0100;
134 const uint8_t kValue0 = '6'; 135 const uint8_t kValue0 = '6';
135 const uint64_t kBaseAddress1 = 0xfac00fac; 136 const uint64_t kBaseAddress1 = 0xfac00fac;
136 const uint64_t kSize1 = 0x0200; 137 const uint64_t kSize1 = 0x0200;
137 const uint8_t kValue1 = '!'; 138 const uint8_t kValue1 = '!';
138 139
139 TestMinidumpMemoryWriter memory_writer_0(kBaseAddress0, kSize0, kValue0); 140 auto memory_writer_0 = make_scoped_ptr(
140 memory_list_writer.AddMemory(&memory_writer_0); 141 new TestMinidumpMemoryWriter(kBaseAddress0, kSize0, kValue0));
141 TestMinidumpMemoryWriter memory_writer_1(kBaseAddress1, kSize1, kValue1); 142 memory_list_writer->AddMemory(memory_writer_0.Pass());
142 memory_list_writer.AddMemory(&memory_writer_1); 143 auto memory_writer_1 = make_scoped_ptr(
144 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1));
145 memory_list_writer->AddMemory(memory_writer_1.Pass());
143 146
144 minidump_file_writer.AddStream(&memory_list_writer); 147 minidump_file_writer.AddStream(memory_list_writer.Pass());
145 148
146 StringFileWriter file_writer; 149 StringFileWriter file_writer;
147 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 150 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
148 151
149 const MINIDUMP_MEMORY_LIST* memory_list; 152 const MINIDUMP_MEMORY_LIST* memory_list;
150 ASSERT_NO_FATAL_FAILURE( 153 ASSERT_NO_FATAL_FAILURE(
151 GetMemoryListStream(file_writer.string(), &memory_list, 1)); 154 GetMemoryListStream(file_writer.string(), &memory_list, 1));
152 155
153 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); 156 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
154 157
(...skipping 28 matching lines...) Expand all
183 kValue1, 186 kValue1,
184 true); 187 true);
185 } 188 }
186 } 189 }
187 190
188 class TestMemoryStream final : public internal::MinidumpStreamWriter { 191 class TestMemoryStream final : public internal::MinidumpStreamWriter {
189 public: 192 public:
190 TestMemoryStream(uint64_t base_address, size_t size, uint8_t value) 193 TestMemoryStream(uint64_t base_address, size_t size, uint8_t value)
191 : MinidumpStreamWriter(), memory_(base_address, size, value) {} 194 : MinidumpStreamWriter(), memory_(base_address, size, value) {}
192 195
193 ~TestMemoryStream() {} 196 ~TestMemoryStream() override {}
194 197
195 TestMinidumpMemoryWriter* memory() { return &memory_; } 198 TestMinidumpMemoryWriter* memory() {
199 return &memory_;
200 }
196 201
197 // MinidumpStreamWriter: 202 // MinidumpStreamWriter:
198 MinidumpStreamType StreamType() const override { 203 MinidumpStreamType StreamType() const override {
199 return kBogusStreamType; 204 return kBogusStreamType;
200 } 205 }
201 206
202 protected: 207 protected:
203 // MinidumpWritable: 208 // MinidumpWritable:
204 size_t SizeOfObject() override { 209 size_t SizeOfObject() override {
205 EXPECT_GE(state(), kStateFrozen); 210 EXPECT_GE(state(), kStateFrozen);
(...skipping 19 matching lines...) Expand all
225 230
226 TEST(MinidumpMemoryWriter, ExtraMemory) { 231 TEST(MinidumpMemoryWriter, ExtraMemory) {
227 // This tests MinidumpMemoryListWriter::AddExtraMemory(). That method adds 232 // This tests MinidumpMemoryListWriter::AddExtraMemory(). That method adds
228 // a MinidumpMemoryWriter to the MinidumpMemoryListWriter without making the 233 // a MinidumpMemoryWriter to the MinidumpMemoryListWriter without making the
229 // memory writer a child of the memory list writer. 234 // memory writer a child of the memory list writer.
230 MinidumpFileWriter minidump_file_writer; 235 MinidumpFileWriter minidump_file_writer;
231 236
232 const uint64_t kBaseAddress0 = 0x1000; 237 const uint64_t kBaseAddress0 = 0x1000;
233 const uint64_t kSize0 = 0x0400; 238 const uint64_t kSize0 = 0x0400;
234 const uint8_t kValue0 = '1'; 239 const uint8_t kValue0 = '1';
235 TestMemoryStream test_memory_stream(kBaseAddress0, kSize0, kValue0); 240 auto test_memory_stream =
241 make_scoped_ptr(new TestMemoryStream(kBaseAddress0, kSize0, kValue0));
236 242
237 MinidumpMemoryListWriter memory_list_writer; 243 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter());
238 memory_list_writer.AddExtraMemory(test_memory_stream.memory()); 244 memory_list_writer->AddExtraMemory(test_memory_stream->memory());
239 245
240 minidump_file_writer.AddStream(&test_memory_stream); 246 minidump_file_writer.AddStream(test_memory_stream.Pass());
241 247
242 const uint64_t kBaseAddress1 = 0x2000; 248 const uint64_t kBaseAddress1 = 0x2000;
243 const uint64_t kSize1 = 0x0400; 249 const uint64_t kSize1 = 0x0400;
244 const uint8_t kValue1 = 'm'; 250 const uint8_t kValue1 = 'm';
245 251
246 TestMinidumpMemoryWriter memory_writer(kBaseAddress1, kSize1, kValue1); 252 auto memory_writer = make_scoped_ptr(
247 memory_list_writer.AddMemory(&memory_writer); 253 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1));
254 memory_list_writer->AddMemory(memory_writer.Pass());
248 255
249 minidump_file_writer.AddStream(&memory_list_writer); 256 minidump_file_writer.AddStream(memory_list_writer.Pass());
250 257
251 StringFileWriter file_writer; 258 StringFileWriter file_writer;
252 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 259 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
253 260
254 const MINIDUMP_MEMORY_LIST* memory_list; 261 const MINIDUMP_MEMORY_LIST* memory_list;
255 ASSERT_NO_FATAL_FAILURE( 262 ASSERT_NO_FATAL_FAILURE(
256 GetMemoryListStream(file_writer.string(), &memory_list, 2)); 263 GetMemoryListStream(file_writer.string(), &memory_list, 2));
257 264
258 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); 265 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
259 266
(...skipping 26 matching lines...) Expand all
286 &memory_list->MemoryRanges[1], 293 &memory_list->MemoryRanges[1],
287 file_writer.string(), 294 file_writer.string(),
288 kValue1, 295 kValue1,
289 true); 296 true);
290 } 297 }
291 } 298 }
292 299
293 } // namespace 300 } // namespace
294 } // namespace test 301 } // namespace test
295 } // namespace crashpad 302 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_memory_writer.cc ('k') | minidump/minidump_misc_info_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698