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

Side by Side Diff: minidump/minidump_misc_info_writer_test.cc

Issue 674153002: minidump: Change the ownership model (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 6 years, 1 month 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_misc_info_writer.cc ('k') | minidump/minidump_module_crashpad_info_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_misc_info_writer.h" 15 #include "minidump/minidump_misc_info_writer.h"
16 16
17 #include <dbghelp.h> 17 #include <dbghelp.h>
18 #include <string.h> 18 #include <string.h>
19 19
20 #include <string> 20 #include <string>
21 21
22 #include "base/basictypes.h" 22 #include "base/basictypes.h"
23 #include "base/memory/scoped_ptr.h"
23 #include "base/strings/string16.h" 24 #include "base/strings/string16.h"
24 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
25 #include "gtest/gtest.h" 26 #include "gtest/gtest.h"
26 #include "minidump/minidump_file_writer.h" 27 #include "minidump/minidump_file_writer.h"
27 #include "minidump/test/minidump_file_writer_test_util.h" 28 #include "minidump/test/minidump_file_writer_test_util.h"
28 #include "minidump/test/minidump_writable_test_util.h" 29 #include "minidump/test/minidump_writable_test_util.h"
29 #include "util/file/string_file_writer.h" 30 #include "util/file/string_file_writer.h"
30 #include "util/stdlib/strlcpy.h" 31 #include "util/stdlib/strlcpy.h"
31 32
32 namespace crashpad { 33 namespace crashpad {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 { 149 {
149 SCOPED_TRACE("DbgBldStr"); 150 SCOPED_TRACE("DbgBldStr");
150 ExpectNULPaddedString16Equal(expected->DbgBldStr, 151 ExpectNULPaddedString16Equal(expected->DbgBldStr,
151 observed->DbgBldStr, 152 observed->DbgBldStr,
152 arraysize(expected->DbgBldStr)); 153 arraysize(expected->DbgBldStr));
153 } 154 }
154 } 155 }
155 156
156 TEST(MinidumpMiscInfoWriter, Empty) { 157 TEST(MinidumpMiscInfoWriter, Empty) {
157 MinidumpFileWriter minidump_file_writer; 158 MinidumpFileWriter minidump_file_writer;
158 MinidumpMiscInfoWriter misc_info_writer; 159 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
159 160
160 minidump_file_writer.AddStream(&misc_info_writer); 161 minidump_file_writer.AddStream(misc_info_writer.Pass());
161 162
162 StringFileWriter file_writer; 163 StringFileWriter file_writer;
163 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 164 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
164 165
165 const MINIDUMP_MISC_INFO* observed; 166 const MINIDUMP_MISC_INFO* observed;
166 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 167 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
167 168
168 MINIDUMP_MISC_INFO expected = {}; 169 MINIDUMP_MISC_INFO expected = {};
169 170
170 ExpectMiscInfoEqual(&expected, observed); 171 ExpectMiscInfoEqual(&expected, observed);
171 } 172 }
172 173
173 TEST(MinidumpMiscInfoWriter, ProcessId) { 174 TEST(MinidumpMiscInfoWriter, ProcessId) {
174 MinidumpFileWriter minidump_file_writer; 175 MinidumpFileWriter minidump_file_writer;
175 MinidumpMiscInfoWriter misc_info_writer; 176 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
176 177
177 const uint32_t kProcessId = 12345; 178 const uint32_t kProcessId = 12345;
178 179
179 misc_info_writer.SetProcessId(kProcessId); 180 misc_info_writer->SetProcessId(kProcessId);
180 181
181 minidump_file_writer.AddStream(&misc_info_writer); 182 minidump_file_writer.AddStream(misc_info_writer.Pass());
182 183
183 StringFileWriter file_writer; 184 StringFileWriter file_writer;
184 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 185 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
185 186
186 const MINIDUMP_MISC_INFO* observed; 187 const MINIDUMP_MISC_INFO* observed;
187 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 188 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
188 189
189 MINIDUMP_MISC_INFO expected = {}; 190 MINIDUMP_MISC_INFO expected = {};
190 expected.Flags1 = MINIDUMP_MISC1_PROCESS_ID; 191 expected.Flags1 = MINIDUMP_MISC1_PROCESS_ID;
191 expected.ProcessId = kProcessId; 192 expected.ProcessId = kProcessId;
192 193
193 ExpectMiscInfoEqual(&expected, observed); 194 ExpectMiscInfoEqual(&expected, observed);
194 } 195 }
195 196
196 TEST(MinidumpMiscInfoWriter, ProcessTimes) { 197 TEST(MinidumpMiscInfoWriter, ProcessTimes) {
197 MinidumpFileWriter minidump_file_writer; 198 MinidumpFileWriter minidump_file_writer;
198 MinidumpMiscInfoWriter misc_info_writer; 199 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
199 200
200 const time_t kProcessCreateTime = 0x15252f00; 201 const time_t kProcessCreateTime = 0x15252f00;
201 const uint32_t kProcessUserTime = 10; 202 const uint32_t kProcessUserTime = 10;
202 const uint32_t kProcessKernelTime = 5; 203 const uint32_t kProcessKernelTime = 5;
203 204
204 misc_info_writer.SetProcessTimes( 205 misc_info_writer->SetProcessTimes(
205 kProcessCreateTime, kProcessUserTime, kProcessKernelTime); 206 kProcessCreateTime, kProcessUserTime, kProcessKernelTime);
206 207
207 minidump_file_writer.AddStream(&misc_info_writer); 208 minidump_file_writer.AddStream(misc_info_writer.Pass());
208 209
209 StringFileWriter file_writer; 210 StringFileWriter file_writer;
210 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 211 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
211 212
212 const MINIDUMP_MISC_INFO* observed; 213 const MINIDUMP_MISC_INFO* observed;
213 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 214 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
214 215
215 MINIDUMP_MISC_INFO expected = {}; 216 MINIDUMP_MISC_INFO expected = {};
216 expected.Flags1 = MINIDUMP_MISC1_PROCESS_TIMES; 217 expected.Flags1 = MINIDUMP_MISC1_PROCESS_TIMES;
217 expected.ProcessCreateTime = kProcessCreateTime; 218 expected.ProcessCreateTime = kProcessCreateTime;
218 expected.ProcessUserTime = kProcessUserTime; 219 expected.ProcessUserTime = kProcessUserTime;
219 expected.ProcessKernelTime = kProcessKernelTime; 220 expected.ProcessKernelTime = kProcessKernelTime;
220 221
221 ExpectMiscInfoEqual(&expected, observed); 222 ExpectMiscInfoEqual(&expected, observed);
222 } 223 }
223 224
224 TEST(MinidumpMiscInfoWriter, ProcessorPowerInfo) { 225 TEST(MinidumpMiscInfoWriter, ProcessorPowerInfo) {
225 MinidumpFileWriter minidump_file_writer; 226 MinidumpFileWriter minidump_file_writer;
226 MinidumpMiscInfoWriter misc_info_writer; 227 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
227 228
228 const uint32_t kProcessorMaxMhz = 2800; 229 const uint32_t kProcessorMaxMhz = 2800;
229 const uint32_t kProcessorCurrentMhz = 2300; 230 const uint32_t kProcessorCurrentMhz = 2300;
230 const uint32_t kProcessorMhzLimit = 3300; 231 const uint32_t kProcessorMhzLimit = 3300;
231 const uint32_t kProcessorMaxIdleState = 5; 232 const uint32_t kProcessorMaxIdleState = 5;
232 const uint32_t kProcessorCurrentIdleState = 1; 233 const uint32_t kProcessorCurrentIdleState = 1;
233 234
234 misc_info_writer.SetProcessorPowerInfo(kProcessorMaxMhz, 235 misc_info_writer->SetProcessorPowerInfo(kProcessorMaxMhz,
235 kProcessorCurrentMhz, 236 kProcessorCurrentMhz,
236 kProcessorMhzLimit, 237 kProcessorMhzLimit,
237 kProcessorMaxIdleState, 238 kProcessorMaxIdleState,
238 kProcessorCurrentIdleState); 239 kProcessorCurrentIdleState);
239 240
240 minidump_file_writer.AddStream(&misc_info_writer); 241 minidump_file_writer.AddStream(misc_info_writer.Pass());
241 242
242 StringFileWriter file_writer; 243 StringFileWriter file_writer;
243 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 244 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
244 245
245 const MINIDUMP_MISC_INFO_2* observed; 246 const MINIDUMP_MISC_INFO_2* observed;
246 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 247 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
247 248
248 MINIDUMP_MISC_INFO_2 expected = {}; 249 MINIDUMP_MISC_INFO_2 expected = {};
249 expected.Flags1 = MINIDUMP_MISC1_PROCESSOR_POWER_INFO; 250 expected.Flags1 = MINIDUMP_MISC1_PROCESSOR_POWER_INFO;
250 expected.ProcessorMaxMhz = kProcessorMaxMhz; 251 expected.ProcessorMaxMhz = kProcessorMaxMhz;
251 expected.ProcessorCurrentMhz = kProcessorCurrentMhz; 252 expected.ProcessorCurrentMhz = kProcessorCurrentMhz;
252 expected.ProcessorMhzLimit = kProcessorMhzLimit; 253 expected.ProcessorMhzLimit = kProcessorMhzLimit;
253 expected.ProcessorMaxIdleState = kProcessorMaxIdleState; 254 expected.ProcessorMaxIdleState = kProcessorMaxIdleState;
254 expected.ProcessorCurrentIdleState = kProcessorCurrentIdleState; 255 expected.ProcessorCurrentIdleState = kProcessorCurrentIdleState;
255 256
256 ExpectMiscInfoEqual(&expected, observed); 257 ExpectMiscInfoEqual(&expected, observed);
257 } 258 }
258 259
259 TEST(MinidumpMiscInfoWriter, ProcessIntegrityLevel) { 260 TEST(MinidumpMiscInfoWriter, ProcessIntegrityLevel) {
260 MinidumpFileWriter minidump_file_writer; 261 MinidumpFileWriter minidump_file_writer;
261 MinidumpMiscInfoWriter misc_info_writer; 262 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
262 263
263 const uint32_t kProcessIntegrityLevel = 0x2000; 264 const uint32_t kProcessIntegrityLevel = 0x2000;
264 265
265 misc_info_writer.SetProcessIntegrityLevel(kProcessIntegrityLevel); 266 misc_info_writer->SetProcessIntegrityLevel(kProcessIntegrityLevel);
266 267
267 minidump_file_writer.AddStream(&misc_info_writer); 268 minidump_file_writer.AddStream(misc_info_writer.Pass());
268 269
269 StringFileWriter file_writer; 270 StringFileWriter file_writer;
270 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 271 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
271 272
272 const MINIDUMP_MISC_INFO_3* observed; 273 const MINIDUMP_MISC_INFO_3* observed;
273 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 274 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
274 275
275 MINIDUMP_MISC_INFO_3 expected = {}; 276 MINIDUMP_MISC_INFO_3 expected = {};
276 expected.Flags1 = MINIDUMP_MISC3_PROCESS_INTEGRITY; 277 expected.Flags1 = MINIDUMP_MISC3_PROCESS_INTEGRITY;
277 expected.ProcessIntegrityLevel = kProcessIntegrityLevel; 278 expected.ProcessIntegrityLevel = kProcessIntegrityLevel;
278 279
279 ExpectMiscInfoEqual(&expected, observed); 280 ExpectMiscInfoEqual(&expected, observed);
280 } 281 }
281 282
282 TEST(MinidumpMiscInfoWriter, ProcessExecuteFlags) { 283 TEST(MinidumpMiscInfoWriter, ProcessExecuteFlags) {
283 MinidumpFileWriter minidump_file_writer; 284 MinidumpFileWriter minidump_file_writer;
284 MinidumpMiscInfoWriter misc_info_writer; 285 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
285 286
286 const uint32_t kProcessExecuteFlags = 0x13579bdf; 287 const uint32_t kProcessExecuteFlags = 0x13579bdf;
287 288
288 misc_info_writer.SetProcessExecuteFlags(kProcessExecuteFlags); 289 misc_info_writer->SetProcessExecuteFlags(kProcessExecuteFlags);
289 290
290 minidump_file_writer.AddStream(&misc_info_writer); 291 minidump_file_writer.AddStream(misc_info_writer.Pass());
291 292
292 StringFileWriter file_writer; 293 StringFileWriter file_writer;
293 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 294 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
294 295
295 const MINIDUMP_MISC_INFO_3* observed; 296 const MINIDUMP_MISC_INFO_3* observed;
296 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 297 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
297 298
298 MINIDUMP_MISC_INFO_3 expected = {}; 299 MINIDUMP_MISC_INFO_3 expected = {};
299 expected.Flags1 = MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS; 300 expected.Flags1 = MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS;
300 expected.ProcessExecuteFlags = kProcessExecuteFlags; 301 expected.ProcessExecuteFlags = kProcessExecuteFlags;
301 302
302 ExpectMiscInfoEqual(&expected, observed); 303 ExpectMiscInfoEqual(&expected, observed);
303 } 304 }
304 305
305 TEST(MinidumpMiscInfoWriter, ProtectedProcess) { 306 TEST(MinidumpMiscInfoWriter, ProtectedProcess) {
306 MinidumpFileWriter minidump_file_writer; 307 MinidumpFileWriter minidump_file_writer;
307 MinidumpMiscInfoWriter misc_info_writer; 308 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
308 309
309 const uint32_t kProtectedProcess = 1; 310 const uint32_t kProtectedProcess = 1;
310 311
311 misc_info_writer.SetProtectedProcess(kProtectedProcess); 312 misc_info_writer->SetProtectedProcess(kProtectedProcess);
312 313
313 minidump_file_writer.AddStream(&misc_info_writer); 314 minidump_file_writer.AddStream(misc_info_writer.Pass());
314 315
315 StringFileWriter file_writer; 316 StringFileWriter file_writer;
316 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 317 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
317 318
318 const MINIDUMP_MISC_INFO_3* observed; 319 const MINIDUMP_MISC_INFO_3* observed;
319 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 320 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
320 321
321 MINIDUMP_MISC_INFO_3 expected = {}; 322 MINIDUMP_MISC_INFO_3 expected = {};
322 expected.Flags1 = MINIDUMP_MISC3_PROTECTED_PROCESS; 323 expected.Flags1 = MINIDUMP_MISC3_PROTECTED_PROCESS;
323 expected.ProtectedProcess = kProtectedProcess; 324 expected.ProtectedProcess = kProtectedProcess;
324 325
325 ExpectMiscInfoEqual(&expected, observed); 326 ExpectMiscInfoEqual(&expected, observed);
326 } 327 }
327 328
328 TEST(MinidumpMiscInfoWriter, TimeZone) { 329 TEST(MinidumpMiscInfoWriter, TimeZone) {
329 MinidumpFileWriter minidump_file_writer; 330 MinidumpFileWriter minidump_file_writer;
330 MinidumpMiscInfoWriter misc_info_writer; 331 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
331 332
332 const uint32_t kTimeZoneId = 2; 333 const uint32_t kTimeZoneId = 2;
333 const int32_t kBias = 300; 334 const int32_t kBias = 300;
334 const char kStandardName[] = "EST"; 335 const char kStandardName[] = "EST";
335 const SYSTEMTIME kStandardDate = {0, 11, 1, 0, 2, 0, 0, 0}; 336 const SYSTEMTIME kStandardDate = {0, 11, 1, 0, 2, 0, 0, 0};
336 const int32_t kStandardBias = 0; 337 const int32_t kStandardBias = 0;
337 const char kDaylightName[] = "EDT"; 338 const char kDaylightName[] = "EDT";
338 const SYSTEMTIME kDaylightDate = {0, 3, 2, 0, 2, 0, 0, 0}; 339 const SYSTEMTIME kDaylightDate = {0, 3, 2, 0, 2, 0, 0, 0};
339 const int32_t kDaylightBias = -60; 340 const int32_t kDaylightBias = -60;
340 341
341 misc_info_writer.SetTimeZone(kTimeZoneId, 342 misc_info_writer->SetTimeZone(kTimeZoneId,
342 kBias, 343 kBias,
343 kStandardName, 344 kStandardName,
344 kStandardDate, 345 kStandardDate,
345 kStandardBias, 346 kStandardBias,
346 kDaylightName, 347 kDaylightName,
347 kDaylightDate, 348 kDaylightDate,
348 kDaylightBias); 349 kDaylightBias);
349 350
350 minidump_file_writer.AddStream(&misc_info_writer); 351 minidump_file_writer.AddStream(misc_info_writer.Pass());
351 352
352 StringFileWriter file_writer; 353 StringFileWriter file_writer;
353 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 354 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
354 355
355 const MINIDUMP_MISC_INFO_3* observed; 356 const MINIDUMP_MISC_INFO_3* observed;
356 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 357 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
357 358
358 MINIDUMP_MISC_INFO_3 expected = {}; 359 MINIDUMP_MISC_INFO_3 expected = {};
359 expected.Flags1 = MINIDUMP_MISC3_TIMEZONE; 360 expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
360 expected.TimeZoneId = kTimeZoneId; 361 expected.TimeZoneId = kTimeZoneId;
(...skipping 16 matching lines...) Expand all
377 expected.TimeZone.DaylightBias = kDaylightBias; 378 expected.TimeZone.DaylightBias = kDaylightBias;
378 379
379 ExpectMiscInfoEqual(&expected, observed); 380 ExpectMiscInfoEqual(&expected, observed);
380 } 381 }
381 382
382 TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) { 383 TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
383 // This test makes sure that the time zone name strings are truncated properly 384 // This test makes sure that the time zone name strings are truncated properly
384 // to the widths of their fields. 385 // to the widths of their fields.
385 386
386 MinidumpFileWriter minidump_file_writer; 387 MinidumpFileWriter minidump_file_writer;
387 MinidumpMiscInfoWriter misc_info_writer; 388 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
388 389
389 const uint32_t kTimeZoneId = 2; 390 const uint32_t kTimeZoneId = 2;
390 const int32_t kBias = 300; 391 const int32_t kBias = 300;
391 std::string standard_name( 392 std::string standard_name(
392 arraysize(decltype(MINIDUMP_MISC_INFO_N::TimeZone)::StandardName) + 1, 393 arraysize(decltype(MINIDUMP_MISC_INFO_N::TimeZone)::StandardName) + 1,
393 's'); 394 's');
394 const int32_t kStandardBias = 0; 395 const int32_t kStandardBias = 0;
395 std::string daylight_name( 396 std::string daylight_name(
396 arraysize(decltype(MINIDUMP_MISC_INFO_N::TimeZone)::DaylightName), 'd'); 397 arraysize(decltype(MINIDUMP_MISC_INFO_N::TimeZone)::DaylightName), 'd');
397 const int32_t kDaylightBias = -60; 398 const int32_t kDaylightBias = -60;
398 399
399 // Test using kSystemTimeZero, because not all platforms will be able to 400 // Test using kSystemTimeZero, because not all platforms will be able to
400 // provide daylight saving time transition times. 401 // provide daylight saving time transition times.
401 const SYSTEMTIME kSystemTimeZero = {}; 402 const SYSTEMTIME kSystemTimeZero = {};
402 403
403 misc_info_writer.SetTimeZone(kTimeZoneId, 404 misc_info_writer->SetTimeZone(kTimeZoneId,
404 kBias, 405 kBias,
405 standard_name, 406 standard_name,
406 kSystemTimeZero, 407 kSystemTimeZero,
407 kStandardBias, 408 kStandardBias,
408 daylight_name, 409 daylight_name,
409 kSystemTimeZero, 410 kSystemTimeZero,
410 kDaylightBias); 411 kDaylightBias);
411 412
412 minidump_file_writer.AddStream(&misc_info_writer); 413 minidump_file_writer.AddStream(misc_info_writer.Pass());
413 414
414 StringFileWriter file_writer; 415 StringFileWriter file_writer;
415 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 416 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
416 417
417 const MINIDUMP_MISC_INFO_3* observed; 418 const MINIDUMP_MISC_INFO_3* observed;
418 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 419 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
419 420
420 MINIDUMP_MISC_INFO_3 expected = {}; 421 MINIDUMP_MISC_INFO_3 expected = {};
421 expected.Flags1 = MINIDUMP_MISC3_TIMEZONE; 422 expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
422 expected.TimeZoneId = kTimeZoneId; 423 expected.TimeZoneId = kTimeZoneId;
(...skipping 13 matching lines...) Expand all
436 memcpy(&expected.TimeZone.DaylightDate, 437 memcpy(&expected.TimeZone.DaylightDate,
437 &kSystemTimeZero, 438 &kSystemTimeZero,
438 sizeof(expected.TimeZone.DaylightDate)); 439 sizeof(expected.TimeZone.DaylightDate));
439 expected.TimeZone.DaylightBias = kDaylightBias; 440 expected.TimeZone.DaylightBias = kDaylightBias;
440 441
441 ExpectMiscInfoEqual(&expected, observed); 442 ExpectMiscInfoEqual(&expected, observed);
442 } 443 }
443 444
444 TEST(MinidumpMiscInfoWriter, BuildStrings) { 445 TEST(MinidumpMiscInfoWriter, BuildStrings) {
445 MinidumpFileWriter minidump_file_writer; 446 MinidumpFileWriter minidump_file_writer;
446 MinidumpMiscInfoWriter misc_info_writer; 447 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
447 448
448 const char kBuildString[] = "build string"; 449 const char kBuildString[] = "build string";
449 const char kDebugBuildString[] = "debug build string"; 450 const char kDebugBuildString[] = "debug build string";
450 451
451 misc_info_writer.SetBuildString(kBuildString, kDebugBuildString); 452 misc_info_writer->SetBuildString(kBuildString, kDebugBuildString);
452 453
453 minidump_file_writer.AddStream(&misc_info_writer); 454 minidump_file_writer.AddStream(misc_info_writer.Pass());
454 455
455 StringFileWriter file_writer; 456 StringFileWriter file_writer;
456 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 457 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
457 458
458 const MINIDUMP_MISC_INFO_4* observed; 459 const MINIDUMP_MISC_INFO_4* observed;
459 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 460 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
460 461
461 MINIDUMP_MISC_INFO_4 expected = {}; 462 MINIDUMP_MISC_INFO_4 expected = {};
462 expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING; 463 expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
463 string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString); 464 string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString);
464 c16lcpy(expected.BuildString, 465 c16lcpy(expected.BuildString,
465 build_string_utf16.c_str(), 466 build_string_utf16.c_str(),
466 arraysize(expected.BuildString)); 467 arraysize(expected.BuildString));
467 string16 debug_build_string_utf16 = base::UTF8ToUTF16(kDebugBuildString); 468 string16 debug_build_string_utf16 = base::UTF8ToUTF16(kDebugBuildString);
468 c16lcpy(expected.DbgBldStr, 469 c16lcpy(expected.DbgBldStr,
469 debug_build_string_utf16.c_str(), 470 debug_build_string_utf16.c_str(),
470 arraysize(expected.DbgBldStr)); 471 arraysize(expected.DbgBldStr));
471 472
472 ExpectMiscInfoEqual(&expected, observed); 473 ExpectMiscInfoEqual(&expected, observed);
473 } 474 }
474 475
475 TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) { 476 TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) {
476 // This test makes sure that the build strings are truncated properly to the 477 // This test makes sure that the build strings are truncated properly to the
477 // widths of their fields. 478 // widths of their fields.
478 479
479 MinidumpFileWriter minidump_file_writer; 480 MinidumpFileWriter minidump_file_writer;
480 MinidumpMiscInfoWriter misc_info_writer; 481 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
481 482
482 std::string build_string(arraysize(MINIDUMP_MISC_INFO_N::BuildString) + 1, 483 std::string build_string(arraysize(MINIDUMP_MISC_INFO_N::BuildString) + 1,
483 'B'); 484 'B');
484 std::string debug_build_string(arraysize(MINIDUMP_MISC_INFO_N::DbgBldStr), 485 std::string debug_build_string(arraysize(MINIDUMP_MISC_INFO_N::DbgBldStr),
485 'D'); 486 'D');
486 487
487 misc_info_writer.SetBuildString(build_string, debug_build_string); 488 misc_info_writer->SetBuildString(build_string, debug_build_string);
488 489
489 minidump_file_writer.AddStream(&misc_info_writer); 490 minidump_file_writer.AddStream(misc_info_writer.Pass());
490 491
491 StringFileWriter file_writer; 492 StringFileWriter file_writer;
492 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 493 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
493 494
494 const MINIDUMP_MISC_INFO_4* observed; 495 const MINIDUMP_MISC_INFO_4* observed;
495 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 496 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
496 497
497 MINIDUMP_MISC_INFO_4 expected = {}; 498 MINIDUMP_MISC_INFO_4 expected = {};
498 expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING; 499 expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
499 string16 build_string_utf16 = base::UTF8ToUTF16(build_string); 500 string16 build_string_utf16 = base::UTF8ToUTF16(build_string);
500 c16lcpy(expected.BuildString, 501 c16lcpy(expected.BuildString,
501 build_string_utf16.c_str(), 502 build_string_utf16.c_str(),
502 arraysize(expected.BuildString)); 503 arraysize(expected.BuildString));
503 string16 debug_build_string_utf16 = base::UTF8ToUTF16(debug_build_string); 504 string16 debug_build_string_utf16 = base::UTF8ToUTF16(debug_build_string);
504 c16lcpy(expected.DbgBldStr, 505 c16lcpy(expected.DbgBldStr,
505 debug_build_string_utf16.c_str(), 506 debug_build_string_utf16.c_str(),
506 arraysize(expected.DbgBldStr)); 507 arraysize(expected.DbgBldStr));
507 508
508 ExpectMiscInfoEqual(&expected, observed); 509 ExpectMiscInfoEqual(&expected, observed);
509 } 510 }
510 511
511 TEST(MinidumpMiscInfoWriter, Everything) { 512 TEST(MinidumpMiscInfoWriter, Everything) {
512 MinidumpFileWriter minidump_file_writer; 513 MinidumpFileWriter minidump_file_writer;
513 MinidumpMiscInfoWriter misc_info_writer; 514 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter());
514 515
515 const uint32_t kProcessId = 12345; 516 const uint32_t kProcessId = 12345;
516 const time_t kProcessCreateTime = 0x15252f00; 517 const time_t kProcessCreateTime = 0x15252f00;
517 const uint32_t kProcessUserTime = 10; 518 const uint32_t kProcessUserTime = 10;
518 const uint32_t kProcessKernelTime = 5; 519 const uint32_t kProcessKernelTime = 5;
519 const uint32_t kProcessorMaxMhz = 2800; 520 const uint32_t kProcessorMaxMhz = 2800;
520 const uint32_t kProcessorCurrentMhz = 2300; 521 const uint32_t kProcessorCurrentMhz = 2300;
521 const uint32_t kProcessorMhzLimit = 3300; 522 const uint32_t kProcessorMhzLimit = 3300;
522 const uint32_t kProcessorMaxIdleState = 5; 523 const uint32_t kProcessorMaxIdleState = 5;
523 const uint32_t kProcessorCurrentIdleState = 1; 524 const uint32_t kProcessorCurrentIdleState = 1;
524 const uint32_t kProcessIntegrityLevel = 0x2000; 525 const uint32_t kProcessIntegrityLevel = 0x2000;
525 const uint32_t kProcessExecuteFlags = 0x13579bdf; 526 const uint32_t kProcessExecuteFlags = 0x13579bdf;
526 const uint32_t kProtectedProcess = 1; 527 const uint32_t kProtectedProcess = 1;
527 const uint32_t kTimeZoneId = 2; 528 const uint32_t kTimeZoneId = 2;
528 const int32_t kBias = 300; 529 const int32_t kBias = 300;
529 const char kStandardName[] = "EST"; 530 const char kStandardName[] = "EST";
530 const int32_t kStandardBias = 0; 531 const int32_t kStandardBias = 0;
531 const char kDaylightName[] = "EDT"; 532 const char kDaylightName[] = "EDT";
532 const int32_t kDaylightBias = -60; 533 const int32_t kDaylightBias = -60;
533 const SYSTEMTIME kSystemTimeZero = {}; 534 const SYSTEMTIME kSystemTimeZero = {};
534 const char kBuildString[] = "build string"; 535 const char kBuildString[] = "build string";
535 const char kDebugBuildString[] = "debug build string"; 536 const char kDebugBuildString[] = "debug build string";
536 537
537 misc_info_writer.SetProcessId(kProcessId); 538 misc_info_writer->SetProcessId(kProcessId);
538 misc_info_writer.SetProcessTimes( 539 misc_info_writer->SetProcessTimes(
539 kProcessCreateTime, kProcessUserTime, kProcessKernelTime); 540 kProcessCreateTime, kProcessUserTime, kProcessKernelTime);
540 misc_info_writer.SetProcessorPowerInfo(kProcessorMaxMhz, 541 misc_info_writer->SetProcessorPowerInfo(kProcessorMaxMhz,
541 kProcessorCurrentMhz, 542 kProcessorCurrentMhz,
542 kProcessorMhzLimit, 543 kProcessorMhzLimit,
543 kProcessorMaxIdleState, 544 kProcessorMaxIdleState,
544 kProcessorCurrentIdleState); 545 kProcessorCurrentIdleState);
545 misc_info_writer.SetProcessIntegrityLevel(kProcessIntegrityLevel); 546 misc_info_writer->SetProcessIntegrityLevel(kProcessIntegrityLevel);
546 misc_info_writer.SetProcessExecuteFlags(kProcessExecuteFlags); 547 misc_info_writer->SetProcessExecuteFlags(kProcessExecuteFlags);
547 misc_info_writer.SetProtectedProcess(kProtectedProcess); 548 misc_info_writer->SetProtectedProcess(kProtectedProcess);
548 misc_info_writer.SetTimeZone(kTimeZoneId, 549 misc_info_writer->SetTimeZone(kTimeZoneId,
549 kBias, 550 kBias,
550 kStandardName, 551 kStandardName,
551 kSystemTimeZero, 552 kSystemTimeZero,
552 kStandardBias, 553 kStandardBias,
553 kDaylightName, 554 kDaylightName,
554 kSystemTimeZero, 555 kSystemTimeZero,
555 kDaylightBias); 556 kDaylightBias);
556 misc_info_writer.SetBuildString(kBuildString, kDebugBuildString); 557 misc_info_writer->SetBuildString(kBuildString, kDebugBuildString);
557 558
558 minidump_file_writer.AddStream(&misc_info_writer); 559 minidump_file_writer.AddStream(misc_info_writer.Pass());
559 560
560 StringFileWriter file_writer; 561 StringFileWriter file_writer;
561 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 562 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
562 563
563 const MINIDUMP_MISC_INFO_4* observed; 564 const MINIDUMP_MISC_INFO_4* observed;
564 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); 565 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
565 566
566 MINIDUMP_MISC_INFO_4 expected = {}; 567 MINIDUMP_MISC_INFO_4 expected = {};
567 expected.Flags1 = 568 expected.Flags1 =
568 MINIDUMP_MISC1_PROCESS_ID | MINIDUMP_MISC1_PROCESS_TIMES | 569 MINIDUMP_MISC1_PROCESS_ID | MINIDUMP_MISC1_PROCESS_TIMES |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 c16lcpy(expected.DbgBldStr, 608 c16lcpy(expected.DbgBldStr,
608 debug_build_string_utf16.c_str(), 609 debug_build_string_utf16.c_str(),
609 arraysize(expected.DbgBldStr)); 610 arraysize(expected.DbgBldStr));
610 611
611 ExpectMiscInfoEqual(&expected, observed); 612 ExpectMiscInfoEqual(&expected, observed);
612 } 613 }
613 614
614 } // namespace 615 } // namespace
615 } // namespace test 616 } // namespace test
616 } // namespace crashpad 617 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_misc_info_writer.cc ('k') | minidump/minidump_module_crashpad_info_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698