Chromium Code Reviews| 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, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "minidump/minidump_file_writer.h" | 15 #include "minidump/minidump_file_writer.h" |
| 16 | 16 |
| 17 #include <dbghelp.h> | 17 #include <dbghelp.h> |
| 18 | 18 |
| 19 #include <string> | 19 #include <string> |
| 20 | 20 |
| 21 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
| 22 #include "gtest/gtest.h" | 22 #include "gtest/gtest.h" |
| 23 #include "minidump/minidump_stream_writer.h" | 23 #include "minidump/minidump_stream_writer.h" |
| 24 #include "minidump/minidump_writable.h" | 24 #include "minidump/minidump_writable.h" |
| 25 #include "minidump/test/minidump_file_writer_test_util.h" | 25 #include "minidump/test/minidump_file_writer_test_util.h" |
| 26 #include "minidump/test/minidump_writable_test_util.h" | 26 #include "minidump/test/minidump_writable_test_util.h" |
| 27 #include "snapshot/test/test_cpu_context.h" | |
| 28 #include "snapshot/test/test_exception_snapshot.h" | |
| 29 #include "snapshot/test/test_module_snapshot.h" | |
| 30 #include "snapshot/test/test_process_snapshot.h" | |
| 31 #include "snapshot/test/test_system_snapshot.h" | |
| 32 #include "snapshot/test/test_thread_snapshot.h" | |
| 27 #include "util/file/file_writer.h" | 33 #include "util/file/file_writer.h" |
| 28 #include "util/file/string_file_writer.h" | 34 #include "util/file/string_file_writer.h" |
| 29 | 35 |
| 30 namespace crashpad { | 36 namespace crashpad { |
| 31 namespace test { | 37 namespace test { |
| 32 namespace { | 38 namespace { |
| 33 | 39 |
| 34 TEST(MinidumpFileWriter, Empty) { | 40 TEST(MinidumpFileWriter, Empty) { |
| 35 MinidumpFileWriter minidump_file; | 41 MinidumpFileWriter minidump_file; |
| 36 StringFileWriter file_writer; | 42 StringFileWriter file_writer; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 const MINIDUMP_HEADER* header = | 231 const MINIDUMP_HEADER* header = |
| 226 MinidumpHeaderAtStart(file_writer.string(), &directory); | 232 MinidumpHeaderAtStart(file_writer.string(), &directory); |
| 227 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0)); | 233 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0)); |
| 228 ASSERT_TRUE(directory); | 234 ASSERT_TRUE(directory); |
| 229 | 235 |
| 230 EXPECT_EQ(kStreamType, directory[0].StreamType); | 236 EXPECT_EQ(kStreamType, directory[0].StreamType); |
| 231 EXPECT_EQ(kStreamSize, directory[0].Location.DataSize); | 237 EXPECT_EQ(kStreamSize, directory[0].Location.DataSize); |
| 232 EXPECT_EQ(kStreamOffset, directory[0].Location.Rva); | 238 EXPECT_EQ(kStreamOffset, directory[0].Location.Rva); |
| 233 } | 239 } |
| 234 | 240 |
| 241 TEST(MinidumpFileWriter, InitializeFromSnapshot_Basic) { | |
| 242 const uint32_t kSnapshotTime = 0x4976043c; | |
| 243 const timeval kSnapshotTimeval = { implicit_cast<time_t>(kSnapshotTime), 0 }; | |
| 244 | |
| 245 TestProcessSnapshot process_snapshot; | |
| 246 process_snapshot.SetSnapshotTime(kSnapshotTimeval); | |
| 247 | |
| 248 auto system_snapshot = make_scoped_ptr(new TestSystemSnapshot()); | |
| 249 system_snapshot->SetCPUArchitecture(kCPUArchitectureX86_64); | |
| 250 system_snapshot->SetOperatingSystem(SystemSnapshot::kOperatingSystemMacOSX); | |
| 251 process_snapshot.SetSystem(system_snapshot.Pass()); | |
| 252 | |
| 253 MinidumpFileWriter minidump_file_writer; | |
| 254 minidump_file_writer.InitializeFromSnapshot(&process_snapshot); | |
| 255 | |
| 256 StringFileWriter file_writer; | |
| 257 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | |
| 258 | |
| 259 const MINIDUMP_DIRECTORY* directory; | |
| 260 const MINIDUMP_HEADER* header = | |
| 261 MinidumpHeaderAtStart(file_writer.string(), &directory); | |
| 262 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 5, kSnapshotTime)); | |
| 263 ASSERT_TRUE(directory); | |
| 264 | |
| 265 EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType); | |
|
Robert Sesek
2014/11/07 17:07:47
Is there any significance to the order in which th
| |
| 266 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>( | |
| 267 file_writer.string(), directory[0].Location)); | |
| 268 | |
| 269 EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType); | |
| 270 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>( | |
| 271 file_writer.string(), directory[1].Location)); | |
| 272 | |
| 273 EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType); | |
| 274 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>( | |
| 275 file_writer.string(), directory[2].Location)); | |
| 276 | |
| 277 EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[3].StreamType); | |
| 278 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>( | |
| 279 file_writer.string(), directory[3].Location)); | |
| 280 | |
| 281 EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[4].StreamType); | |
| 282 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( | |
| 283 file_writer.string(), directory[4].Location)); | |
| 284 } | |
| 285 | |
| 286 TEST(MinidumpFileWriter, InitializeFromSnapshot_Exception) { | |
| 287 // In a 32-bit environment, this will give a “timestamp out of range” warning, | |
| 288 // but the test should complete without failure. | |
| 289 const uint32_t kSnapshotTime = 0xfd469ab8; | |
| 290 const timeval kSnapshotTimeval = { implicit_cast<time_t>(kSnapshotTime), 0 }; | |
| 291 | |
| 292 TestProcessSnapshot process_snapshot; | |
| 293 process_snapshot.SetSnapshotTime(kSnapshotTimeval); | |
| 294 | |
| 295 auto system_snapshot = make_scoped_ptr(new TestSystemSnapshot()); | |
| 296 system_snapshot->SetCPUArchitecture(kCPUArchitectureX86_64); | |
| 297 system_snapshot->SetOperatingSystem(SystemSnapshot::kOperatingSystemMacOSX); | |
| 298 process_snapshot.SetSystem(system_snapshot.Pass()); | |
| 299 | |
| 300 auto thread_snapshot = make_scoped_ptr(new TestThreadSnapshot()); | |
| 301 InitializeCPUContextX86_64(thread_snapshot->MutableContext(), 5); | |
| 302 process_snapshot.AddThread(thread_snapshot.Pass()); | |
| 303 | |
| 304 auto exception_snapshot = make_scoped_ptr(new TestExceptionSnapshot()); | |
| 305 InitializeCPUContextX86_64(exception_snapshot->MutableContext(), 11); | |
| 306 process_snapshot.SetException(exception_snapshot.Pass()); | |
| 307 | |
| 308 MinidumpFileWriter minidump_file_writer; | |
| 309 minidump_file_writer.InitializeFromSnapshot(&process_snapshot); | |
| 310 | |
| 311 StringFileWriter file_writer; | |
| 312 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | |
| 313 | |
| 314 const MINIDUMP_DIRECTORY* directory; | |
| 315 const MINIDUMP_HEADER* header = | |
| 316 MinidumpHeaderAtStart(file_writer.string(), &directory); | |
| 317 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 6, kSnapshotTime)); | |
| 318 ASSERT_TRUE(directory); | |
| 319 | |
| 320 EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType); | |
| 321 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>( | |
| 322 file_writer.string(), directory[0].Location)); | |
| 323 | |
| 324 EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType); | |
| 325 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>( | |
| 326 file_writer.string(), directory[1].Location)); | |
| 327 | |
| 328 EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType); | |
| 329 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>( | |
| 330 file_writer.string(), directory[2].Location)); | |
| 331 | |
| 332 EXPECT_EQ(kMinidumpStreamTypeException, directory[3].StreamType); | |
| 333 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_EXCEPTION_STREAM>( | |
| 334 file_writer.string(), directory[3].Location)); | |
| 335 | |
| 336 EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[4].StreamType); | |
| 337 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>( | |
| 338 file_writer.string(), directory[4].Location)); | |
| 339 | |
| 340 EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[5].StreamType); | |
| 341 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( | |
| 342 file_writer.string(), directory[5].Location)); | |
| 343 } | |
| 344 | |
| 345 TEST(MinidumpFileWriter, InitializeFromSnapshot_CrashpadInfo) { | |
| 346 const uint32_t kSnapshotTime = 0x15393bd3; | |
| 347 const timeval kSnapshotTimeval = { implicit_cast<time_t>(kSnapshotTime), 0 }; | |
| 348 | |
| 349 TestProcessSnapshot process_snapshot; | |
| 350 process_snapshot.SetSnapshotTime(kSnapshotTimeval); | |
| 351 | |
| 352 auto system_snapshot = make_scoped_ptr(new TestSystemSnapshot()); | |
| 353 system_snapshot->SetCPUArchitecture(kCPUArchitectureX86_64); | |
| 354 system_snapshot->SetOperatingSystem(SystemSnapshot::kOperatingSystemMacOSX); | |
| 355 process_snapshot.SetSystem(system_snapshot.Pass()); | |
| 356 | |
| 357 auto thread_snapshot = make_scoped_ptr(new TestThreadSnapshot()); | |
| 358 InitializeCPUContextX86_64(thread_snapshot->MutableContext(), 5); | |
| 359 process_snapshot.AddThread(thread_snapshot.Pass()); | |
| 360 | |
| 361 auto exception_snapshot = make_scoped_ptr(new TestExceptionSnapshot()); | |
| 362 InitializeCPUContextX86_64(exception_snapshot->MutableContext(), 11); | |
| 363 process_snapshot.SetException(exception_snapshot.Pass()); | |
| 364 | |
| 365 // The module needs an annotation for the MinidumpCrashpadInfo stream to be | |
|
Robert Sesek
2014/11/07 17:07:47
May want to test a !IsUseful() module, too.
| |
| 366 // considered useful and be included. | |
| 367 auto module_snapshot = make_scoped_ptr(new TestModuleSnapshot()); | |
| 368 std::vector<std::string> annotations_list(1, std::string("annotation")); | |
| 369 module_snapshot->SetAnnotationsVector(annotations_list); | |
| 370 process_snapshot.AddModule(module_snapshot.Pass()); | |
| 371 | |
| 372 MinidumpFileWriter minidump_file_writer; | |
| 373 minidump_file_writer.InitializeFromSnapshot(&process_snapshot); | |
| 374 | |
| 375 StringFileWriter file_writer; | |
| 376 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | |
| 377 | |
| 378 const MINIDUMP_DIRECTORY* directory; | |
| 379 const MINIDUMP_HEADER* header = | |
| 380 MinidumpHeaderAtStart(file_writer.string(), &directory); | |
| 381 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 7, kSnapshotTime)); | |
| 382 ASSERT_TRUE(directory); | |
| 383 | |
| 384 EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType); | |
| 385 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>( | |
| 386 file_writer.string(), directory[0].Location)); | |
| 387 | |
| 388 EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType); | |
| 389 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>( | |
| 390 file_writer.string(), directory[1].Location)); | |
| 391 | |
| 392 EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType); | |
| 393 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>( | |
| 394 file_writer.string(), directory[2].Location)); | |
| 395 | |
| 396 EXPECT_EQ(kMinidumpStreamTypeException, directory[3].StreamType); | |
| 397 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_EXCEPTION_STREAM>( | |
| 398 file_writer.string(), directory[3].Location)); | |
| 399 | |
| 400 EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[4].StreamType); | |
| 401 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>( | |
| 402 file_writer.string(), directory[4].Location)); | |
| 403 | |
| 404 EXPECT_EQ(kMinidumpStreamTypeCrashpadInfo, directory[5].StreamType); | |
| 405 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MinidumpCrashpadInfo>( | |
| 406 file_writer.string(), directory[5].Location)); | |
| 407 | |
| 408 EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[6].StreamType); | |
| 409 EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( | |
| 410 file_writer.string(), directory[6].Location)); | |
| 411 } | |
| 412 | |
| 235 TEST(MinidumpFileWriterDeathTest, SameStreamType) { | 413 TEST(MinidumpFileWriterDeathTest, SameStreamType) { |
| 236 MinidumpFileWriter minidump_file; | 414 MinidumpFileWriter minidump_file; |
| 237 | 415 |
| 238 const size_t kStream0Size = 5; | 416 const size_t kStream0Size = 5; |
| 239 const MinidumpStreamType kStream0Type = static_cast<MinidumpStreamType>(0x4d); | 417 const MinidumpStreamType kStream0Type = static_cast<MinidumpStreamType>(0x4d); |
| 240 const uint8_t kStream0Value = 0x5a; | 418 const uint8_t kStream0Value = 0x5a; |
| 241 auto stream0 = make_scoped_ptr( | 419 auto stream0 = make_scoped_ptr( |
| 242 new TestStream(kStream0Type, kStream0Size, kStream0Value)); | 420 new TestStream(kStream0Type, kStream0Size, kStream0Value)); |
| 243 minidump_file.AddStream(stream0.Pass()); | 421 minidump_file.AddStream(stream0.Pass()); |
| 244 | 422 |
| 245 // It is an error to add a second stream of the same type. | 423 // It is an error to add a second stream of the same type. |
| 246 const size_t kStream1Size = 3; | 424 const size_t kStream1Size = 3; |
| 247 const MinidumpStreamType kStream1Type = static_cast<MinidumpStreamType>(0x4d); | 425 const MinidumpStreamType kStream1Type = static_cast<MinidumpStreamType>(0x4d); |
| 248 const uint8_t kStream1Value = 0xa5; | 426 const uint8_t kStream1Value = 0xa5; |
| 249 auto stream1 = make_scoped_ptr( | 427 auto stream1 = make_scoped_ptr( |
| 250 new TestStream(kStream1Type, kStream1Size, kStream1Value)); | 428 new TestStream(kStream1Type, kStream1Size, kStream1Value)); |
| 251 ASSERT_DEATH(minidump_file.AddStream(stream1.Pass()), "already present"); | 429 ASSERT_DEATH(minidump_file.AddStream(stream1.Pass()), "already present"); |
| 252 } | 430 } |
| 253 | 431 |
| 254 } // namespace | 432 } // namespace |
| 255 } // namespace test | 433 } // namespace test |
| 256 } // namespace crashpad | 434 } // namespace crashpad |
| OLD | NEW |