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

Side by Side Diff: minidump/minidump_handle_writer_test.cc

Issue 1411793005: Pool TypeName strings when writing MINIDUMP_HANDLE_DESCRIPTOR (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@handle-write
Patch Set: map-insert 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
« no previous file with comments | « minidump/minidump_handle_writer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 EXPECT_EQ(handle_snapshot.type_name, 115 EXPECT_EQ(handle_snapshot.type_name,
116 base::UTF16ToUTF8(MinidumpStringAtRVAAsString( 116 base::UTF16ToUTF8(MinidumpStringAtRVAAsString(
117 string_file.string(), handle_descriptor->TypeNameRva))); 117 string_file.string(), handle_descriptor->TypeNameRva)));
118 EXPECT_EQ(0u, handle_descriptor->ObjectNameRva); 118 EXPECT_EQ(0u, handle_descriptor->ObjectNameRva);
119 EXPECT_EQ(handle_snapshot.attributes, handle_descriptor->Attributes); 119 EXPECT_EQ(handle_snapshot.attributes, handle_descriptor->Attributes);
120 EXPECT_EQ(handle_snapshot.granted_access, handle_descriptor->GrantedAccess); 120 EXPECT_EQ(handle_snapshot.granted_access, handle_descriptor->GrantedAccess);
121 EXPECT_EQ(handle_snapshot.handle_count, handle_descriptor->HandleCount); 121 EXPECT_EQ(handle_snapshot.handle_count, handle_descriptor->HandleCount);
122 EXPECT_EQ(handle_snapshot.pointer_count, handle_descriptor->PointerCount); 122 EXPECT_EQ(handle_snapshot.pointer_count, handle_descriptor->PointerCount);
123 } 123 }
124 124
125 TEST(MinidumpHandleDataWriter, RepeatedTypeName) {
126 MinidumpFileWriter minidump_file_writer;
127 auto handle_data_writer = make_scoped_ptr(new MinidumpHandleDataWriter());
128
129 HandleSnapshot handle_snapshot;
130 handle_snapshot.handle = 0x1234;
131 handle_snapshot.type_name = "Something";
132 handle_snapshot.attributes = 0x12345678;
133 handle_snapshot.granted_access = 0x9abcdef0;
134 handle_snapshot.pointer_count = 4567;
135 handle_snapshot.handle_count = 9876;
136
137 HandleSnapshot handle_snapshot2;
138 handle_snapshot2.handle = 0x4321;
139 handle_snapshot2.type_name = "Something"; // Note: same as above.
140 handle_snapshot2.attributes = 0x87654321;
141 handle_snapshot2.granted_access = 0x0fedcba9;
142 handle_snapshot2.pointer_count = 7654;
143 handle_snapshot2.handle_count = 6789;
144
145 std::vector<HandleSnapshot> snapshot;
146 snapshot.push_back(handle_snapshot);
147 snapshot.push_back(handle_snapshot2);
148
149 handle_data_writer->InitializeFromSnapshot(snapshot);
150
151 minidump_file_writer.AddStream(handle_data_writer.Pass());
152
153 StringFile string_file;
154 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
155
156 const size_t kTypeNameStringDataLength =
157 (handle_snapshot.type_name.size() + 1) * sizeof(base::char16);
158 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
159 sizeof(MINIDUMP_HANDLE_DATA_STREAM) +
160 (sizeof(MINIDUMP_HANDLE_DESCRIPTOR) * 2) +
161 sizeof(MINIDUMP_STRING) + kTypeNameStringDataLength,
162 string_file.string().size());
163
164 const MINIDUMP_HANDLE_DATA_STREAM* handle_data_stream = nullptr;
165 ASSERT_NO_FATAL_FAILURE(
166 GetHandleDataStream(string_file.string(), &handle_data_stream));
167
168 EXPECT_EQ(2u, handle_data_stream->NumberOfDescriptors);
169 const MINIDUMP_HANDLE_DESCRIPTOR* handle_descriptor =
170 reinterpret_cast<const MINIDUMP_HANDLE_DESCRIPTOR*>(
171 &handle_data_stream[1]);
172 EXPECT_EQ(handle_snapshot.handle, handle_descriptor->Handle);
173 EXPECT_EQ(handle_snapshot.type_name,
174 base::UTF16ToUTF8(MinidumpStringAtRVAAsString(
175 string_file.string(), handle_descriptor->TypeNameRva)));
176 EXPECT_EQ(0u, handle_descriptor->ObjectNameRva);
177 EXPECT_EQ(handle_snapshot.attributes, handle_descriptor->Attributes);
178 EXPECT_EQ(handle_snapshot.granted_access, handle_descriptor->GrantedAccess);
179 EXPECT_EQ(handle_snapshot.handle_count, handle_descriptor->HandleCount);
180 EXPECT_EQ(handle_snapshot.pointer_count, handle_descriptor->PointerCount);
181
182 const MINIDUMP_HANDLE_DESCRIPTOR* handle_descriptor2 =
183 reinterpret_cast<const MINIDUMP_HANDLE_DESCRIPTOR*>(
184 reinterpret_cast<const unsigned char*>(&handle_data_stream[1]) +
185 sizeof(MINIDUMP_HANDLE_DESCRIPTOR));
186 EXPECT_EQ(handle_snapshot2.handle, handle_descriptor2->Handle);
187 EXPECT_EQ(handle_snapshot2.type_name,
188 base::UTF16ToUTF8(MinidumpStringAtRVAAsString(
189 string_file.string(), handle_descriptor2->TypeNameRva)));
190 EXPECT_EQ(0u, handle_descriptor2->ObjectNameRva);
191 EXPECT_EQ(handle_snapshot2.attributes, handle_descriptor2->Attributes);
192 EXPECT_EQ(handle_snapshot2.granted_access, handle_descriptor2->GrantedAccess);
193 EXPECT_EQ(handle_snapshot2.handle_count, handle_descriptor2->HandleCount);
194 EXPECT_EQ(handle_snapshot2.pointer_count, handle_descriptor2->PointerCount);
195
196 EXPECT_EQ(handle_descriptor->TypeNameRva, handle_descriptor2->TypeNameRva);
197 }
198
125 } // namespace 199 } // namespace
126 } // namespace test 200 } // namespace test
127 } // namespace crashpad 201 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_handle_writer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698