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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 nullptr, | 607 nullptr, |
608 0, | 608 0, |
609 false)); | 609 false)); |
610 } | 610 } |
611 } | 611 } |
612 | 612 |
613 void InitializeTestModuleSnapshotFromMinidumpModule( | 613 void InitializeTestModuleSnapshotFromMinidumpModule( |
614 TestModuleSnapshot* module_snapshot, | 614 TestModuleSnapshot* module_snapshot, |
615 const MINIDUMP_MODULE& minidump_module, | 615 const MINIDUMP_MODULE& minidump_module, |
616 const std::string& name, | 616 const std::string& name, |
617 const crashpad::UUID& uuid) { | 617 const crashpad::UUID& uuid, |
| 618 uint32_t age) { |
618 module_snapshot->SetName(name); | 619 module_snapshot->SetName(name); |
619 | 620 |
620 module_snapshot->SetAddressAndSize(minidump_module.BaseOfImage, | 621 module_snapshot->SetAddressAndSize(minidump_module.BaseOfImage, |
621 minidump_module.SizeOfImage); | 622 minidump_module.SizeOfImage); |
622 module_snapshot->SetTimestamp(minidump_module.TimeDateStamp); | 623 module_snapshot->SetTimestamp(minidump_module.TimeDateStamp); |
623 module_snapshot->SetFileVersion( | 624 module_snapshot->SetFileVersion( |
624 minidump_module.VersionInfo.dwFileVersionMS >> 16, | 625 minidump_module.VersionInfo.dwFileVersionMS >> 16, |
625 minidump_module.VersionInfo.dwFileVersionMS & 0xffff, | 626 minidump_module.VersionInfo.dwFileVersionMS & 0xffff, |
626 minidump_module.VersionInfo.dwFileVersionLS >> 16, | 627 minidump_module.VersionInfo.dwFileVersionLS >> 16, |
627 minidump_module.VersionInfo.dwFileVersionLS & 0xffff); | 628 minidump_module.VersionInfo.dwFileVersionLS & 0xffff); |
(...skipping 10 matching lines...) Expand all Loading... |
638 break; | 639 break; |
639 case VFT_DLL: | 640 case VFT_DLL: |
640 module_type = ModuleSnapshot::kModuleTypeSharedLibrary; | 641 module_type = ModuleSnapshot::kModuleTypeSharedLibrary; |
641 break; | 642 break; |
642 default: | 643 default: |
643 module_type = ModuleSnapshot::kModuleTypeUnknown; | 644 module_type = ModuleSnapshot::kModuleTypeUnknown; |
644 break; | 645 break; |
645 } | 646 } |
646 module_snapshot->SetModuleType(module_type); | 647 module_snapshot->SetModuleType(module_type); |
647 | 648 |
648 module_snapshot->SetUUID(uuid); | 649 module_snapshot->SetUUIDAndAge(uuid, age); |
649 } | 650 } |
650 | 651 |
651 TEST(MinidumpModuleWriter, InitializeFromSnapshot) { | 652 TEST(MinidumpModuleWriter, InitializeFromSnapshot) { |
652 MINIDUMP_MODULE expect_modules[3] = {}; | 653 MINIDUMP_MODULE expect_modules[3] = {}; |
653 const char* module_paths[arraysize(expect_modules)] = {}; | 654 const char* module_paths[arraysize(expect_modules)] = {}; |
654 const char* module_names[arraysize(expect_modules)] = {}; | 655 const char* module_names[arraysize(expect_modules)] = {}; |
655 UUID uuids[arraysize(expect_modules)] = {}; | 656 UUID uuids[arraysize(expect_modules)] = {}; |
| 657 uint32_t ages[arraysize(expect_modules)] = {}; |
656 | 658 |
657 expect_modules[0].BaseOfImage = 0x100101000; | 659 expect_modules[0].BaseOfImage = 0x100101000; |
658 expect_modules[0].SizeOfImage = 0xf000; | 660 expect_modules[0].SizeOfImage = 0xf000; |
659 expect_modules[0].TimeDateStamp = 0x01234567; | 661 expect_modules[0].TimeDateStamp = 0x01234567; |
660 expect_modules[0].VersionInfo.dwFileVersionMS = 0x00010002; | 662 expect_modules[0].VersionInfo.dwFileVersionMS = 0x00010002; |
661 expect_modules[0].VersionInfo.dwFileVersionLS = 0x00030004; | 663 expect_modules[0].VersionInfo.dwFileVersionLS = 0x00030004; |
662 expect_modules[0].VersionInfo.dwProductVersionMS = 0x00050006; | 664 expect_modules[0].VersionInfo.dwProductVersionMS = 0x00050006; |
663 expect_modules[0].VersionInfo.dwProductVersionLS = 0x00070008; | 665 expect_modules[0].VersionInfo.dwProductVersionLS = 0x00070008; |
664 expect_modules[0].VersionInfo.dwFileType = VFT_APP; | 666 expect_modules[0].VersionInfo.dwFileType = VFT_APP; |
665 module_paths[0] = "/usr/bin/true"; | 667 module_paths[0] = "/usr/bin/true"; |
666 module_names[0] = "true"; | 668 module_names[0] = "true"; |
667 const uint8_t kUUIDBytes0[16] = | 669 const uint8_t kUUIDBytes0[16] = |
668 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 670 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
669 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; | 671 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; |
670 uuids[0].InitializeFromBytes(kUUIDBytes0); | 672 uuids[0].InitializeFromBytes(kUUIDBytes0); |
| 673 ages[0] = 10; |
671 | 674 |
672 expect_modules[1].BaseOfImage = 0x200202000; | 675 expect_modules[1].BaseOfImage = 0x200202000; |
673 expect_modules[1].SizeOfImage = 0x1e1000; | 676 expect_modules[1].SizeOfImage = 0x1e1000; |
674 expect_modules[1].TimeDateStamp = 0x89abcdef; | 677 expect_modules[1].TimeDateStamp = 0x89abcdef; |
675 expect_modules[1].VersionInfo.dwFileVersionMS = 0x0009000a; | 678 expect_modules[1].VersionInfo.dwFileVersionMS = 0x0009000a; |
676 expect_modules[1].VersionInfo.dwFileVersionLS = 0x000b000c; | 679 expect_modules[1].VersionInfo.dwFileVersionLS = 0x000b000c; |
677 expect_modules[1].VersionInfo.dwProductVersionMS = 0x000d000e; | 680 expect_modules[1].VersionInfo.dwProductVersionMS = 0x000d000e; |
678 expect_modules[1].VersionInfo.dwProductVersionLS = 0x000f0000; | 681 expect_modules[1].VersionInfo.dwProductVersionLS = 0x000f0000; |
679 expect_modules[1].VersionInfo.dwFileType = VFT_DLL; | 682 expect_modules[1].VersionInfo.dwFileType = VFT_DLL; |
680 module_paths[1] = "/usr/lib/libSystem.B.dylib"; | 683 module_paths[1] = "/usr/lib/libSystem.B.dylib"; |
681 module_names[1] = "libSystem.B.dylib"; | 684 module_names[1] = "libSystem.B.dylib"; |
682 const uint8_t kUUIDBytes1[16] = | 685 const uint8_t kUUIDBytes1[16] = |
683 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 686 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
684 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; | 687 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; |
685 uuids[1].InitializeFromBytes(kUUIDBytes1); | 688 uuids[1].InitializeFromBytes(kUUIDBytes1); |
| 689 ages[1] = 20; |
686 | 690 |
687 expect_modules[2].BaseOfImage = 0x300303000; | 691 expect_modules[2].BaseOfImage = 0x300303000; |
688 expect_modules[2].SizeOfImage = 0x2d000; | 692 expect_modules[2].SizeOfImage = 0x2d000; |
689 expect_modules[2].TimeDateStamp = 0x76543210; | 693 expect_modules[2].TimeDateStamp = 0x76543210; |
690 expect_modules[2].VersionInfo.dwFileVersionMS = 0x11112222; | 694 expect_modules[2].VersionInfo.dwFileVersionMS = 0x11112222; |
691 expect_modules[2].VersionInfo.dwFileVersionLS = 0x33334444; | 695 expect_modules[2].VersionInfo.dwFileVersionLS = 0x33334444; |
692 expect_modules[2].VersionInfo.dwProductVersionMS = 0x9999aaaa; | 696 expect_modules[2].VersionInfo.dwProductVersionMS = 0x9999aaaa; |
693 expect_modules[2].VersionInfo.dwProductVersionLS = 0xbbbbcccc; | 697 expect_modules[2].VersionInfo.dwProductVersionLS = 0xbbbbcccc; |
694 expect_modules[2].VersionInfo.dwFileType = VFT_UNKNOWN; | 698 expect_modules[2].VersionInfo.dwFileType = VFT_UNKNOWN; |
695 module_paths[2] = "/usr/lib/dyld"; | 699 module_paths[2] = "/usr/lib/dyld"; |
696 module_names[2] = "dyld"; | 700 module_names[2] = "dyld"; |
697 const uint8_t kUUIDBytes2[16] = | 701 const uint8_t kUUIDBytes2[16] = |
698 {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, | 702 {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, |
699 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0}; | 703 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0}; |
700 uuids[2].InitializeFromBytes(kUUIDBytes2); | 704 uuids[2].InitializeFromBytes(kUUIDBytes2); |
| 705 ages[2] = 30; |
701 | 706 |
702 PointerVector<TestModuleSnapshot> module_snapshots_owner; | 707 PointerVector<TestModuleSnapshot> module_snapshots_owner; |
703 std::vector<const ModuleSnapshot*> module_snapshots; | 708 std::vector<const ModuleSnapshot*> module_snapshots; |
704 for (size_t index = 0; index < arraysize(expect_modules); ++index) { | 709 for (size_t index = 0; index < arraysize(expect_modules); ++index) { |
705 TestModuleSnapshot* module_snapshot = new TestModuleSnapshot(); | 710 TestModuleSnapshot* module_snapshot = new TestModuleSnapshot(); |
706 module_snapshots_owner.push_back(module_snapshot); | 711 module_snapshots_owner.push_back(module_snapshot); |
707 InitializeTestModuleSnapshotFromMinidumpModule(module_snapshot, | 712 InitializeTestModuleSnapshotFromMinidumpModule(module_snapshot, |
708 expect_modules[index], | 713 expect_modules[index], |
709 module_paths[index], | 714 module_paths[index], |
710 uuids[index]); | 715 uuids[index], |
| 716 ages[index]); |
711 module_snapshots.push_back(module_snapshot); | 717 module_snapshots.push_back(module_snapshot); |
712 } | 718 } |
713 | 719 |
714 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); | 720 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); |
715 module_list_writer->InitializeFromSnapshot(module_snapshots); | 721 module_list_writer->InitializeFromSnapshot(module_snapshots); |
716 | 722 |
717 MinidumpFileWriter minidump_file_writer; | 723 MinidumpFileWriter minidump_file_writer; |
718 minidump_file_writer.AddStream(module_list_writer.Pass()); | 724 minidump_file_writer.AddStream(module_list_writer.Pass()); |
719 | 725 |
720 StringFile string_file; | 726 StringFile string_file; |
721 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 727 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
722 | 728 |
723 const MINIDUMP_MODULE_LIST* module_list = nullptr; | 729 const MINIDUMP_MODULE_LIST* module_list = nullptr; |
724 ASSERT_NO_FATAL_FAILURE( | 730 ASSERT_NO_FATAL_FAILURE( |
725 GetModuleListStream(string_file.string(), &module_list)); | 731 GetModuleListStream(string_file.string(), &module_list)); |
726 | 732 |
727 ASSERT_EQ(3u, module_list->NumberOfModules); | 733 ASSERT_EQ(3u, module_list->NumberOfModules); |
728 | 734 |
729 for (size_t index = 0; index < module_list->NumberOfModules; ++index) { | 735 for (size_t index = 0; index < module_list->NumberOfModules; ++index) { |
730 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); | 736 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); |
731 ASSERT_NO_FATAL_FAILURE(ExpectModule(&expect_modules[index], | 737 ASSERT_NO_FATAL_FAILURE(ExpectModule(&expect_modules[index], |
732 &module_list->Modules[index], | 738 &module_list->Modules[index], |
733 string_file.string(), | 739 string_file.string(), |
734 module_paths[index], | 740 module_paths[index], |
735 module_names[index], | 741 module_names[index], |
736 &uuids[index], | 742 &uuids[index], |
737 0, | 743 0, |
738 0, | 744 ages[index], |
739 nullptr, | 745 nullptr, |
740 0, | 746 0, |
741 false)); | 747 false)); |
742 } | 748 } |
743 } | 749 } |
744 | 750 |
745 TEST(MinidumpModuleWriterDeathTest, NoModuleName) { | 751 TEST(MinidumpModuleWriterDeathTest, NoModuleName) { |
746 MinidumpFileWriter minidump_file_writer; | 752 MinidumpFileWriter minidump_file_writer; |
747 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); | 753 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); |
748 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter()); | 754 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter()); |
749 module_list_writer->AddModule(module_writer.Pass()); | 755 module_list_writer->AddModule(module_writer.Pass()); |
750 minidump_file_writer.AddStream(module_list_writer.Pass()); | 756 minidump_file_writer.AddStream(module_list_writer.Pass()); |
751 | 757 |
752 StringFile string_file; | 758 StringFile string_file; |
753 ASSERT_DEATH_CHECK(minidump_file_writer.WriteEverything(&string_file), | 759 ASSERT_DEATH_CHECK(minidump_file_writer.WriteEverything(&string_file), |
754 "name_"); | 760 "name_"); |
755 } | 761 } |
756 | 762 |
757 } // namespace | 763 } // namespace |
758 } // namespace test | 764 } // namespace test |
759 } // namespace crashpad | 765 } // namespace crashpad |
OLD | NEW |