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

Side by Side Diff: third_party/crashpad/crashpad/minidump/minidump_memory_writer_test.cc

Issue 2773813002: Update Crashpad to 8e37886d418dd042c3c7bfadac99214739ee4d98 (Closed)
Patch Set: Update Crashpad to 8e37886d418dd042c3c7bfadac99214739ee4d98 Created 3 years, 9 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,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 *memory_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( 73 *memory_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
74 file_contents, directory[directory_index].Location); 74 file_contents, directory[directory_index].Location);
75 ASSERT_TRUE(memory_list); 75 ASSERT_TRUE(memory_list);
76 } 76 }
77 77
78 TEST(MinidumpMemoryWriter, EmptyMemoryList) { 78 TEST(MinidumpMemoryWriter, EmptyMemoryList) {
79 MinidumpFileWriter minidump_file_writer; 79 MinidumpFileWriter minidump_file_writer;
80 auto memory_list_writer = base::WrapUnique(new MinidumpMemoryListWriter()); 80 auto memory_list_writer = base::WrapUnique(new MinidumpMemoryListWriter());
81 81
82 minidump_file_writer.AddStream(std::move(memory_list_writer)); 82 ASSERT_TRUE(minidump_file_writer.AddStream(std::move(memory_list_writer)));
83 83
84 StringFile string_file; 84 StringFile string_file;
85 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 85 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
86 86
87 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 87 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
88 sizeof(MINIDUMP_MEMORY_LIST), 88 sizeof(MINIDUMP_MEMORY_LIST),
89 string_file.string().size()); 89 string_file.string().size());
90 90
91 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; 91 const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
92 ASSERT_NO_FATAL_FAILURE( 92 ASSERT_NO_FATAL_FAILURE(
93 GetMemoryListStream(string_file.string(), &memory_list, 1)); 93 GetMemoryListStream(string_file.string(), &memory_list, 1));
94 94
95 EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges); 95 EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges);
96 } 96 }
97 97
98 TEST(MinidumpMemoryWriter, OneMemoryRegion) { 98 TEST(MinidumpMemoryWriter, OneMemoryRegion) {
99 MinidumpFileWriter minidump_file_writer; 99 MinidumpFileWriter minidump_file_writer;
100 auto memory_list_writer = base::WrapUnique(new MinidumpMemoryListWriter()); 100 auto memory_list_writer = base::WrapUnique(new MinidumpMemoryListWriter());
101 101
102 const uint64_t kBaseAddress = 0xfedcba9876543210; 102 const uint64_t kBaseAddress = 0xfedcba9876543210;
103 const uint64_t kSize = 0x1000; 103 const uint64_t kSize = 0x1000;
104 const uint8_t kValue = 'm'; 104 const uint8_t kValue = 'm';
105 105
106 auto memory_writer = base::WrapUnique( 106 auto memory_writer = base::WrapUnique(
107 new TestMinidumpMemoryWriter(kBaseAddress, kSize, kValue)); 107 new TestMinidumpMemoryWriter(kBaseAddress, kSize, kValue));
108 memory_list_writer->AddMemory(std::move(memory_writer)); 108 memory_list_writer->AddMemory(std::move(memory_writer));
109 109
110 minidump_file_writer.AddStream(std::move(memory_list_writer)); 110 ASSERT_TRUE(minidump_file_writer.AddStream(std::move(memory_list_writer)));
111 111
112 StringFile string_file; 112 StringFile string_file;
113 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 113 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
114 114
115 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; 115 const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
116 ASSERT_NO_FATAL_FAILURE( 116 ASSERT_NO_FATAL_FAILURE(
117 GetMemoryListStream(string_file.string(), &memory_list, 1)); 117 GetMemoryListStream(string_file.string(), &memory_list, 1));
118 118
119 MINIDUMP_MEMORY_DESCRIPTOR expected; 119 MINIDUMP_MEMORY_DESCRIPTOR expected;
120 expected.StartOfMemoryRange = kBaseAddress; 120 expected.StartOfMemoryRange = kBaseAddress;
(...skipping 20 matching lines...) Expand all
141 const uint64_t kSize1 = 0x0200; 141 const uint64_t kSize1 = 0x0200;
142 const uint8_t kValue1 = '!'; 142 const uint8_t kValue1 = '!';
143 143
144 auto memory_writer_0 = base::WrapUnique( 144 auto memory_writer_0 = base::WrapUnique(
145 new TestMinidumpMemoryWriter(kBaseAddress0, kSize0, kValue0)); 145 new TestMinidumpMemoryWriter(kBaseAddress0, kSize0, kValue0));
146 memory_list_writer->AddMemory(std::move(memory_writer_0)); 146 memory_list_writer->AddMemory(std::move(memory_writer_0));
147 auto memory_writer_1 = base::WrapUnique( 147 auto memory_writer_1 = base::WrapUnique(
148 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); 148 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1));
149 memory_list_writer->AddMemory(std::move(memory_writer_1)); 149 memory_list_writer->AddMemory(std::move(memory_writer_1));
150 150
151 minidump_file_writer.AddStream(std::move(memory_list_writer)); 151 ASSERT_TRUE(minidump_file_writer.AddStream(std::move(memory_list_writer)));
152 152
153 StringFile string_file; 153 StringFile string_file;
154 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 154 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
155 155
156 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; 156 const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
157 ASSERT_NO_FATAL_FAILURE( 157 ASSERT_NO_FATAL_FAILURE(
158 GetMemoryListStream(string_file.string(), &memory_list, 1)); 158 GetMemoryListStream(string_file.string(), &memory_list, 1));
159 159
160 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); 160 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
161 161
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 240
241 const uint64_t kBaseAddress0 = 0x1000; 241 const uint64_t kBaseAddress0 = 0x1000;
242 const size_t kSize0 = 0x0400; 242 const size_t kSize0 = 0x0400;
243 const uint8_t kValue0 = '1'; 243 const uint8_t kValue0 = '1';
244 auto test_memory_stream = 244 auto test_memory_stream =
245 base::WrapUnique(new TestMemoryStream(kBaseAddress0, kSize0, kValue0)); 245 base::WrapUnique(new TestMemoryStream(kBaseAddress0, kSize0, kValue0));
246 246
247 auto memory_list_writer = base::WrapUnique(new MinidumpMemoryListWriter()); 247 auto memory_list_writer = base::WrapUnique(new MinidumpMemoryListWriter());
248 memory_list_writer->AddExtraMemory(test_memory_stream->memory()); 248 memory_list_writer->AddExtraMemory(test_memory_stream->memory());
249 249
250 minidump_file_writer.AddStream(std::move(test_memory_stream)); 250 ASSERT_TRUE(minidump_file_writer.AddStream(std::move(test_memory_stream)));
251 251
252 const uint64_t kBaseAddress1 = 0x2000; 252 const uint64_t kBaseAddress1 = 0x2000;
253 const size_t kSize1 = 0x0400; 253 const size_t kSize1 = 0x0400;
254 const uint8_t kValue1 = 'm'; 254 const uint8_t kValue1 = 'm';
255 255
256 auto memory_writer = base::WrapUnique( 256 auto memory_writer = base::WrapUnique(
257 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); 257 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1));
258 memory_list_writer->AddMemory(std::move(memory_writer)); 258 memory_list_writer->AddMemory(std::move(memory_writer));
259 259
260 minidump_file_writer.AddStream(std::move(memory_list_writer)); 260 ASSERT_TRUE(minidump_file_writer.AddStream(std::move(memory_list_writer)));
261 261
262 StringFile string_file; 262 StringFile string_file;
263 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 263 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
264 264
265 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; 265 const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
266 ASSERT_NO_FATAL_FAILURE( 266 ASSERT_NO_FATAL_FAILURE(
267 GetMemoryListStream(string_file.string(), &memory_list, 2)); 267 GetMemoryListStream(string_file.string(), &memory_list, 2));
268 268
269 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); 269 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
270 270
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 expect_memory_descriptors[index].StartOfMemoryRange); 328 expect_memory_descriptors[index].StartOfMemoryRange);
329 memory_snapshot->SetSize(expect_memory_descriptors[index].Memory.DataSize); 329 memory_snapshot->SetSize(expect_memory_descriptors[index].Memory.DataSize);
330 memory_snapshot->SetValue(values[index]); 330 memory_snapshot->SetValue(values[index]);
331 memory_snapshots.push_back(memory_snapshot); 331 memory_snapshots.push_back(memory_snapshot);
332 } 332 }
333 333
334 auto memory_list_writer = base::WrapUnique(new MinidumpMemoryListWriter()); 334 auto memory_list_writer = base::WrapUnique(new MinidumpMemoryListWriter());
335 memory_list_writer->AddFromSnapshot(memory_snapshots); 335 memory_list_writer->AddFromSnapshot(memory_snapshots);
336 336
337 MinidumpFileWriter minidump_file_writer; 337 MinidumpFileWriter minidump_file_writer;
338 minidump_file_writer.AddStream(std::move(memory_list_writer)); 338 ASSERT_TRUE(minidump_file_writer.AddStream(std::move(memory_list_writer)));
339 339
340 StringFile string_file; 340 StringFile string_file;
341 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 341 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
342 342
343 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; 343 const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
344 ASSERT_NO_FATAL_FAILURE( 344 ASSERT_NO_FATAL_FAILURE(
345 GetMemoryListStream(string_file.string(), &memory_list, 1)); 345 GetMemoryListStream(string_file.string(), &memory_list, 1));
346 346
347 ASSERT_EQ(3u, memory_list->NumberOfMemoryRanges); 347 ASSERT_EQ(3u, memory_list->NumberOfMemoryRanges);
348 348
349 for (size_t index = 0; index < memory_list->NumberOfMemoryRanges; ++index) { 349 for (size_t index = 0; index < memory_list->NumberOfMemoryRanges; ++index) {
350 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); 350 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index));
351 ExpectMinidumpMemoryDescriptorAndContents( 351 ExpectMinidumpMemoryDescriptorAndContents(
352 &expect_memory_descriptors[index], 352 &expect_memory_descriptors[index],
353 &memory_list->MemoryRanges[index], 353 &memory_list->MemoryRanges[index],
354 string_file.string(), 354 string_file.string(),
355 values[index], 355 values[index],
356 index == memory_list->NumberOfMemoryRanges - 1); 356 index == memory_list->NumberOfMemoryRanges - 1);
357 } 357 }
358 } 358 }
359 359
360 } // namespace 360 } // namespace
361 } // namespace test 361 } // namespace test
362 } // namespace crashpad 362 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698