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

Side by Side Diff: minidump/minidump_crashpad_module_writer_test.cc

Issue 675803002: Add MinidumpCrashpadModule, its list form, their writers, and their tests (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Update for https://codereview.chromium.org/679443002/ Created 6 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_crashpad_module_writer.cc ('k') | minidump/minidump_extensions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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_crashpad_module_writer.h"
16
17 #include <dbghelp.h>
18
19 #include "gtest/gtest.h"
20 #include "minidump/minidump_extensions.h"
21 #include "minidump/minidump_simple_string_dictionary_writer.h"
22 #include "minidump/test/minidump_file_writer_test_util.h"
23 #include "minidump/test/minidump_string_writer_test_util.h"
24 #include "minidump/test/minidump_writable_test_util.h"
25 #include "util/file/string_file_writer.h"
26
27 namespace crashpad {
28 namespace test {
29 namespace {
30
31 const MinidumpModuleCrashpadInfoList* MinidumpModuleCrashpadInfoListAtStart(
32 const std::string& file_contents,
33 size_t count) {
34 MINIDUMP_LOCATION_DESCRIPTOR location_descriptor;
35 location_descriptor.DataSize = sizeof(MinidumpModuleCrashpadInfoList) +
36 count * sizeof(MINIDUMP_LOCATION_DESCRIPTOR);
37 location_descriptor.Rva = 0;
38 return MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfoList>(
39 file_contents, location_descriptor);
40 }
41
42 TEST(MinidumpModuleCrashpadInfoWriter, EmptyList) {
43 StringFileWriter file_writer;
44
45 MinidumpModuleCrashpadInfoListWriter module_list_writer;
46
47 EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer));
48 ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList),
49 file_writer.string().size());
50
51 const MinidumpModuleCrashpadInfoList* module_list =
52 MinidumpModuleCrashpadInfoListAtStart(file_writer.string(), 0);
53 ASSERT_TRUE(module_list);
54
55 EXPECT_EQ(0u, module_list->count);
56 }
57
58 TEST(MinidumpModuleCrashpadInfoWriter, EmptyModule) {
59 StringFileWriter file_writer;
60
61 MinidumpModuleCrashpadInfoListWriter module_list_writer;
62 MinidumpModuleCrashpadInfoWriter module_writer;
63 module_list_writer.AddModule(&module_writer);
64
65 EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer));
66 ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList) +
67 sizeof(MINIDUMP_LOCATION_DESCRIPTOR) +
68 sizeof(MinidumpModuleCrashpadInfo),
69 file_writer.string().size());
70
71 const MinidumpModuleCrashpadInfoList* module_list =
72 MinidumpModuleCrashpadInfoListAtStart(file_writer.string(), 1);
73 ASSERT_TRUE(module_list);
74
75 ASSERT_EQ(1u, module_list->count);
76
77 const MinidumpModuleCrashpadInfo* module =
78 MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
79 file_writer.string(), module_list->modules[0]);
80 ASSERT_TRUE(module);
81
82 EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module->version);
83 EXPECT_EQ(0u, module->minidump_module_list_index);
84 EXPECT_EQ(0u, module->simple_annotations.DataSize);
85 EXPECT_EQ(0u, module->simple_annotations.Rva);
86 }
87
88 TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
89 const uint32_t kMinidumpModuleListIndex = 1;
90 const char kKey[] = "key";
91 const char kValue[] = "value";
92
93 StringFileWriter file_writer;
94
95 MinidumpModuleCrashpadInfoListWriter module_list_writer;
96
97 MinidumpModuleCrashpadInfoWriter module_writer;
98 module_writer.SetMinidumpModuleListIndex(kMinidumpModuleListIndex);
99 MinidumpSimpleStringDictionaryWriter simple_string_dictionary_writer;
100 MinidumpSimpleStringDictionaryEntryWriter
101 simple_string_dictionary_entry_writer;
102 simple_string_dictionary_entry_writer.SetKeyValue(kKey, kValue);
103 simple_string_dictionary_writer.AddEntry(
104 &simple_string_dictionary_entry_writer);
105 module_writer.SetSimpleAnnotations(&simple_string_dictionary_writer);
106 module_list_writer.AddModule(&module_writer);
107
108 EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer));
109 ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList) +
110 sizeof(MINIDUMP_LOCATION_DESCRIPTOR) +
111 sizeof(MinidumpModuleCrashpadInfo) +
112 sizeof(MinidumpSimpleStringDictionary) +
113 sizeof(MinidumpSimpleStringDictionaryEntry) +
114 sizeof(MinidumpUTF8String) + arraysize(kKey) +
115 sizeof(MinidumpUTF8String) + arraysize(kValue),
116 file_writer.string().size());
117
118 const MinidumpModuleCrashpadInfoList* module_list =
119 MinidumpModuleCrashpadInfoListAtStart(file_writer.string(), 1);
120 ASSERT_TRUE(module_list);
121
122 ASSERT_EQ(1u, module_list->count);
123
124 const MinidumpModuleCrashpadInfo* module =
125 MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
126 file_writer.string(), module_list->modules[0]);
127 ASSERT_TRUE(module);
128
129 EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module->version);
130 EXPECT_EQ(kMinidumpModuleListIndex, module->minidump_module_list_index);
131 EXPECT_NE(0u, module->simple_annotations.DataSize);
132 EXPECT_NE(0u, module->simple_annotations.Rva);
133
134 const MinidumpSimpleStringDictionary* simple_annotations =
135 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
136 file_writer.string(), module->simple_annotations);
137 ASSERT_TRUE(simple_annotations);
138
139 ASSERT_EQ(1u, simple_annotations->count);
140 EXPECT_EQ(kKey,
141 MinidumpUTF8StringAtRVAAsString(
142 file_writer.string(), simple_annotations->entries[0].key));
143 EXPECT_EQ(kValue,
144 MinidumpUTF8StringAtRVAAsString(
145 file_writer.string(), simple_annotations->entries[0].value));
146 }
147
148 TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
149 const uint32_t kMinidumpModuleListIndex0 = 0;
150 const char kKey0[] = "key";
151 const char kValue0[] = "value";
152 const uint32_t kMinidumpModuleListIndex1 = 2;
153 const uint32_t kMinidumpModuleListIndex2 = 5;
154 const char kKey2A[] = "K";
155 const char kValue2A[] = "VVV";
156 const char kKey2B[] = "river";
157 const char kValue2B[] = "hudson";
158
159 StringFileWriter file_writer;
160
161 MinidumpModuleCrashpadInfoListWriter module_list_writer;
162
163 MinidumpModuleCrashpadInfoWriter module_writer_0;
164 module_writer_0.SetMinidumpModuleListIndex(kMinidumpModuleListIndex0);
165 MinidumpSimpleStringDictionaryWriter simple_string_dictionary_writer_0;
166 MinidumpSimpleStringDictionaryEntryWriter
167 simple_string_dictionary_entry_writer_0;
168 simple_string_dictionary_entry_writer_0.SetKeyValue(kKey0, kValue0);
169 simple_string_dictionary_writer_0.AddEntry(
170 &simple_string_dictionary_entry_writer_0);
171 module_writer_0.SetSimpleAnnotations(&simple_string_dictionary_writer_0);
172 module_list_writer.AddModule(&module_writer_0);
173
174 MinidumpModuleCrashpadInfoWriter module_writer_1;
175 module_writer_1.SetMinidumpModuleListIndex(kMinidumpModuleListIndex1);
176 module_list_writer.AddModule(&module_writer_1);
177
178 MinidumpModuleCrashpadInfoWriter module_writer_2;
179 module_writer_2.SetMinidumpModuleListIndex(kMinidumpModuleListIndex2);
180 MinidumpSimpleStringDictionaryWriter simple_string_dictionary_writer_2;
181 MinidumpSimpleStringDictionaryEntryWriter
182 simple_string_dictionary_entry_writer_2a;
183 simple_string_dictionary_entry_writer_2a.SetKeyValue(kKey2A, kValue2A);
184 simple_string_dictionary_writer_2.AddEntry(
185 &simple_string_dictionary_entry_writer_2a);
186 MinidumpSimpleStringDictionaryEntryWriter
187 simple_string_dictionary_entry_writer_2b;
188 simple_string_dictionary_entry_writer_2b.SetKeyValue(kKey2B, kValue2B);
189 simple_string_dictionary_writer_2.AddEntry(
190 &simple_string_dictionary_entry_writer_2b);
191 module_writer_2.SetSimpleAnnotations(&simple_string_dictionary_writer_2);
192 module_list_writer.AddModule(&module_writer_2);
193
194 EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer));
195
196 const MinidumpModuleCrashpadInfoList* module_list =
197 MinidumpModuleCrashpadInfoListAtStart(file_writer.string(), 3);
198 ASSERT_TRUE(module_list);
199
200 ASSERT_EQ(3u, module_list->count);
201
202 const MinidumpModuleCrashpadInfo* module_0 =
203 MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
204 file_writer.string(), module_list->modules[0]);
205 ASSERT_TRUE(module_0);
206
207 EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_0->version);
208 EXPECT_EQ(kMinidumpModuleListIndex0, module_0->minidump_module_list_index);
209
210 const MinidumpSimpleStringDictionary* simple_annotations_0 =
211 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
212 file_writer.string(), module_0->simple_annotations);
213 ASSERT_TRUE(simple_annotations_0);
214
215 ASSERT_EQ(1u, simple_annotations_0->count);
216 EXPECT_EQ(kKey0,
217 MinidumpUTF8StringAtRVAAsString(
218 file_writer.string(), simple_annotations_0->entries[0].key));
219 EXPECT_EQ(kValue0,
220 MinidumpUTF8StringAtRVAAsString(
221 file_writer.string(), simple_annotations_0->entries[0].value));
222
223 const MinidumpModuleCrashpadInfo* module_1 =
224 MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
225 file_writer.string(), module_list->modules[1]);
226 ASSERT_TRUE(module_1);
227
228 EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_1->version);
229 EXPECT_EQ(kMinidumpModuleListIndex1, module_1->minidump_module_list_index);
230
231 const MinidumpSimpleStringDictionary* simple_annotations_1 =
232 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
233 file_writer.string(), module_1->simple_annotations);
234 EXPECT_FALSE(simple_annotations_1);
235
236 const MinidumpModuleCrashpadInfo* module_2 =
237 MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
238 file_writer.string(), module_list->modules[2]);
239 ASSERT_TRUE(module_2);
240
241 EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_2->version);
242 EXPECT_EQ(kMinidumpModuleListIndex2, module_2->minidump_module_list_index);
243
244 const MinidumpSimpleStringDictionary* simple_annotations_2 =
245 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
246 file_writer.string(), module_2->simple_annotations);
247 ASSERT_TRUE(simple_annotations_2);
248
249 ASSERT_EQ(2u, simple_annotations_2->count);
250 EXPECT_EQ(kKey2A,
251 MinidumpUTF8StringAtRVAAsString(
252 file_writer.string(), simple_annotations_2->entries[0].key));
253 EXPECT_EQ(kValue2A,
254 MinidumpUTF8StringAtRVAAsString(
255 file_writer.string(), simple_annotations_2->entries[0].value));
256 EXPECT_EQ(kKey2B,
257 MinidumpUTF8StringAtRVAAsString(
258 file_writer.string(), simple_annotations_2->entries[1].key));
259 EXPECT_EQ(kValue2B,
260 MinidumpUTF8StringAtRVAAsString(
261 file_writer.string(), simple_annotations_2->entries[1].value));
262 }
263
264 } // namespace
265 } // namespace test
266 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_crashpad_module_writer.cc ('k') | minidump/minidump_extensions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698