OLD | NEW |
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 12 matching lines...) Expand all Loading... |
23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
24 #include "gtest/gtest.h" | 24 #include "gtest/gtest.h" |
25 #include "minidump/minidump_extensions.h" | 25 #include "minidump/minidump_extensions.h" |
26 #include "minidump/minidump_file_writer.h" | 26 #include "minidump/minidump_file_writer.h" |
27 #include "minidump/minidump_stream_writer.h" | 27 #include "minidump/minidump_stream_writer.h" |
28 #include "minidump/test/minidump_file_writer_test_util.h" | 28 #include "minidump/test/minidump_file_writer_test_util.h" |
29 #include "minidump/test/minidump_memory_writer_test_util.h" | 29 #include "minidump/test/minidump_memory_writer_test_util.h" |
30 #include "minidump/test/minidump_writable_test_util.h" | 30 #include "minidump/test/minidump_writable_test_util.h" |
31 #include "snapshot/test/test_memory_snapshot.h" | 31 #include "snapshot/test/test_memory_snapshot.h" |
32 #include "util/file/string_file.h" | 32 #include "util/file/string_file.h" |
| 33 #include "util/stdlib/move.h" |
33 #include "util/stdlib/pointer_container.h" | 34 #include "util/stdlib/pointer_container.h" |
34 | 35 |
35 namespace crashpad { | 36 namespace crashpad { |
36 namespace test { | 37 namespace test { |
37 namespace { | 38 namespace { |
38 | 39 |
39 const MinidumpStreamType kBogusStreamType = | 40 const MinidumpStreamType kBogusStreamType = |
40 static_cast<MinidumpStreamType>(1234); | 41 static_cast<MinidumpStreamType>(1234); |
41 | 42 |
42 // expected_streams is the expected number of streams in the file. The memory | 43 // expected_streams is the expected number of streams in the file. The memory |
(...skipping 30 matching lines...) Expand all Loading... |
73 | 74 |
74 *memory_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( | 75 *memory_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( |
75 file_contents, directory[directory_index].Location); | 76 file_contents, directory[directory_index].Location); |
76 ASSERT_TRUE(memory_list); | 77 ASSERT_TRUE(memory_list); |
77 } | 78 } |
78 | 79 |
79 TEST(MinidumpMemoryWriter, EmptyMemoryList) { | 80 TEST(MinidumpMemoryWriter, EmptyMemoryList) { |
80 MinidumpFileWriter minidump_file_writer; | 81 MinidumpFileWriter minidump_file_writer; |
81 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 82 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
82 | 83 |
83 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 84 minidump_file_writer.AddStream(crashpad::move(memory_list_writer)); |
84 | 85 |
85 StringFile string_file; | 86 StringFile string_file; |
86 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 87 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
87 | 88 |
88 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 89 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
89 sizeof(MINIDUMP_MEMORY_LIST), | 90 sizeof(MINIDUMP_MEMORY_LIST), |
90 string_file.string().size()); | 91 string_file.string().size()); |
91 | 92 |
92 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 93 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
93 ASSERT_NO_FATAL_FAILURE( | 94 ASSERT_NO_FATAL_FAILURE( |
94 GetMemoryListStream(string_file.string(), &memory_list, 1)); | 95 GetMemoryListStream(string_file.string(), &memory_list, 1)); |
95 | 96 |
96 EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges); | 97 EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges); |
97 } | 98 } |
98 | 99 |
99 TEST(MinidumpMemoryWriter, OneMemoryRegion) { | 100 TEST(MinidumpMemoryWriter, OneMemoryRegion) { |
100 MinidumpFileWriter minidump_file_writer; | 101 MinidumpFileWriter minidump_file_writer; |
101 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 102 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
102 | 103 |
103 const uint64_t kBaseAddress = 0xfedcba9876543210; | 104 const uint64_t kBaseAddress = 0xfedcba9876543210; |
104 const uint64_t kSize = 0x1000; | 105 const uint64_t kSize = 0x1000; |
105 const uint8_t kValue = 'm'; | 106 const uint8_t kValue = 'm'; |
106 | 107 |
107 auto memory_writer = make_scoped_ptr( | 108 auto memory_writer = make_scoped_ptr( |
108 new TestMinidumpMemoryWriter(kBaseAddress, kSize, kValue)); | 109 new TestMinidumpMemoryWriter(kBaseAddress, kSize, kValue)); |
109 memory_list_writer->AddMemory(memory_writer.Pass()); | 110 memory_list_writer->AddMemory(crashpad::move(memory_writer)); |
110 | 111 |
111 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 112 minidump_file_writer.AddStream(crashpad::move(memory_list_writer)); |
112 | 113 |
113 StringFile string_file; | 114 StringFile string_file; |
114 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 115 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
115 | 116 |
116 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 117 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
117 ASSERT_NO_FATAL_FAILURE( | 118 ASSERT_NO_FATAL_FAILURE( |
118 GetMemoryListStream(string_file.string(), &memory_list, 1)); | 119 GetMemoryListStream(string_file.string(), &memory_list, 1)); |
119 | 120 |
120 MINIDUMP_MEMORY_DESCRIPTOR expected; | 121 MINIDUMP_MEMORY_DESCRIPTOR expected; |
121 expected.StartOfMemoryRange = kBaseAddress; | 122 expected.StartOfMemoryRange = kBaseAddress; |
(...skipping 15 matching lines...) Expand all Loading... |
137 | 138 |
138 const uint64_t kBaseAddress0 = 0xc0ffee; | 139 const uint64_t kBaseAddress0 = 0xc0ffee; |
139 const uint64_t kSize0 = 0x0100; | 140 const uint64_t kSize0 = 0x0100; |
140 const uint8_t kValue0 = '6'; | 141 const uint8_t kValue0 = '6'; |
141 const uint64_t kBaseAddress1 = 0xfac00fac; | 142 const uint64_t kBaseAddress1 = 0xfac00fac; |
142 const uint64_t kSize1 = 0x0200; | 143 const uint64_t kSize1 = 0x0200; |
143 const uint8_t kValue1 = '!'; | 144 const uint8_t kValue1 = '!'; |
144 | 145 |
145 auto memory_writer_0 = make_scoped_ptr( | 146 auto memory_writer_0 = make_scoped_ptr( |
146 new TestMinidumpMemoryWriter(kBaseAddress0, kSize0, kValue0)); | 147 new TestMinidumpMemoryWriter(kBaseAddress0, kSize0, kValue0)); |
147 memory_list_writer->AddMemory(memory_writer_0.Pass()); | 148 memory_list_writer->AddMemory(crashpad::move(memory_writer_0)); |
148 auto memory_writer_1 = make_scoped_ptr( | 149 auto memory_writer_1 = make_scoped_ptr( |
149 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); | 150 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); |
150 memory_list_writer->AddMemory(memory_writer_1.Pass()); | 151 memory_list_writer->AddMemory(crashpad::move(memory_writer_1)); |
151 | 152 |
152 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 153 minidump_file_writer.AddStream(crashpad::move(memory_list_writer)); |
153 | 154 |
154 StringFile string_file; | 155 StringFile string_file; |
155 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 156 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
156 | 157 |
157 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 158 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
158 ASSERT_NO_FATAL_FAILURE( | 159 ASSERT_NO_FATAL_FAILURE( |
159 GetMemoryListStream(string_file.string(), &memory_list, 1)); | 160 GetMemoryListStream(string_file.string(), &memory_list, 1)); |
160 | 161 |
161 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); | 162 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); |
162 | 163 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 242 |
242 const uint64_t kBaseAddress0 = 0x1000; | 243 const uint64_t kBaseAddress0 = 0x1000; |
243 const size_t kSize0 = 0x0400; | 244 const size_t kSize0 = 0x0400; |
244 const uint8_t kValue0 = '1'; | 245 const uint8_t kValue0 = '1'; |
245 auto test_memory_stream = | 246 auto test_memory_stream = |
246 make_scoped_ptr(new TestMemoryStream(kBaseAddress0, kSize0, kValue0)); | 247 make_scoped_ptr(new TestMemoryStream(kBaseAddress0, kSize0, kValue0)); |
247 | 248 |
248 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 249 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
249 memory_list_writer->AddExtraMemory(test_memory_stream->memory()); | 250 memory_list_writer->AddExtraMemory(test_memory_stream->memory()); |
250 | 251 |
251 minidump_file_writer.AddStream(test_memory_stream.Pass()); | 252 minidump_file_writer.AddStream(crashpad::move(test_memory_stream)); |
252 | 253 |
253 const uint64_t kBaseAddress1 = 0x2000; | 254 const uint64_t kBaseAddress1 = 0x2000; |
254 const size_t kSize1 = 0x0400; | 255 const size_t kSize1 = 0x0400; |
255 const uint8_t kValue1 = 'm'; | 256 const uint8_t kValue1 = 'm'; |
256 | 257 |
257 auto memory_writer = make_scoped_ptr( | 258 auto memory_writer = make_scoped_ptr( |
258 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); | 259 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); |
259 memory_list_writer->AddMemory(memory_writer.Pass()); | 260 memory_list_writer->AddMemory(crashpad::move(memory_writer)); |
260 | 261 |
261 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 262 minidump_file_writer.AddStream(crashpad::move(memory_list_writer)); |
262 | 263 |
263 StringFile string_file; | 264 StringFile string_file; |
264 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 265 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
265 | 266 |
266 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 267 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
267 ASSERT_NO_FATAL_FAILURE( | 268 ASSERT_NO_FATAL_FAILURE( |
268 GetMemoryListStream(string_file.string(), &memory_list, 2)); | 269 GetMemoryListStream(string_file.string(), &memory_list, 2)); |
269 | 270 |
270 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); | 271 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); |
271 | 272 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 expect_memory_descriptors[index].StartOfMemoryRange); | 330 expect_memory_descriptors[index].StartOfMemoryRange); |
330 memory_snapshot->SetSize(expect_memory_descriptors[index].Memory.DataSize); | 331 memory_snapshot->SetSize(expect_memory_descriptors[index].Memory.DataSize); |
331 memory_snapshot->SetValue(values[index]); | 332 memory_snapshot->SetValue(values[index]); |
332 memory_snapshots.push_back(memory_snapshot); | 333 memory_snapshots.push_back(memory_snapshot); |
333 } | 334 } |
334 | 335 |
335 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 336 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
336 memory_list_writer->AddFromSnapshot(memory_snapshots); | 337 memory_list_writer->AddFromSnapshot(memory_snapshots); |
337 | 338 |
338 MinidumpFileWriter minidump_file_writer; | 339 MinidumpFileWriter minidump_file_writer; |
339 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 340 minidump_file_writer.AddStream(crashpad::move(memory_list_writer)); |
340 | 341 |
341 StringFile string_file; | 342 StringFile string_file; |
342 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 343 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
343 | 344 |
344 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 345 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
345 ASSERT_NO_FATAL_FAILURE( | 346 ASSERT_NO_FATAL_FAILURE( |
346 GetMemoryListStream(string_file.string(), &memory_list, 1)); | 347 GetMemoryListStream(string_file.string(), &memory_list, 1)); |
347 | 348 |
348 ASSERT_EQ(3u, memory_list->NumberOfMemoryRanges); | 349 ASSERT_EQ(3u, memory_list->NumberOfMemoryRanges); |
349 | 350 |
350 for (size_t index = 0; index < memory_list->NumberOfMemoryRanges; ++index) { | 351 for (size_t index = 0; index < memory_list->NumberOfMemoryRanges; ++index) { |
351 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); | 352 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); |
352 ExpectMinidumpMemoryDescriptorAndContents( | 353 ExpectMinidumpMemoryDescriptorAndContents( |
353 &expect_memory_descriptors[index], | 354 &expect_memory_descriptors[index], |
354 &memory_list->MemoryRanges[index], | 355 &memory_list->MemoryRanges[index], |
355 string_file.string(), | 356 string_file.string(), |
356 values[index], | 357 values[index], |
357 index == memory_list->NumberOfMemoryRanges - 1); | 358 index == memory_list->NumberOfMemoryRanges - 1); |
358 } | 359 } |
359 } | 360 } |
360 | 361 |
361 } // namespace | 362 } // namespace |
362 } // namespace test | 363 } // namespace test |
363 } // namespace crashpad | 364 } // namespace crashpad |
OLD | NEW |