OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 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_memory_info_writer.h" | 15 #include "minidump/minidump_memory_info_writer.h" |
16 | 16 |
17 #include <string> | 17 #include <string> |
| 18 #include <utility> |
18 | 19 |
19 #include "gtest/gtest.h" | 20 #include "gtest/gtest.h" |
20 #include "minidump/minidump_file_writer.h" | 21 #include "minidump/minidump_file_writer.h" |
21 #include "minidump/test/minidump_file_writer_test_util.h" | 22 #include "minidump/test/minidump_file_writer_test_util.h" |
22 #include "minidump/test/minidump_writable_test_util.h" | 23 #include "minidump/test/minidump_writable_test_util.h" |
23 #include "snapshot/test/test_memory_map_region_snapshot.h" | 24 #include "snapshot/test/test_memory_map_region_snapshot.h" |
24 #include "util/file/string_file.h" | 25 #include "util/file/string_file.h" |
25 #include "util/stdlib/move.h" | |
26 | 26 |
27 namespace crashpad { | 27 namespace crashpad { |
28 namespace test { | 28 namespace test { |
29 namespace { | 29 namespace { |
30 | 30 |
31 // The memory info list is expected to be the only stream. | 31 // The memory info list is expected to be the only stream. |
32 void GetMemoryInfoListStream( | 32 void GetMemoryInfoListStream( |
33 const std::string& file_contents, | 33 const std::string& file_contents, |
34 const MINIDUMP_MEMORY_INFO_LIST** memory_info_list) { | 34 const MINIDUMP_MEMORY_INFO_LIST** memory_info_list) { |
35 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 35 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
(...skipping 16 matching lines...) Expand all Loading... |
52 *memory_info_list = | 52 *memory_info_list = |
53 MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_INFO_LIST>( | 53 MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_INFO_LIST>( |
54 file_contents, directory[kDirectoryIndex].Location); | 54 file_contents, directory[kDirectoryIndex].Location); |
55 ASSERT_TRUE(*memory_info_list); | 55 ASSERT_TRUE(*memory_info_list); |
56 } | 56 } |
57 | 57 |
58 TEST(MinidumpMemoryInfoWriter, Empty) { | 58 TEST(MinidumpMemoryInfoWriter, Empty) { |
59 MinidumpFileWriter minidump_file_writer; | 59 MinidumpFileWriter minidump_file_writer; |
60 auto memory_info_list_writer = | 60 auto memory_info_list_writer = |
61 make_scoped_ptr(new MinidumpMemoryInfoListWriter()); | 61 make_scoped_ptr(new MinidumpMemoryInfoListWriter()); |
62 minidump_file_writer.AddStream(crashpad::move(memory_info_list_writer)); | 62 minidump_file_writer.AddStream(std::move(memory_info_list_writer)); |
63 | 63 |
64 StringFile string_file; | 64 StringFile string_file; |
65 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 65 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
66 | 66 |
67 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 67 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
68 sizeof(MINIDUMP_MEMORY_INFO_LIST), | 68 sizeof(MINIDUMP_MEMORY_INFO_LIST), |
69 string_file.string().size()); | 69 string_file.string().size()); |
70 | 70 |
71 const MINIDUMP_MEMORY_INFO_LIST* memory_info_list = nullptr; | 71 const MINIDUMP_MEMORY_INFO_LIST* memory_info_list = nullptr; |
72 ASSERT_NO_FATAL_FAILURE( | 72 ASSERT_NO_FATAL_FAILURE( |
(...skipping 16 matching lines...) Expand all Loading... |
89 mmi.RegionSize = 0x6000; | 89 mmi.RegionSize = 0x6000; |
90 mmi.State = MEM_COMMIT; | 90 mmi.State = MEM_COMMIT; |
91 mmi.Protect = PAGE_NOACCESS; | 91 mmi.Protect = PAGE_NOACCESS; |
92 mmi.Type = MEM_PRIVATE; | 92 mmi.Type = MEM_PRIVATE; |
93 memory_map_region->SetMindumpMemoryInfo(mmi); | 93 memory_map_region->SetMindumpMemoryInfo(mmi); |
94 | 94 |
95 std::vector<const MemoryMapRegionSnapshot*> memory_map; | 95 std::vector<const MemoryMapRegionSnapshot*> memory_map; |
96 memory_map.push_back(memory_map_region.get()); | 96 memory_map.push_back(memory_map_region.get()); |
97 memory_info_list_writer->InitializeFromSnapshot(memory_map); | 97 memory_info_list_writer->InitializeFromSnapshot(memory_map); |
98 | 98 |
99 minidump_file_writer.AddStream(crashpad::move(memory_info_list_writer)); | 99 minidump_file_writer.AddStream(std::move(memory_info_list_writer)); |
100 | 100 |
101 StringFile string_file; | 101 StringFile string_file; |
102 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 102 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
103 | 103 |
104 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 104 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
105 sizeof(MINIDUMP_MEMORY_INFO_LIST) + | 105 sizeof(MINIDUMP_MEMORY_INFO_LIST) + |
106 sizeof(MINIDUMP_MEMORY_INFO), | 106 sizeof(MINIDUMP_MEMORY_INFO), |
107 string_file.string().size()); | 107 string_file.string().size()); |
108 | 108 |
109 const MINIDUMP_MEMORY_INFO_LIST* memory_info_list = nullptr; | 109 const MINIDUMP_MEMORY_INFO_LIST* memory_info_list = nullptr; |
110 ASSERT_NO_FATAL_FAILURE( | 110 ASSERT_NO_FATAL_FAILURE( |
111 GetMemoryInfoListStream(string_file.string(), &memory_info_list)); | 111 GetMemoryInfoListStream(string_file.string(), &memory_info_list)); |
112 | 112 |
113 EXPECT_EQ(1u, memory_info_list->NumberOfEntries); | 113 EXPECT_EQ(1u, memory_info_list->NumberOfEntries); |
114 const MINIDUMP_MEMORY_INFO* memory_info = | 114 const MINIDUMP_MEMORY_INFO* memory_info = |
115 reinterpret_cast<const MINIDUMP_MEMORY_INFO*>(&memory_info_list[1]); | 115 reinterpret_cast<const MINIDUMP_MEMORY_INFO*>(&memory_info_list[1]); |
116 EXPECT_EQ(mmi.BaseAddress, memory_info->BaseAddress); | 116 EXPECT_EQ(mmi.BaseAddress, memory_info->BaseAddress); |
117 EXPECT_EQ(mmi.AllocationBase, memory_info->AllocationBase); | 117 EXPECT_EQ(mmi.AllocationBase, memory_info->AllocationBase); |
118 EXPECT_EQ(mmi.AllocationProtect, memory_info->AllocationProtect); | 118 EXPECT_EQ(mmi.AllocationProtect, memory_info->AllocationProtect); |
119 EXPECT_EQ(mmi.RegionSize, memory_info->RegionSize); | 119 EXPECT_EQ(mmi.RegionSize, memory_info->RegionSize); |
120 EXPECT_EQ(mmi.State, memory_info->State); | 120 EXPECT_EQ(mmi.State, memory_info->State); |
121 EXPECT_EQ(mmi.Protect, memory_info->Protect); | 121 EXPECT_EQ(mmi.Protect, memory_info->Protect); |
122 EXPECT_EQ(mmi.Type, memory_info->Type); | 122 EXPECT_EQ(mmi.Type, memory_info->Type); |
123 } | 123 } |
124 | 124 |
125 } // namespace | 125 } // namespace |
126 } // namespace test | 126 } // namespace test |
127 } // namespace crashpad | 127 } // namespace crashpad |
OLD | NEW |