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_module_writer.h" | 15 #include "minidump/minidump_module_writer.h" |
16 | 16 |
17 #include <dbghelp.h> | 17 #include <dbghelp.h> |
18 #include <stdint.h> | 18 #include <stdint.h> |
19 #include <string.h> | 19 #include <string.h> |
20 #include <sys/types.h> | 20 #include <sys/types.h> |
21 | 21 |
22 #include "base/strings/stringprintf.h" | |
22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
23 #include "gtest/gtest.h" | 24 #include "gtest/gtest.h" |
24 #include "minidump/minidump_extensions.h" | 25 #include "minidump/minidump_extensions.h" |
25 #include "minidump/minidump_file_writer.h" | 26 #include "minidump/minidump_file_writer.h" |
26 #include "minidump/test/minidump_file_writer_test_util.h" | 27 #include "minidump/test/minidump_file_writer_test_util.h" |
27 #include "minidump/test/minidump_string_writer_test_util.h" | 28 #include "minidump/test/minidump_string_writer_test_util.h" |
28 #include "minidump/test/minidump_writable_test_util.h" | 29 #include "minidump/test/minidump_writable_test_util.h" |
30 #include "snapshot/test/test_module_snapshot.h" | |
29 #include "util/file/string_file_writer.h" | 31 #include "util/file/string_file_writer.h" |
30 #include "util/misc/uuid.h" | 32 #include "util/misc/uuid.h" |
33 #include "util/stdlib/pointer_container.h" | |
31 | 34 |
32 namespace crashpad { | 35 namespace crashpad { |
33 namespace test { | 36 namespace test { |
34 namespace { | 37 namespace { |
35 | 38 |
36 void GetModuleListStream(const std::string& file_contents, | 39 void GetModuleListStream(const std::string& file_contents, |
37 const MINIDUMP_MODULE_LIST** module_list) { | 40 const MINIDUMP_MODULE_LIST** module_list) { |
38 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 41 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
39 const size_t kModuleListStreamOffset = | 42 const size_t kModuleListStreamOffset = |
40 kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); | 43 kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 kPDBName2, | 602 kPDBName2, |
600 nullptr, | 603 nullptr, |
601 kPDBTimestamp2, | 604 kPDBTimestamp2, |
602 kPDBAge2, | 605 kPDBAge2, |
603 nullptr, | 606 nullptr, |
604 0, | 607 0, |
605 false)); | 608 false)); |
606 } | 609 } |
607 } | 610 } |
608 | 611 |
609 TEST(MinidumpSystemInfoWriterDeathTest, NoModuleName) { | 612 void InitializeTestModuleSnapshotFromMinidumpModule( |
613 TestModuleSnapshot* module_snapshot, | |
614 const MINIDUMP_MODULE& minidump_module, | |
615 const std::string& name, | |
616 const crashpad::UUID& uuid) { | |
617 module_snapshot->SetName(name); | |
618 | |
619 module_snapshot->SetAddressAndSize(minidump_module.BaseOfImage, | |
620 minidump_module.SizeOfImage); | |
621 module_snapshot->SetTimestamp(minidump_module.TimeDateStamp); | |
622 module_snapshot->SetFileVersion( | |
623 minidump_module.VersionInfo.dwFileVersionMS >> 16, | |
624 minidump_module.VersionInfo.dwFileVersionMS & 0xffff, | |
625 minidump_module.VersionInfo.dwFileVersionLS >> 16, | |
626 minidump_module.VersionInfo.dwFileVersionLS & 0xffff); | |
627 module_snapshot->SetSourceVersion( | |
628 minidump_module.VersionInfo.dwProductVersionMS >> 16, | |
629 minidump_module.VersionInfo.dwProductVersionMS & 0xffff, | |
630 minidump_module.VersionInfo.dwProductVersionLS >> 16, | |
631 minidump_module.VersionInfo.dwProductVersionLS & 0xffff); | |
632 | |
633 ModuleSnapshot::ModuleType module_type; | |
634 switch (minidump_module.VersionInfo.dwFileType) { | |
635 case VFT_APP: | |
636 module_type = ModuleSnapshot::kModuleTypeExecutable; | |
637 break; | |
638 case VFT_DLL: | |
639 module_type = ModuleSnapshot::kModuleTypeSharedLibrary; | |
640 break; | |
641 default: | |
642 module_type = ModuleSnapshot::kModuleTypeUnknown; | |
643 break; | |
644 } | |
645 module_snapshot->SetModuleType(module_type); | |
646 | |
647 module_snapshot->SetUUID(uuid); | |
648 } | |
649 | |
650 TEST(MinidumpModuleWriter, InitializeFromSnapshot) { | |
651 MINIDUMP_MODULE expect_modules[3] = {}; | |
652 const char* module_paths[3] = {}; | |
653 const char* module_names[3] = {}; | |
654 UUID uuids[3] = {}; | |
Robert Sesek
2014/10/29 15:25:24
This doesn't need crashpad:: ?
Mark Mentovai
2014/10/29 15:35:36
Robert Sesek wrote:
| |
655 | |
656 static_assert(arraysize(expect_modules) == arraysize(module_paths), | |
657 "array sizes must be equal"); | |
658 static_assert(arraysize(expect_modules) == arraysize(module_names), | |
659 "array sizes must be equal"); | |
660 static_assert(arraysize(expect_modules) == arraysize(uuids), | |
661 "array sizes must be equal"); | |
662 | |
663 expect_modules[0].BaseOfImage = 0x100101000; | |
664 expect_modules[0].SizeOfImage = 0xf000; | |
665 expect_modules[0].TimeDateStamp = 0x01234567; | |
666 expect_modules[0].VersionInfo.dwFileVersionMS = 0x00010002; | |
667 expect_modules[0].VersionInfo.dwFileVersionLS = 0x00030004; | |
668 expect_modules[0].VersionInfo.dwProductVersionMS = 0x00050006; | |
669 expect_modules[0].VersionInfo.dwProductVersionLS = 0x00070008; | |
670 expect_modules[0].VersionInfo.dwFileType = VFT_APP; | |
671 module_paths[0] = "/usr/bin/true"; | |
672 module_names[0] = "true"; | |
673 const uint8_t kUUIDBytes0[16] = | |
674 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | |
675 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; | |
676 uuids[0].InitializeFromBytes(kUUIDBytes0); | |
677 | |
678 expect_modules[1].BaseOfImage = 0x200202000; | |
679 expect_modules[1].SizeOfImage = 0x1e1000; | |
680 expect_modules[1].TimeDateStamp = 0x89abcdef; | |
681 expect_modules[1].VersionInfo.dwFileVersionMS = 0x0009000a; | |
682 expect_modules[1].VersionInfo.dwFileVersionLS = 0x000b000c; | |
683 expect_modules[1].VersionInfo.dwProductVersionMS = 0x000d000e; | |
684 expect_modules[1].VersionInfo.dwProductVersionLS = 0x000f0000; | |
685 expect_modules[1].VersionInfo.dwFileType = VFT_DLL; | |
686 module_paths[1] = "/usr/lib/libSystem.B.dylib"; | |
687 module_names[1] = "libSystem.B.dylib"; | |
688 const uint8_t kUUIDBytes1[16] = | |
689 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
690 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; | |
691 uuids[1].InitializeFromBytes(kUUIDBytes1); | |
692 | |
693 expect_modules[2].BaseOfImage = 0x300303000; | |
694 expect_modules[2].SizeOfImage = 0x2d000; | |
695 expect_modules[2].TimeDateStamp = 0x76543210; | |
696 expect_modules[2].VersionInfo.dwFileVersionMS = 0x11112222; | |
697 expect_modules[2].VersionInfo.dwFileVersionLS = 0x33334444; | |
698 expect_modules[2].VersionInfo.dwProductVersionMS = 0x9999aaaa; | |
699 expect_modules[2].VersionInfo.dwProductVersionLS = 0xbbbbcccc; | |
700 expect_modules[2].VersionInfo.dwFileType = VFT_UNKNOWN; | |
701 module_paths[2] = "/usr/lib/dyld"; | |
702 module_names[2] = "dyld"; | |
703 const uint8_t kUUIDBytes2[16] = | |
704 {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, | |
705 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0}; | |
706 uuids[2].InitializeFromBytes(kUUIDBytes2); | |
707 | |
708 PointerVector<TestModuleSnapshot> module_snapshots_owner; | |
709 std::vector<const ModuleSnapshot*> module_snapshots; | |
710 for (size_t index = 0; index < arraysize(expect_modules); ++index) { | |
711 TestModuleSnapshot* module_snapshot = new TestModuleSnapshot(); | |
712 module_snapshots_owner.push_back(module_snapshot); | |
713 InitializeTestModuleSnapshotFromMinidumpModule(module_snapshot, | |
714 expect_modules[index], | |
715 module_paths[index], | |
716 uuids[index]); | |
717 module_snapshots.push_back(module_snapshot); | |
718 } | |
719 | |
720 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); | |
721 module_list_writer->InitializeFromSnapshot(module_snapshots); | |
722 | |
723 MinidumpFileWriter minidump_file_writer; | |
724 minidump_file_writer.AddStream(module_list_writer.Pass()); | |
725 | |
726 StringFileWriter file_writer; | |
727 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | |
728 | |
729 const MINIDUMP_MODULE_LIST* module_list; | |
730 ASSERT_NO_FATAL_FAILURE( | |
731 GetModuleListStream(file_writer.string(), &module_list)); | |
732 | |
733 ASSERT_EQ(3u, module_list->NumberOfModules); | |
734 | |
735 for (size_t index = 0; index < module_list->NumberOfModules; ++index) { | |
736 SCOPED_TRACE(base::StringPrintf("index %zu", index)); | |
737 ASSERT_NO_FATAL_FAILURE(ExpectModule(&expect_modules[index], | |
738 &module_list->Modules[index], | |
739 file_writer.string(), | |
740 module_paths[index], | |
741 module_names[index], | |
742 &uuids[index], | |
743 0, | |
744 0, | |
745 nullptr, | |
746 0, | |
747 false)); | |
748 } | |
749 } | |
750 | |
751 TEST(MinidumpModuleWriterDeathTest, NoModuleName) { | |
610 MinidumpFileWriter minidump_file_writer; | 752 MinidumpFileWriter minidump_file_writer; |
611 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); | 753 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); |
612 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter()); | 754 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter()); |
613 module_list_writer->AddModule(module_writer.Pass()); | 755 module_list_writer->AddModule(module_writer.Pass()); |
614 minidump_file_writer.AddStream(module_list_writer.Pass()); | 756 minidump_file_writer.AddStream(module_list_writer.Pass()); |
615 | 757 |
616 StringFileWriter file_writer; | 758 StringFileWriter file_writer; |
617 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "name_"); | 759 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "name_"); |
618 } | 760 } |
619 | 761 |
620 } // namespace | 762 } // namespace |
621 } // namespace test | 763 } // namespace test |
622 } // namespace crashpad | 764 } // namespace crashpad |
OLD | NEW |