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

Side by Side Diff: minidump/minidump_memory_writer_test.cc

Issue 643683003: minidump: Use variable names in tests that match parallel array indices (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Rebase 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 unified diff | Download patch
« no previous file with comments | « no previous file | minidump/minidump_module_writer_test.cc » ('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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 &memory_list->MemoryRanges[0], 127 &memory_list->MemoryRanges[0],
128 file_writer.string(), 128 file_writer.string(),
129 kValue, 129 kValue,
130 true); 130 true);
131 } 131 }
132 132
133 TEST(MinidumpMemoryWriter, TwoMemoryRegions) { 133 TEST(MinidumpMemoryWriter, TwoMemoryRegions) {
134 MinidumpFileWriter minidump_file_writer; 134 MinidumpFileWriter minidump_file_writer;
135 MinidumpMemoryListWriter memory_list_writer; 135 MinidumpMemoryListWriter memory_list_writer;
136 136
137 const uint64_t kBaseAddress1 = 0xc0ffee; 137 const uint64_t kBaseAddress0 = 0xc0ffee;
138 const uint64_t kSize1 = 0x0100; 138 const uint64_t kSize0 = 0x0100;
139 const uint8_t kValue1 = '6'; 139 const uint8_t kValue0 = '6';
140 const uint64_t kBaseAddress2 = 0xfac00fac; 140 const uint64_t kBaseAddress1 = 0xfac00fac;
141 const uint64_t kSize2 = 0x0200; 141 const uint64_t kSize1 = 0x0200;
142 const uint8_t kValue2 = '!'; 142 const uint8_t kValue1 = '!';
143 143
144 TestMinidumpMemoryWriter memory_writer_0(kBaseAddress0, kSize0, kValue0);
145 memory_list_writer.AddMemory(&memory_writer_0);
144 TestMinidumpMemoryWriter memory_writer_1(kBaseAddress1, kSize1, kValue1); 146 TestMinidumpMemoryWriter memory_writer_1(kBaseAddress1, kSize1, kValue1);
145 memory_list_writer.AddMemory(&memory_writer_1); 147 memory_list_writer.AddMemory(&memory_writer_1);
146 TestMinidumpMemoryWriter memory_writer_2(kBaseAddress2, kSize2, kValue2);
147 memory_list_writer.AddMemory(&memory_writer_2);
148 148
149 minidump_file_writer.AddStream(&memory_list_writer); 149 minidump_file_writer.AddStream(&memory_list_writer);
150 150
151 StringFileWriter file_writer; 151 StringFileWriter file_writer;
152 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 152 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
153 153
154 const MINIDUMP_MEMORY_LIST* memory_list; 154 const MINIDUMP_MEMORY_LIST* memory_list;
155 ASSERT_NO_FATAL_FAILURE( 155 ASSERT_NO_FATAL_FAILURE(
156 GetMemoryListStream(file_writer.string(), &memory_list, 1)); 156 GetMemoryListStream(file_writer.string(), &memory_list, 1));
157 157
158 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); 158 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
159 159
160 MINIDUMP_MEMORY_DESCRIPTOR expected; 160 MINIDUMP_MEMORY_DESCRIPTOR expected;
161 161
162 { 162 {
163 SCOPED_TRACE("region 0"); 163 SCOPED_TRACE("region 0");
164 164
165 expected.StartOfMemoryRange = kBaseAddress1; 165 expected.StartOfMemoryRange = kBaseAddress0;
166 expected.Memory.DataSize = kSize1; 166 expected.Memory.DataSize = kSize0;
167 expected.Memory.Rva = 167 expected.Memory.Rva =
168 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 168 sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
169 sizeof(MINIDUMP_MEMORY_LIST) + 169 sizeof(MINIDUMP_MEMORY_LIST) +
170 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR); 170 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
171 ExpectMinidumpMemoryDescriptorAndContents(&expected, 171 ExpectMinidumpMemoryDescriptorAndContents(&expected,
172 &memory_list->MemoryRanges[0], 172 &memory_list->MemoryRanges[0],
173 file_writer.string(), 173 file_writer.string(),
174 kValue1, 174 kValue0,
175 false); 175 false);
176 } 176 }
177 177
178 { 178 {
179 SCOPED_TRACE("region 1"); 179 SCOPED_TRACE("region 1");
180 180
181 expected.StartOfMemoryRange = kBaseAddress2; 181 expected.StartOfMemoryRange = kBaseAddress1;
182 expected.Memory.DataSize = kSize2; 182 expected.Memory.DataSize = kSize1;
183 expected.Memory.Rva = memory_list->MemoryRanges[0].Memory.Rva + 183 expected.Memory.Rva = memory_list->MemoryRanges[0].Memory.Rva +
184 memory_list->MemoryRanges[0].Memory.DataSize; 184 memory_list->MemoryRanges[0].Memory.DataSize;
185 ExpectMinidumpMemoryDescriptorAndContents(&expected, 185 ExpectMinidumpMemoryDescriptorAndContents(&expected,
186 &memory_list->MemoryRanges[1], 186 &memory_list->MemoryRanges[1],
187 file_writer.string(), 187 file_writer.string(),
188 kValue2, 188 kValue1,
189 true); 189 true);
190 } 190 }
191 } 191 }
192 192
193 class TestMemoryStream final : public internal::MinidumpStreamWriter { 193 class TestMemoryStream final : public internal::MinidumpStreamWriter {
194 public: 194 public:
195 TestMemoryStream(uint64_t base_address, size_t size, uint8_t value) 195 TestMemoryStream(uint64_t base_address, size_t size, uint8_t value)
196 : MinidumpStreamWriter(), memory_(base_address, size, value) {} 196 : MinidumpStreamWriter(), memory_(base_address, size, value) {}
197 197
198 ~TestMemoryStream() {} 198 ~TestMemoryStream() {}
(...skipping 28 matching lines...) Expand all
227 227
228 DISALLOW_COPY_AND_ASSIGN(TestMemoryStream); 228 DISALLOW_COPY_AND_ASSIGN(TestMemoryStream);
229 }; 229 };
230 230
231 TEST(MinidumpMemoryWriter, ExtraMemory) { 231 TEST(MinidumpMemoryWriter, ExtraMemory) {
232 // This tests MinidumpMemoryListWriter::AddExtraMemory(). That method adds 232 // This tests MinidumpMemoryListWriter::AddExtraMemory(). That method adds
233 // a MinidumpMemoryWriter to the MinidumpMemoryListWriter without making the 233 // a MinidumpMemoryWriter to the MinidumpMemoryListWriter without making the
234 // memory writer a child of the memory list writer. 234 // memory writer a child of the memory list writer.
235 MinidumpFileWriter minidump_file_writer; 235 MinidumpFileWriter minidump_file_writer;
236 236
237 const uint64_t kBaseAddress1 = 0x1000; 237 const uint64_t kBaseAddress0 = 0x1000;
238 const uint64_t kSize1 = 0x0400; 238 const uint64_t kSize0 = 0x0400;
239 const uint8_t kValue1 = '1'; 239 const uint8_t kValue0 = '1';
240 TestMemoryStream test_memory_stream(kBaseAddress1, kSize1, kValue1); 240 TestMemoryStream test_memory_stream(kBaseAddress0, kSize0, kValue0);
241 241
242 MinidumpMemoryListWriter memory_list_writer; 242 MinidumpMemoryListWriter memory_list_writer;
243 memory_list_writer.AddExtraMemory(test_memory_stream.memory()); 243 memory_list_writer.AddExtraMemory(test_memory_stream.memory());
244 244
245 minidump_file_writer.AddStream(&test_memory_stream); 245 minidump_file_writer.AddStream(&test_memory_stream);
246 246
247 const uint64_t kBaseAddress2 = 0x2000; 247 const uint64_t kBaseAddress1 = 0x2000;
248 const uint64_t kSize2 = 0x0400; 248 const uint64_t kSize1 = 0x0400;
249 const uint8_t kValue2 = 'm'; 249 const uint8_t kValue1 = 'm';
250 250
251 TestMinidumpMemoryWriter memory_writer(kBaseAddress2, kSize2, kValue2); 251 TestMinidumpMemoryWriter memory_writer(kBaseAddress1, kSize1, kValue1);
252 memory_list_writer.AddMemory(&memory_writer); 252 memory_list_writer.AddMemory(&memory_writer);
253 253
254 minidump_file_writer.AddStream(&memory_list_writer); 254 minidump_file_writer.AddStream(&memory_list_writer);
255 255
256 StringFileWriter file_writer; 256 StringFileWriter file_writer;
257 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 257 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
258 258
259 const MINIDUMP_MEMORY_LIST* memory_list; 259 const MINIDUMP_MEMORY_LIST* memory_list;
260 ASSERT_NO_FATAL_FAILURE( 260 ASSERT_NO_FATAL_FAILURE(
261 GetMemoryListStream(file_writer.string(), &memory_list, 2)); 261 GetMemoryListStream(file_writer.string(), &memory_list, 2));
262 262
263 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); 263 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
264 264
265 MINIDUMP_MEMORY_DESCRIPTOR expected; 265 MINIDUMP_MEMORY_DESCRIPTOR expected;
266 266
267 { 267 {
268 SCOPED_TRACE("region 0"); 268 SCOPED_TRACE("region 0");
269 269
270 expected.StartOfMemoryRange = kBaseAddress1; 270 expected.StartOfMemoryRange = kBaseAddress0;
271 expected.Memory.DataSize = kSize1; 271 expected.Memory.DataSize = kSize0;
272 expected.Memory.Rva = 272 expected.Memory.Rva =
273 sizeof(MINIDUMP_HEADER) + 2 * sizeof(MINIDUMP_DIRECTORY) + 273 sizeof(MINIDUMP_HEADER) + 2 * sizeof(MINIDUMP_DIRECTORY) +
274 sizeof(MINIDUMP_MEMORY_LIST) + 274 sizeof(MINIDUMP_MEMORY_LIST) +
275 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR); 275 memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
276 ExpectMinidumpMemoryDescriptorAndContents(&expected, 276 ExpectMinidumpMemoryDescriptorAndContents(&expected,
277 &memory_list->MemoryRanges[0], 277 &memory_list->MemoryRanges[0],
278 file_writer.string(), 278 file_writer.string(),
279 kValue1, 279 kValue0,
280 false); 280 false);
281 } 281 }
282 282
283 { 283 {
284 SCOPED_TRACE("region 1"); 284 SCOPED_TRACE("region 1");
285 285
286 expected.StartOfMemoryRange = kBaseAddress2; 286 expected.StartOfMemoryRange = kBaseAddress1;
287 expected.Memory.DataSize = kSize2; 287 expected.Memory.DataSize = kSize1;
288 expected.Memory.Rva = memory_list->MemoryRanges[0].Memory.Rva + 288 expected.Memory.Rva = memory_list->MemoryRanges[0].Memory.Rva +
289 memory_list->MemoryRanges[0].Memory.DataSize; 289 memory_list->MemoryRanges[0].Memory.DataSize;
290 ExpectMinidumpMemoryDescriptorAndContents(&expected, 290 ExpectMinidumpMemoryDescriptorAndContents(&expected,
291 &memory_list->MemoryRanges[1], 291 &memory_list->MemoryRanges[1],
292 file_writer.string(), 292 file_writer.string(),
293 kValue2, 293 kValue1,
294 true); 294 true);
295 } 295 }
296 } 296 }
297 297
298 } // namespace 298 } // namespace
299 } // namespace test 299 } // namespace test
300 } // namespace crashpad 300 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | minidump/minidump_module_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698