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

Side by Side Diff: minidump/minidump_memory_info_writer_test.cc

Issue 1379873005: win: Write memory map info as MINIDUMP_MEMORY_INFO[_LIST] (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@save-peb-more-2
Patch Set: typo Created 5 years, 2 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
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "minidump/minidump_memory_info_writer.h"
16
17 #include <string>
18
19 #include "gtest/gtest.h"
20 #include "minidump/minidump_file_writer.h"
21 #include "minidump/test/minidump_file_writer_test_util.h"
22 #include "minidump/test/minidump_writable_test_util.h"
23 #include "snapshot/test/test_memory_map_region_snapshot.h"
24 #include "util/file/string_file.h"
25
26 namespace crashpad {
27 namespace test {
28 namespace {
29
30 const MinidumpStreamType kBogusStreamType =
Mark Mentovai 2015/10/12 14:34:47 This never comes into play, you can get rid of eve
scottmg 2015/10/13 19:51:29 Done.
31 static_cast<MinidumpStreamType>(1234);
32
33 // expected_streams is the expected number of streams in the file. The memory
34 // info list must be the last stream. If there is another stream, it must come
35 // first, have stream type kBogusStreamType, and have zero-length data.
36 void GetMemoryInfoListStream(const std::string& file_contents,
37 const MINIDUMP_MEMORY_INFO_LIST** memory_info_list,
38 const uint32_t expected_streams) {
39 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
40 const size_t kMemoryInfoListStreamOffset =
41 kDirectoryOffset + expected_streams * sizeof(MINIDUMP_DIRECTORY);
42
43 const MINIDUMP_DIRECTORY* directory;
44 const MINIDUMP_HEADER* header =
45 MinidumpHeaderAtStart(file_contents, &directory);
46 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, expected_streams, 0));
47 ASSERT_TRUE(directory);
48
49 size_t directory_index = 0;
50 if (expected_streams > 1) {
51 ASSERT_EQ(kBogusStreamType, directory[directory_index].StreamType);
52 ASSERT_EQ(0u, directory[directory_index].Location.DataSize);
53 ASSERT_EQ(kMemoryInfoListStreamOffset,
54 directory[directory_index].Location.Rva);
55 ++directory_index;
56 }
57
58 ASSERT_EQ(kMinidumpStreamTypeMemoryInfoList,
59 directory[directory_index].StreamType);
60 EXPECT_EQ(kMemoryInfoListStreamOffset,
61 directory[directory_index].Location.Rva);
62
63 *memory_info_list =
64 MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_INFO_LIST>(
65 file_contents, directory[directory_index].Location);
66 ASSERT_TRUE(memory_info_list);
67 }
68
69 TEST(MinidumpMemoryInfoWriter, Empty) {
70 MinidumpFileWriter minidump_file_writer;
71 auto memory_info_list_writer =
72 make_scoped_ptr(new MinidumpMemoryInfoListWriter());
73 minidump_file_writer.AddStream(memory_info_list_writer.Pass());
74
75 StringFile string_file;
76 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
77
78 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
79 sizeof(MINIDUMP_MEMORY_INFO_LIST),
80 string_file.string().size());
81
82 const MINIDUMP_MEMORY_INFO_LIST* memory_info_list = nullptr;
83 ASSERT_NO_FATAL_FAILURE(
84 GetMemoryInfoListStream(string_file.string(), &memory_info_list, 1));
85
86 EXPECT_EQ(0u, memory_info_list->NumberOfEntries);
87 }
88
89 TEST(MinidumpMemoryInfoWriter, OneRegion) {
90 MinidumpFileWriter minidump_file_writer;
91 auto memory_info_list_writer =
92 make_scoped_ptr(new MinidumpMemoryInfoListWriter());
93
94 auto memory_map_region = make_scoped_ptr(new TestMemoryMapRegionSnapshot());
95
96 MINIDUMP_MEMORY_INFO mmi = {0};
97 mmi.BaseAddress = 0x12340000;
98 mmi.AllocationBase = 0x12000000;
99 mmi.AllocationProtect = PAGE_READWRITE;
100 mmi.RegionSize = 0x6000;
101 mmi.State = MEM_COMMIT;
102 mmi.Protect = PAGE_NOACCESS;
103 mmi.Type = MEM_PRIVATE;
104 memory_map_region->SetMindumpMemoryInfo(mmi);
105
106 std::vector<const MemoryMapRegionSnapshot*> memory_map;
107 memory_map.push_back(memory_map_region.get());
108 memory_info_list_writer->InitializeFromSnapshot(memory_map);
109
110 minidump_file_writer.AddStream(memory_info_list_writer.Pass());
111
112 StringFile string_file;
113 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
114
115 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
116 sizeof(MINIDUMP_MEMORY_INFO_LIST) +
117 sizeof(MINIDUMP_MEMORY_INFO),
118 string_file.string().size());
119
120 const MINIDUMP_MEMORY_INFO_LIST* memory_info_list = nullptr;
121 ASSERT_NO_FATAL_FAILURE(
122 GetMemoryInfoListStream(string_file.string(), &memory_info_list, 1));
123
124 EXPECT_EQ(1u, memory_info_list->NumberOfEntries);
125 const MINIDUMP_MEMORY_INFO* memory_info =
126 reinterpret_cast<const MINIDUMP_MEMORY_INFO*>(&memory_info_list[1]);
127 EXPECT_EQ(mmi.BaseAddress, memory_info->BaseAddress);
128 EXPECT_EQ(mmi.AllocationBase, memory_info->AllocationBase);
129 EXPECT_EQ(mmi.AllocationProtect, memory_info->AllocationProtect);
130 EXPECT_EQ(mmi.RegionSize, memory_info->RegionSize);
131 EXPECT_EQ(mmi.State, memory_info->State);
132 EXPECT_EQ(mmi.Protect, memory_info->Protect);
133 EXPECT_EQ(mmi.Type, memory_info->Type);
134 }
135
136 } // namespace
137 } // namespace test
138 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698