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

Side by Side Diff: minidump/minidump_file_writer_test.cc

Issue 936153002: Add FileReaderInterface. Move StringFileWriter to StringFile and (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Remove unused #include 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 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 14 matching lines...) Expand all
25 #include "minidump/minidump_stream_writer.h" 25 #include "minidump/minidump_stream_writer.h"
26 #include "minidump/minidump_writable.h" 26 #include "minidump/minidump_writable.h"
27 #include "minidump/test/minidump_file_writer_test_util.h" 27 #include "minidump/test/minidump_file_writer_test_util.h"
28 #include "minidump/test/minidump_writable_test_util.h" 28 #include "minidump/test/minidump_writable_test_util.h"
29 #include "snapshot/test/test_cpu_context.h" 29 #include "snapshot/test/test_cpu_context.h"
30 #include "snapshot/test/test_exception_snapshot.h" 30 #include "snapshot/test/test_exception_snapshot.h"
31 #include "snapshot/test/test_module_snapshot.h" 31 #include "snapshot/test/test_module_snapshot.h"
32 #include "snapshot/test/test_process_snapshot.h" 32 #include "snapshot/test/test_process_snapshot.h"
33 #include "snapshot/test/test_system_snapshot.h" 33 #include "snapshot/test/test_system_snapshot.h"
34 #include "snapshot/test/test_thread_snapshot.h" 34 #include "snapshot/test/test_thread_snapshot.h"
35 #include "util/file/file_writer.h" 35 #include "util/file/string_file.h"
36 #include "util/file/string_file_writer.h" 36 #include "util/file/string_file.h"
37 37
38 namespace crashpad { 38 namespace crashpad {
39 namespace test { 39 namespace test {
40 namespace { 40 namespace {
41 41
42 TEST(MinidumpFileWriter, Empty) { 42 TEST(MinidumpFileWriter, Empty) {
43 MinidumpFileWriter minidump_file; 43 MinidumpFileWriter minidump_file;
44 StringFileWriter file_writer; 44 StringFile string_file;
45 ASSERT_TRUE(minidump_file.WriteEverything(&file_writer)); 45 ASSERT_TRUE(minidump_file.WriteEverything(&string_file));
46 ASSERT_EQ(sizeof(MINIDUMP_HEADER), file_writer.string().size()); 46 ASSERT_EQ(sizeof(MINIDUMP_HEADER), string_file.string().size());
47 47
48 const MINIDUMP_DIRECTORY* directory; 48 const MINIDUMP_DIRECTORY* directory;
49 const MINIDUMP_HEADER* header = 49 const MINIDUMP_HEADER* header =
50 MinidumpHeaderAtStart(file_writer.string(), &directory); 50 MinidumpHeaderAtStart(string_file.string(), &directory);
51 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 0, 0)); 51 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 0, 0));
52 EXPECT_FALSE(directory); 52 EXPECT_FALSE(directory);
53 } 53 }
54 54
55 class TestStream final : public internal::MinidumpStreamWriter { 55 class TestStream final : public internal::MinidumpStreamWriter {
56 public: 56 public:
57 TestStream(MinidumpStreamType stream_type, 57 TestStream(MinidumpStreamType stream_type,
58 size_t stream_size, 58 size_t stream_size,
59 uint8_t stream_value) 59 uint8_t stream_value)
60 : stream_data_(stream_size, stream_value), stream_type_(stream_type) {} 60 : stream_data_(stream_size, stream_value), stream_type_(stream_type) {}
(...skipping 29 matching lines...) Expand all
90 const time_t kTimestamp = 0x155d2fb8; 90 const time_t kTimestamp = 0x155d2fb8;
91 minidump_file.SetTimestamp(kTimestamp); 91 minidump_file.SetTimestamp(kTimestamp);
92 92
93 const size_t kStreamSize = 5; 93 const size_t kStreamSize = 5;
94 const MinidumpStreamType kStreamType = static_cast<MinidumpStreamType>(0x4d); 94 const MinidumpStreamType kStreamType = static_cast<MinidumpStreamType>(0x4d);
95 const uint8_t kStreamValue = 0x5a; 95 const uint8_t kStreamValue = 0x5a;
96 auto stream = 96 auto stream =
97 make_scoped_ptr(new TestStream(kStreamType, kStreamSize, kStreamValue)); 97 make_scoped_ptr(new TestStream(kStreamType, kStreamSize, kStreamValue));
98 minidump_file.AddStream(stream.Pass()); 98 minidump_file.AddStream(stream.Pass());
99 99
100 StringFileWriter file_writer; 100 StringFile string_file;
101 ASSERT_TRUE(minidump_file.WriteEverything(&file_writer)); 101 ASSERT_TRUE(minidump_file.WriteEverything(&string_file));
102 102
103 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); 103 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
104 const size_t kStreamOffset = kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); 104 const size_t kStreamOffset = kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY);
105 const size_t kFileSize = kStreamOffset + kStreamSize; 105 const size_t kFileSize = kStreamOffset + kStreamSize;
106 106
107 ASSERT_EQ(kFileSize, file_writer.string().size()); 107 ASSERT_EQ(kFileSize, string_file.string().size());
108 108
109 const MINIDUMP_DIRECTORY* directory; 109 const MINIDUMP_DIRECTORY* directory;
110 const MINIDUMP_HEADER* header = 110 const MINIDUMP_HEADER* header =
111 MinidumpHeaderAtStart(file_writer.string(), &directory); 111 MinidumpHeaderAtStart(string_file.string(), &directory);
112 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, kTimestamp)); 112 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, kTimestamp));
113 ASSERT_TRUE(directory); 113 ASSERT_TRUE(directory);
114 114
115 EXPECT_EQ(kStreamType, directory[0].StreamType); 115 EXPECT_EQ(kStreamType, directory[0].StreamType);
116 EXPECT_EQ(kStreamSize, directory[0].Location.DataSize); 116 EXPECT_EQ(kStreamSize, directory[0].Location.DataSize);
117 EXPECT_EQ(kStreamOffset, directory[0].Location.Rva); 117 EXPECT_EQ(kStreamOffset, directory[0].Location.Rva);
118 118
119 const uint8_t* stream_data = MinidumpWritableAtLocationDescriptor<uint8_t>( 119 const uint8_t* stream_data = MinidumpWritableAtLocationDescriptor<uint8_t>(
120 file_writer.string(), directory[0].Location); 120 string_file.string(), directory[0].Location);
121 ASSERT_TRUE(stream_data); 121 ASSERT_TRUE(stream_data);
122 122
123 std::string expected_stream(kStreamSize, kStreamValue); 123 std::string expected_stream(kStreamSize, kStreamValue);
124 EXPECT_EQ(0, memcmp(stream_data, expected_stream.c_str(), kStreamSize)); 124 EXPECT_EQ(0, memcmp(stream_data, expected_stream.c_str(), kStreamSize));
125 } 125 }
126 126
127 TEST(MinidumpFileWriter, ThreeStreams) { 127 TEST(MinidumpFileWriter, ThreeStreams) {
128 MinidumpFileWriter minidump_file; 128 MinidumpFileWriter minidump_file;
129 const time_t kTimestamp = 0x155d2fb8; 129 const time_t kTimestamp = 0x155d2fb8;
130 minidump_file.SetTimestamp(kTimestamp); 130 minidump_file.SetTimestamp(kTimestamp);
(...skipping 15 matching lines...) Expand all
146 new TestStream(kStream1Type, kStream1Size, kStream1Value)); 146 new TestStream(kStream1Type, kStream1Size, kStream1Value));
147 minidump_file.AddStream(stream1.Pass()); 147 minidump_file.AddStream(stream1.Pass());
148 148
149 const size_t kStream2Size = 1; 149 const size_t kStream2Size = 1;
150 const MinidumpStreamType kStream2Type = static_cast<MinidumpStreamType>(0x7e); 150 const MinidumpStreamType kStream2Type = static_cast<MinidumpStreamType>(0x7e);
151 const uint8_t kStream2Value = 0x36; 151 const uint8_t kStream2Value = 0x36;
152 auto stream2 = make_scoped_ptr( 152 auto stream2 = make_scoped_ptr(
153 new TestStream(kStream2Type, kStream2Size, kStream2Value)); 153 new TestStream(kStream2Type, kStream2Size, kStream2Value));
154 minidump_file.AddStream(stream2.Pass()); 154 minidump_file.AddStream(stream2.Pass());
155 155
156 StringFileWriter file_writer; 156 StringFile string_file;
157 ASSERT_TRUE(minidump_file.WriteEverything(&file_writer)); 157 ASSERT_TRUE(minidump_file.WriteEverything(&string_file));
158 158
159 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); 159 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
160 const size_t kStream0Offset = 160 const size_t kStream0Offset =
161 kDirectoryOffset + 3 * sizeof(MINIDUMP_DIRECTORY); 161 kDirectoryOffset + 3 * sizeof(MINIDUMP_DIRECTORY);
162 const size_t kStream1Padding = 3; 162 const size_t kStream1Padding = 3;
163 const size_t kStream1Offset = kStream0Offset + kStream0Size + kStream1Padding; 163 const size_t kStream1Offset = kStream0Offset + kStream0Size + kStream1Padding;
164 const size_t kStream2Padding = 1; 164 const size_t kStream2Padding = 1;
165 const size_t kStream2Offset = kStream1Offset + kStream1Size + kStream2Padding; 165 const size_t kStream2Offset = kStream1Offset + kStream1Size + kStream2Padding;
166 const size_t kFileSize = kStream2Offset + kStream2Size; 166 const size_t kFileSize = kStream2Offset + kStream2Size;
167 167
168 ASSERT_EQ(kFileSize, file_writer.string().size()); 168 ASSERT_EQ(kFileSize, string_file.string().size());
169 169
170 const MINIDUMP_DIRECTORY* directory; 170 const MINIDUMP_DIRECTORY* directory;
171 const MINIDUMP_HEADER* header = 171 const MINIDUMP_HEADER* header =
172 MinidumpHeaderAtStart(file_writer.string(), &directory); 172 MinidumpHeaderAtStart(string_file.string(), &directory);
173 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 3, kTimestamp)); 173 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 3, kTimestamp));
174 ASSERT_TRUE(directory); 174 ASSERT_TRUE(directory);
175 175
176 EXPECT_EQ(kStream0Type, directory[0].StreamType); 176 EXPECT_EQ(kStream0Type, directory[0].StreamType);
177 EXPECT_EQ(kStream0Size, directory[0].Location.DataSize); 177 EXPECT_EQ(kStream0Size, directory[0].Location.DataSize);
178 EXPECT_EQ(kStream0Offset, directory[0].Location.Rva); 178 EXPECT_EQ(kStream0Offset, directory[0].Location.Rva);
179 EXPECT_EQ(kStream1Type, directory[1].StreamType); 179 EXPECT_EQ(kStream1Type, directory[1].StreamType);
180 EXPECT_EQ(kStream1Size, directory[1].Location.DataSize); 180 EXPECT_EQ(kStream1Size, directory[1].Location.DataSize);
181 EXPECT_EQ(kStream1Offset, directory[1].Location.Rva); 181 EXPECT_EQ(kStream1Offset, directory[1].Location.Rva);
182 EXPECT_EQ(kStream2Type, directory[2].StreamType); 182 EXPECT_EQ(kStream2Type, directory[2].StreamType);
183 EXPECT_EQ(kStream2Size, directory[2].Location.DataSize); 183 EXPECT_EQ(kStream2Size, directory[2].Location.DataSize);
184 EXPECT_EQ(kStream2Offset, directory[2].Location.Rva); 184 EXPECT_EQ(kStream2Offset, directory[2].Location.Rva);
185 185
186 const uint8_t* stream0_data = MinidumpWritableAtLocationDescriptor<uint8_t>( 186 const uint8_t* stream0_data = MinidumpWritableAtLocationDescriptor<uint8_t>(
187 file_writer.string(), directory[0].Location); 187 string_file.string(), directory[0].Location);
188 ASSERT_TRUE(stream0_data); 188 ASSERT_TRUE(stream0_data);
189 189
190 std::string expected_stream0(kStream0Size, kStream0Value); 190 std::string expected_stream0(kStream0Size, kStream0Value);
191 EXPECT_EQ(0, memcmp(stream0_data, expected_stream0.c_str(), kStream0Size)); 191 EXPECT_EQ(0, memcmp(stream0_data, expected_stream0.c_str(), kStream0Size));
192 192
193 const int kZeroes[16] = {}; 193 const int kZeroes[16] = {};
194 ASSERT_GE(sizeof(kZeroes), kStream1Padding); 194 ASSERT_GE(sizeof(kZeroes), kStream1Padding);
195 EXPECT_EQ(0, memcmp(stream0_data + kStream0Size, kZeroes, kStream1Padding)); 195 EXPECT_EQ(0, memcmp(stream0_data + kStream0Size, kZeroes, kStream1Padding));
196 196
197 const uint8_t* stream1_data = MinidumpWritableAtLocationDescriptor<uint8_t>( 197 const uint8_t* stream1_data = MinidumpWritableAtLocationDescriptor<uint8_t>(
198 file_writer.string(), directory[1].Location); 198 string_file.string(), directory[1].Location);
199 ASSERT_TRUE(stream1_data); 199 ASSERT_TRUE(stream1_data);
200 200
201 std::string expected_stream1(kStream1Size, kStream1Value); 201 std::string expected_stream1(kStream1Size, kStream1Value);
202 EXPECT_EQ(0, memcmp(stream1_data, expected_stream1.c_str(), kStream1Size)); 202 EXPECT_EQ(0, memcmp(stream1_data, expected_stream1.c_str(), kStream1Size));
203 203
204 ASSERT_GE(sizeof(kZeroes), kStream2Padding); 204 ASSERT_GE(sizeof(kZeroes), kStream2Padding);
205 EXPECT_EQ(0, memcmp(stream1_data + kStream1Size, kZeroes, kStream2Padding)); 205 EXPECT_EQ(0, memcmp(stream1_data + kStream1Size, kZeroes, kStream2Padding));
206 206
207 const uint8_t* stream2_data = MinidumpWritableAtLocationDescriptor<uint8_t>( 207 const uint8_t* stream2_data = MinidumpWritableAtLocationDescriptor<uint8_t>(
208 file_writer.string(), directory[2].Location); 208 string_file.string(), directory[2].Location);
209 ASSERT_TRUE(stream2_data); 209 ASSERT_TRUE(stream2_data);
210 210
211 std::string expected_stream2(kStream2Size, kStream2Value); 211 std::string expected_stream2(kStream2Size, kStream2Value);
212 EXPECT_EQ(0, memcmp(stream2_data, expected_stream2.c_str(), kStream2Size)); 212 EXPECT_EQ(0, memcmp(stream2_data, expected_stream2.c_str(), kStream2Size));
213 } 213 }
214 214
215 TEST(MinidumpFileWriter, ZeroLengthStream) { 215 TEST(MinidumpFileWriter, ZeroLengthStream) {
216 MinidumpFileWriter minidump_file; 216 MinidumpFileWriter minidump_file;
217 217
218 const size_t kStreamSize = 0; 218 const size_t kStreamSize = 0;
219 const MinidumpStreamType kStreamType = static_cast<MinidumpStreamType>(0x4d); 219 const MinidumpStreamType kStreamType = static_cast<MinidumpStreamType>(0x4d);
220 auto stream = make_scoped_ptr(new TestStream(kStreamType, kStreamSize, 0)); 220 auto stream = make_scoped_ptr(new TestStream(kStreamType, kStreamSize, 0));
221 minidump_file.AddStream(stream.Pass()); 221 minidump_file.AddStream(stream.Pass());
222 222
223 StringFileWriter file_writer; 223 StringFile string_file;
224 ASSERT_TRUE(minidump_file.WriteEverything(&file_writer)); 224 ASSERT_TRUE(minidump_file.WriteEverything(&string_file));
225 225
226 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); 226 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
227 const size_t kStreamOffset = kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); 227 const size_t kStreamOffset = kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY);
228 const size_t kFileSize = kStreamOffset + kStreamSize; 228 const size_t kFileSize = kStreamOffset + kStreamSize;
229 229
230 ASSERT_EQ(kFileSize, file_writer.string().size()); 230 ASSERT_EQ(kFileSize, string_file.string().size());
231 231
232 const MINIDUMP_DIRECTORY* directory; 232 const MINIDUMP_DIRECTORY* directory;
233 const MINIDUMP_HEADER* header = 233 const MINIDUMP_HEADER* header =
234 MinidumpHeaderAtStart(file_writer.string(), &directory); 234 MinidumpHeaderAtStart(string_file.string(), &directory);
235 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0)); 235 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0));
236 ASSERT_TRUE(directory); 236 ASSERT_TRUE(directory);
237 237
238 EXPECT_EQ(kStreamType, directory[0].StreamType); 238 EXPECT_EQ(kStreamType, directory[0].StreamType);
239 EXPECT_EQ(kStreamSize, directory[0].Location.DataSize); 239 EXPECT_EQ(kStreamSize, directory[0].Location.DataSize);
240 EXPECT_EQ(kStreamOffset, directory[0].Location.Rva); 240 EXPECT_EQ(kStreamOffset, directory[0].Location.Rva);
241 } 241 }
242 242
243 TEST(MinidumpFileWriter, InitializeFromSnapshot_Basic) { 243 TEST(MinidumpFileWriter, InitializeFromSnapshot_Basic) {
244 const uint32_t kSnapshotTime = 0x4976043c; 244 const uint32_t kSnapshotTime = 0x4976043c;
245 const timeval kSnapshotTimeval = { static_cast<time_t>(kSnapshotTime), 0 }; 245 const timeval kSnapshotTimeval = { static_cast<time_t>(kSnapshotTime), 0 };
246 246
247 TestProcessSnapshot process_snapshot; 247 TestProcessSnapshot process_snapshot;
248 process_snapshot.SetSnapshotTime(kSnapshotTimeval); 248 process_snapshot.SetSnapshotTime(kSnapshotTimeval);
249 249
250 auto system_snapshot = make_scoped_ptr(new TestSystemSnapshot()); 250 auto system_snapshot = make_scoped_ptr(new TestSystemSnapshot());
251 system_snapshot->SetCPUArchitecture(kCPUArchitectureX86_64); 251 system_snapshot->SetCPUArchitecture(kCPUArchitectureX86_64);
252 system_snapshot->SetOperatingSystem(SystemSnapshot::kOperatingSystemMacOSX); 252 system_snapshot->SetOperatingSystem(SystemSnapshot::kOperatingSystemMacOSX);
253 process_snapshot.SetSystem(system_snapshot.Pass()); 253 process_snapshot.SetSystem(system_snapshot.Pass());
254 254
255 MinidumpFileWriter minidump_file_writer; 255 MinidumpFileWriter minidump_file_writer;
256 minidump_file_writer.InitializeFromSnapshot(&process_snapshot); 256 minidump_file_writer.InitializeFromSnapshot(&process_snapshot);
257 257
258 StringFileWriter file_writer; 258 StringFile string_file;
259 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 259 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
260 260
261 const MINIDUMP_DIRECTORY* directory; 261 const MINIDUMP_DIRECTORY* directory;
262 const MINIDUMP_HEADER* header = 262 const MINIDUMP_HEADER* header =
263 MinidumpHeaderAtStart(file_writer.string(), &directory); 263 MinidumpHeaderAtStart(string_file.string(), &directory);
264 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 5, kSnapshotTime)); 264 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 5, kSnapshotTime));
265 ASSERT_TRUE(directory); 265 ASSERT_TRUE(directory);
266 266
267 EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType); 267 EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType);
268 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>( 268 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>(
269 file_writer.string(), directory[0].Location)); 269 string_file.string(), directory[0].Location));
270 270
271 EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType); 271 EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType);
272 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>( 272 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>(
273 file_writer.string(), directory[1].Location)); 273 string_file.string(), directory[1].Location));
274 274
275 EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType); 275 EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType);
276 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>( 276 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>(
277 file_writer.string(), directory[2].Location)); 277 string_file.string(), directory[2].Location));
278 278
279 EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[3].StreamType); 279 EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[3].StreamType);
280 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>( 280 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>(
281 file_writer.string(), directory[3].Location)); 281 string_file.string(), directory[3].Location));
282 282
283 EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[4].StreamType); 283 EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[4].StreamType);
284 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( 284 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
285 file_writer.string(), directory[4].Location)); 285 string_file.string(), directory[4].Location));
286 } 286 }
287 287
288 TEST(MinidumpFileWriter, InitializeFromSnapshot_Exception) { 288 TEST(MinidumpFileWriter, InitializeFromSnapshot_Exception) {
289 // In a 32-bit environment, this will give a “timestamp out of range” warning, 289 // In a 32-bit environment, this will give a “timestamp out of range” warning,
290 // but the test should complete without failure. 290 // but the test should complete without failure.
291 const uint32_t kSnapshotTime = 0xfd469ab8; 291 const uint32_t kSnapshotTime = 0xfd469ab8;
292 MSVC_SUPPRESS_WARNING(4309); // Truncation of constant value. 292 MSVC_SUPPRESS_WARNING(4309); // Truncation of constant value.
293 const timeval kSnapshotTimeval = { static_cast<time_t>(kSnapshotTime), 0 }; 293 const timeval kSnapshotTimeval = { static_cast<time_t>(kSnapshotTime), 0 };
294 294
295 TestProcessSnapshot process_snapshot; 295 TestProcessSnapshot process_snapshot;
(...skipping 15 matching lines...) Expand all
311 // The module does not have anything that needs to be represented in a 311 // The module does not have anything that needs to be represented in a
312 // MinidumpModuleCrashpadInfo structure, so no such structure is expected to 312 // MinidumpModuleCrashpadInfo structure, so no such structure is expected to
313 // be present, which will in turn suppress the addition of a 313 // be present, which will in turn suppress the addition of a
314 // MinidumpCrashpadInfo stream. 314 // MinidumpCrashpadInfo stream.
315 auto module_snapshot = make_scoped_ptr(new TestModuleSnapshot()); 315 auto module_snapshot = make_scoped_ptr(new TestModuleSnapshot());
316 process_snapshot.AddModule(module_snapshot.Pass()); 316 process_snapshot.AddModule(module_snapshot.Pass());
317 317
318 MinidumpFileWriter minidump_file_writer; 318 MinidumpFileWriter minidump_file_writer;
319 minidump_file_writer.InitializeFromSnapshot(&process_snapshot); 319 minidump_file_writer.InitializeFromSnapshot(&process_snapshot);
320 320
321 StringFileWriter file_writer; 321 StringFile string_file;
322 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 322 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
323 323
324 const MINIDUMP_DIRECTORY* directory; 324 const MINIDUMP_DIRECTORY* directory;
325 const MINIDUMP_HEADER* header = 325 const MINIDUMP_HEADER* header =
326 MinidumpHeaderAtStart(file_writer.string(), &directory); 326 MinidumpHeaderAtStart(string_file.string(), &directory);
327 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 6, kSnapshotTime)); 327 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 6, kSnapshotTime));
328 ASSERT_TRUE(directory); 328 ASSERT_TRUE(directory);
329 329
330 EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType); 330 EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType);
331 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>( 331 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>(
332 file_writer.string(), directory[0].Location)); 332 string_file.string(), directory[0].Location));
333 333
334 EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType); 334 EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType);
335 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>( 335 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>(
336 file_writer.string(), directory[1].Location)); 336 string_file.string(), directory[1].Location));
337 337
338 EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType); 338 EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType);
339 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>( 339 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>(
340 file_writer.string(), directory[2].Location)); 340 string_file.string(), directory[2].Location));
341 341
342 EXPECT_EQ(kMinidumpStreamTypeException, directory[3].StreamType); 342 EXPECT_EQ(kMinidumpStreamTypeException, directory[3].StreamType);
343 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_EXCEPTION_STREAM>( 343 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_EXCEPTION_STREAM>(
344 file_writer.string(), directory[3].Location)); 344 string_file.string(), directory[3].Location));
345 345
346 EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[4].StreamType); 346 EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[4].StreamType);
347 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>( 347 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>(
348 file_writer.string(), directory[4].Location)); 348 string_file.string(), directory[4].Location));
349 349
350 EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[5].StreamType); 350 EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[5].StreamType);
351 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( 351 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
352 file_writer.string(), directory[5].Location)); 352 string_file.string(), directory[5].Location));
353 } 353 }
354 354
355 TEST(MinidumpFileWriter, InitializeFromSnapshot_CrashpadInfo) { 355 TEST(MinidumpFileWriter, InitializeFromSnapshot_CrashpadInfo) {
356 const uint32_t kSnapshotTime = 0x15393bd3; 356 const uint32_t kSnapshotTime = 0x15393bd3;
357 const timeval kSnapshotTimeval = { static_cast<time_t>(kSnapshotTime), 0 }; 357 const timeval kSnapshotTimeval = { static_cast<time_t>(kSnapshotTime), 0 };
358 358
359 TestProcessSnapshot process_snapshot; 359 TestProcessSnapshot process_snapshot;
360 process_snapshot.SetSnapshotTime(kSnapshotTimeval); 360 process_snapshot.SetSnapshotTime(kSnapshotTimeval);
361 361
362 auto system_snapshot = make_scoped_ptr(new TestSystemSnapshot()); 362 auto system_snapshot = make_scoped_ptr(new TestSystemSnapshot());
(...skipping 12 matching lines...) Expand all
375 // The module needs an annotation for the MinidumpCrashpadInfo stream to be 375 // The module needs an annotation for the MinidumpCrashpadInfo stream to be
376 // considered useful and be included. 376 // considered useful and be included.
377 auto module_snapshot = make_scoped_ptr(new TestModuleSnapshot()); 377 auto module_snapshot = make_scoped_ptr(new TestModuleSnapshot());
378 std::vector<std::string> annotations_list(1, std::string("annotation")); 378 std::vector<std::string> annotations_list(1, std::string("annotation"));
379 module_snapshot->SetAnnotationsVector(annotations_list); 379 module_snapshot->SetAnnotationsVector(annotations_list);
380 process_snapshot.AddModule(module_snapshot.Pass()); 380 process_snapshot.AddModule(module_snapshot.Pass());
381 381
382 MinidumpFileWriter minidump_file_writer; 382 MinidumpFileWriter minidump_file_writer;
383 minidump_file_writer.InitializeFromSnapshot(&process_snapshot); 383 minidump_file_writer.InitializeFromSnapshot(&process_snapshot);
384 384
385 StringFileWriter file_writer; 385 StringFile string_file;
386 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 386 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
387 387
388 const MINIDUMP_DIRECTORY* directory; 388 const MINIDUMP_DIRECTORY* directory;
389 const MINIDUMP_HEADER* header = 389 const MINIDUMP_HEADER* header =
390 MinidumpHeaderAtStart(file_writer.string(), &directory); 390 MinidumpHeaderAtStart(string_file.string(), &directory);
391 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 7, kSnapshotTime)); 391 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 7, kSnapshotTime));
392 ASSERT_TRUE(directory); 392 ASSERT_TRUE(directory);
393 393
394 EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType); 394 EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType);
395 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>( 395 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>(
396 file_writer.string(), directory[0].Location)); 396 string_file.string(), directory[0].Location));
397 397
398 EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType); 398 EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType);
399 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>( 399 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>(
400 file_writer.string(), directory[1].Location)); 400 string_file.string(), directory[1].Location));
401 401
402 EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType); 402 EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType);
403 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>( 403 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>(
404 file_writer.string(), directory[2].Location)); 404 string_file.string(), directory[2].Location));
405 405
406 EXPECT_EQ(kMinidumpStreamTypeException, directory[3].StreamType); 406 EXPECT_EQ(kMinidumpStreamTypeException, directory[3].StreamType);
407 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_EXCEPTION_STREAM>( 407 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_EXCEPTION_STREAM>(
408 file_writer.string(), directory[3].Location)); 408 string_file.string(), directory[3].Location));
409 409
410 EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[4].StreamType); 410 EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[4].StreamType);
411 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>( 411 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>(
412 file_writer.string(), directory[4].Location)); 412 string_file.string(), directory[4].Location));
413 413
414 EXPECT_EQ(kMinidumpStreamTypeCrashpadInfo, directory[5].StreamType); 414 EXPECT_EQ(kMinidumpStreamTypeCrashpadInfo, directory[5].StreamType);
415 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MinidumpCrashpadInfo>( 415 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MinidumpCrashpadInfo>(
416 file_writer.string(), directory[5].Location)); 416 string_file.string(), directory[5].Location));
417 417
418 EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[6].StreamType); 418 EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[6].StreamType);
419 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( 419 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
420 file_writer.string(), directory[6].Location)); 420 string_file.string(), directory[6].Location));
421 } 421 }
422 422
423 TEST(MinidumpFileWriterDeathTest, SameStreamType) { 423 TEST(MinidumpFileWriterDeathTest, SameStreamType) {
424 MinidumpFileWriter minidump_file; 424 MinidumpFileWriter minidump_file;
425 425
426 const size_t kStream0Size = 5; 426 const size_t kStream0Size = 5;
427 const MinidumpStreamType kStream0Type = static_cast<MinidumpStreamType>(0x4d); 427 const MinidumpStreamType kStream0Type = static_cast<MinidumpStreamType>(0x4d);
428 const uint8_t kStream0Value = 0x5a; 428 const uint8_t kStream0Value = 0x5a;
429 auto stream0 = make_scoped_ptr( 429 auto stream0 = make_scoped_ptr(
430 new TestStream(kStream0Type, kStream0Size, kStream0Value)); 430 new TestStream(kStream0Type, kStream0Size, kStream0Value));
431 minidump_file.AddStream(stream0.Pass()); 431 minidump_file.AddStream(stream0.Pass());
432 432
433 // It is an error to add a second stream of the same type. 433 // It is an error to add a second stream of the same type.
434 const size_t kStream1Size = 3; 434 const size_t kStream1Size = 3;
435 const MinidumpStreamType kStream1Type = static_cast<MinidumpStreamType>(0x4d); 435 const MinidumpStreamType kStream1Type = static_cast<MinidumpStreamType>(0x4d);
436 const uint8_t kStream1Value = 0xa5; 436 const uint8_t kStream1Value = 0xa5;
437 auto stream1 = make_scoped_ptr( 437 auto stream1 = make_scoped_ptr(
438 new TestStream(kStream1Type, kStream1Size, kStream1Value)); 438 new TestStream(kStream1Type, kStream1Size, kStream1Value));
439 ASSERT_DEATH(minidump_file.AddStream(stream1.Pass()), "already present"); 439 ASSERT_DEATH(minidump_file.AddStream(stream1.Pass()), "already present");
440 } 440 }
441 441
442 } // namespace 442 } // namespace
443 } // namespace test 443 } // namespace test
444 } // namespace crashpad 444 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_exception_writer_test.cc ('k') | minidump/minidump_location_descriptor_list_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698