OLD | NEW |
(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_misc_info_writer.h" |
| 16 |
| 17 #include <dbghelp.h> |
| 18 #include <string.h> |
| 19 |
| 20 #include <string> |
| 21 |
| 22 #include "base/basictypes.h" |
| 23 #include "base/strings/string16.h" |
| 24 #include "base/strings/utf_string_conversions.h" |
| 25 #include "gtest/gtest.h" |
| 26 #include "minidump/minidump_file_writer.h" |
| 27 #include "util/file/string_file_writer.h" |
| 28 #include "util/stdlib/strlcpy.h" |
| 29 |
| 30 namespace { |
| 31 |
| 32 using namespace crashpad; |
| 33 |
| 34 template <typename T> |
| 35 void GetMiscInfoStream(const std::string& file_contents, const T** misc_info) { |
| 36 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
| 37 const size_t kMiscInfoStreamOffset = |
| 38 kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); |
| 39 const size_t kMiscInfoStreamSize = sizeof(T); |
| 40 const size_t kFileSize = kMiscInfoStreamOffset + kMiscInfoStreamSize; |
| 41 |
| 42 ASSERT_EQ(kFileSize, file_contents.size()); |
| 43 |
| 44 const MINIDUMP_HEADER* header = |
| 45 reinterpret_cast<const MINIDUMP_HEADER*>(&file_contents[0]); |
| 46 |
| 47 EXPECT_EQ(static_cast<uint32_t>(MINIDUMP_SIGNATURE), header->Signature); |
| 48 EXPECT_EQ(static_cast<uint32_t>(MINIDUMP_VERSION), header->Version); |
| 49 ASSERT_EQ(1u, header->NumberOfStreams); |
| 50 ASSERT_EQ(kDirectoryOffset, header->StreamDirectoryRva); |
| 51 EXPECT_EQ(0u, header->CheckSum); |
| 52 EXPECT_EQ(0u, header->TimeDateStamp); |
| 53 EXPECT_EQ(MiniDumpNormal, header->Flags); |
| 54 |
| 55 const MINIDUMP_DIRECTORY* directory = |
| 56 reinterpret_cast<const MINIDUMP_DIRECTORY*>( |
| 57 &file_contents[kDirectoryOffset]); |
| 58 |
| 59 ASSERT_EQ(kMinidumpStreamTypeMiscInfo, directory->StreamType); |
| 60 ASSERT_EQ(kMiscInfoStreamSize, directory->Location.DataSize); |
| 61 ASSERT_EQ(kMiscInfoStreamOffset, directory->Location.Rva); |
| 62 |
| 63 *misc_info = |
| 64 reinterpret_cast<const T*>(&file_contents[kMiscInfoStreamOffset]); |
| 65 |
| 66 ASSERT_EQ(kMiscInfoStreamSize, (*misc_info)->SizeOfInfo); |
| 67 } |
| 68 |
| 69 void ExpectNULPaddedString16Equal(const char16* expected, |
| 70 const char16* observed, |
| 71 size_t size) { |
| 72 string16 expected_string(expected, size); |
| 73 string16 observed_string(observed, size); |
| 74 EXPECT_EQ(expected_string, observed_string); |
| 75 } |
| 76 |
| 77 void ExpectSystemTimeEqual(const SYSTEMTIME* expected, |
| 78 const SYSTEMTIME* observed) { |
| 79 EXPECT_EQ(expected->wYear, observed->wYear); |
| 80 EXPECT_EQ(expected->wMonth, observed->wMonth); |
| 81 EXPECT_EQ(expected->wDayOfWeek, observed->wDayOfWeek); |
| 82 EXPECT_EQ(expected->wDay, observed->wDay); |
| 83 EXPECT_EQ(expected->wHour, observed->wHour); |
| 84 EXPECT_EQ(expected->wMinute, observed->wMinute); |
| 85 EXPECT_EQ(expected->wSecond, observed->wSecond); |
| 86 EXPECT_EQ(expected->wMilliseconds, observed->wMilliseconds); |
| 87 } |
| 88 |
| 89 template <typename T> |
| 90 void ExpectMiscInfoEqual(const T* expected, const T* observed); |
| 91 |
| 92 template <> |
| 93 void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO>( |
| 94 const MINIDUMP_MISC_INFO* expected, |
| 95 const MINIDUMP_MISC_INFO* observed) { |
| 96 EXPECT_EQ(expected->Flags1, observed->Flags1); |
| 97 EXPECT_EQ(expected->ProcessId, observed->ProcessId); |
| 98 EXPECT_EQ(expected->ProcessCreateTime, observed->ProcessCreateTime); |
| 99 EXPECT_EQ(expected->ProcessUserTime, observed->ProcessUserTime); |
| 100 EXPECT_EQ(expected->ProcessKernelTime, observed->ProcessKernelTime); |
| 101 } |
| 102 |
| 103 template <> |
| 104 void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_2>( |
| 105 const MINIDUMP_MISC_INFO_2* expected, |
| 106 const MINIDUMP_MISC_INFO_2* observed) { |
| 107 ExpectMiscInfoEqual<MINIDUMP_MISC_INFO>(expected, observed); |
| 108 EXPECT_EQ(expected->ProcessorMaxMhz, observed->ProcessorMaxMhz); |
| 109 EXPECT_EQ(expected->ProcessorCurrentMhz, observed->ProcessorCurrentMhz); |
| 110 EXPECT_EQ(expected->ProcessorMhzLimit, observed->ProcessorMhzLimit); |
| 111 EXPECT_EQ(expected->ProcessorMaxIdleState, observed->ProcessorMaxIdleState); |
| 112 EXPECT_EQ(expected->ProcessorCurrentIdleState, |
| 113 observed->ProcessorCurrentIdleState); |
| 114 } |
| 115 |
| 116 template <> |
| 117 void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>( |
| 118 const MINIDUMP_MISC_INFO_3* expected, |
| 119 const MINIDUMP_MISC_INFO_3* observed) { |
| 120 ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_2>(expected, observed); |
| 121 EXPECT_EQ(expected->ProcessIntegrityLevel, observed->ProcessIntegrityLevel); |
| 122 EXPECT_EQ(expected->ProcessExecuteFlags, observed->ProcessExecuteFlags); |
| 123 EXPECT_EQ(expected->ProtectedProcess, observed->ProtectedProcess); |
| 124 EXPECT_EQ(expected->TimeZoneId, observed->TimeZoneId); |
| 125 EXPECT_EQ(expected->TimeZone.Bias, observed->TimeZone.Bias); |
| 126 { |
| 127 SCOPED_TRACE("Standard"); |
| 128 ExpectNULPaddedString16Equal(expected->TimeZone.StandardName, |
| 129 observed->TimeZone.StandardName, |
| 130 arraysize(expected->TimeZone.StandardName)); |
| 131 ExpectSystemTimeEqual(&expected->TimeZone.StandardDate, |
| 132 &observed->TimeZone.StandardDate); |
| 133 EXPECT_EQ(expected->TimeZone.StandardBias, observed->TimeZone.StandardBias); |
| 134 } |
| 135 { |
| 136 SCOPED_TRACE("Daylight"); |
| 137 ExpectNULPaddedString16Equal(expected->TimeZone.DaylightName, |
| 138 observed->TimeZone.DaylightName, |
| 139 arraysize(expected->TimeZone.DaylightName)); |
| 140 ExpectSystemTimeEqual(&expected->TimeZone.DaylightDate, |
| 141 &observed->TimeZone.DaylightDate); |
| 142 EXPECT_EQ(expected->TimeZone.DaylightBias, observed->TimeZone.DaylightBias); |
| 143 } |
| 144 } |
| 145 |
| 146 template <> |
| 147 void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_4>( |
| 148 const MINIDUMP_MISC_INFO_4* expected, |
| 149 const MINIDUMP_MISC_INFO_4* observed) { |
| 150 ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>(expected, observed); |
| 151 { |
| 152 SCOPED_TRACE("BuildString"); |
| 153 ExpectNULPaddedString16Equal(expected->BuildString, |
| 154 observed->BuildString, |
| 155 arraysize(expected->BuildString)); |
| 156 } |
| 157 { |
| 158 SCOPED_TRACE("DbgBldStr"); |
| 159 ExpectNULPaddedString16Equal(expected->DbgBldStr, |
| 160 observed->DbgBldStr, |
| 161 arraysize(expected->DbgBldStr)); |
| 162 } |
| 163 } |
| 164 |
| 165 TEST(MinidumpMiscInfoWriter, Empty) { |
| 166 MinidumpFileWriter minidump_file_writer; |
| 167 MinidumpMiscInfoWriter misc_info_writer; |
| 168 |
| 169 minidump_file_writer.AddStream(&misc_info_writer); |
| 170 |
| 171 StringFileWriter file_writer; |
| 172 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 173 |
| 174 const MINIDUMP_MISC_INFO* observed; |
| 175 GetMiscInfoStream(file_writer.string(), &observed); |
| 176 if (Test::HasFatalFailure()) { |
| 177 return; |
| 178 } |
| 179 |
| 180 MINIDUMP_MISC_INFO expected = {}; |
| 181 |
| 182 ExpectMiscInfoEqual(&expected, observed); |
| 183 } |
| 184 |
| 185 TEST(MinidumpMiscInfoWriter, ProcessId) { |
| 186 MinidumpFileWriter minidump_file_writer; |
| 187 MinidumpMiscInfoWriter misc_info_writer; |
| 188 |
| 189 const uint32_t kProcessId = 12345; |
| 190 |
| 191 misc_info_writer.SetProcessId(kProcessId); |
| 192 |
| 193 minidump_file_writer.AddStream(&misc_info_writer); |
| 194 |
| 195 StringFileWriter file_writer; |
| 196 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 197 |
| 198 const MINIDUMP_MISC_INFO* observed; |
| 199 GetMiscInfoStream(file_writer.string(), &observed); |
| 200 if (Test::HasFatalFailure()) { |
| 201 return; |
| 202 } |
| 203 |
| 204 MINIDUMP_MISC_INFO expected = {}; |
| 205 expected.Flags1 = MINIDUMP_MISC1_PROCESS_ID; |
| 206 expected.ProcessId = kProcessId; |
| 207 |
| 208 ExpectMiscInfoEqual(&expected, observed); |
| 209 } |
| 210 |
| 211 TEST(MinidumpMiscInfoWriter, ProcessTimes) { |
| 212 MinidumpFileWriter minidump_file_writer; |
| 213 MinidumpMiscInfoWriter misc_info_writer; |
| 214 |
| 215 const time_t kProcessCreateTime = 0x15252f00; |
| 216 const uint32_t kProcessUserTime = 10; |
| 217 const uint32_t kProcessKernelTime = 5; |
| 218 |
| 219 misc_info_writer.SetProcessTimes( |
| 220 kProcessCreateTime, kProcessUserTime, kProcessKernelTime); |
| 221 |
| 222 minidump_file_writer.AddStream(&misc_info_writer); |
| 223 |
| 224 StringFileWriter file_writer; |
| 225 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 226 |
| 227 const MINIDUMP_MISC_INFO* observed; |
| 228 GetMiscInfoStream(file_writer.string(), &observed); |
| 229 if (Test::HasFatalFailure()) { |
| 230 return; |
| 231 } |
| 232 |
| 233 MINIDUMP_MISC_INFO expected = {}; |
| 234 expected.Flags1 = MINIDUMP_MISC1_PROCESS_TIMES; |
| 235 expected.ProcessCreateTime = kProcessCreateTime; |
| 236 expected.ProcessUserTime = kProcessUserTime; |
| 237 expected.ProcessKernelTime = kProcessKernelTime; |
| 238 |
| 239 ExpectMiscInfoEqual(&expected, observed); |
| 240 } |
| 241 |
| 242 TEST(MinidumpMiscInfoWriter, ProcessorPowerInfo) { |
| 243 MinidumpFileWriter minidump_file_writer; |
| 244 MinidumpMiscInfoWriter misc_info_writer; |
| 245 |
| 246 const uint32_t kProcessorMaxMhz = 2800; |
| 247 const uint32_t kProcessorCurrentMhz = 2300; |
| 248 const uint32_t kProcessorMhzLimit = 3300; |
| 249 const uint32_t kProcessorMaxIdleState = 5; |
| 250 const uint32_t kProcessorCurrentIdleState = 1; |
| 251 |
| 252 misc_info_writer.SetProcessorPowerInfo(kProcessorMaxMhz, |
| 253 kProcessorCurrentMhz, |
| 254 kProcessorMhzLimit, |
| 255 kProcessorMaxIdleState, |
| 256 kProcessorCurrentIdleState); |
| 257 |
| 258 minidump_file_writer.AddStream(&misc_info_writer); |
| 259 |
| 260 StringFileWriter file_writer; |
| 261 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 262 |
| 263 const MINIDUMP_MISC_INFO_2* observed; |
| 264 GetMiscInfoStream(file_writer.string(), &observed); |
| 265 if (Test::HasFatalFailure()) { |
| 266 return; |
| 267 } |
| 268 |
| 269 MINIDUMP_MISC_INFO_2 expected = {}; |
| 270 expected.Flags1 = MINIDUMP_MISC1_PROCESSOR_POWER_INFO; |
| 271 expected.ProcessorMaxMhz = kProcessorMaxMhz; |
| 272 expected.ProcessorCurrentMhz = kProcessorCurrentMhz; |
| 273 expected.ProcessorMhzLimit = kProcessorMhzLimit; |
| 274 expected.ProcessorMaxIdleState = kProcessorMaxIdleState; |
| 275 expected.ProcessorCurrentIdleState = kProcessorCurrentIdleState; |
| 276 |
| 277 ExpectMiscInfoEqual(&expected, observed); |
| 278 } |
| 279 |
| 280 TEST(MinidumpMiscInfoWriter, ProcessIntegrityLevel) { |
| 281 MinidumpFileWriter minidump_file_writer; |
| 282 MinidumpMiscInfoWriter misc_info_writer; |
| 283 |
| 284 const uint32_t kProcessIntegrityLevel = 0x2000; |
| 285 |
| 286 misc_info_writer.SetProcessIntegrityLevel(kProcessIntegrityLevel); |
| 287 |
| 288 minidump_file_writer.AddStream(&misc_info_writer); |
| 289 |
| 290 StringFileWriter file_writer; |
| 291 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 292 |
| 293 const MINIDUMP_MISC_INFO_3* observed; |
| 294 GetMiscInfoStream(file_writer.string(), &observed); |
| 295 if (Test::HasFatalFailure()) { |
| 296 return; |
| 297 } |
| 298 |
| 299 MINIDUMP_MISC_INFO_3 expected = {}; |
| 300 expected.Flags1 = MINIDUMP_MISC3_PROCESS_INTEGRITY; |
| 301 expected.ProcessIntegrityLevel = kProcessIntegrityLevel; |
| 302 |
| 303 ExpectMiscInfoEqual(&expected, observed); |
| 304 } |
| 305 |
| 306 TEST(MinidumpMiscInfoWriter, ProcessExecuteFlags) { |
| 307 MinidumpFileWriter minidump_file_writer; |
| 308 MinidumpMiscInfoWriter misc_info_writer; |
| 309 |
| 310 const uint32_t kProcessExecuteFlags = 0x13579bdf; |
| 311 |
| 312 misc_info_writer.SetProcessExecuteFlags(kProcessExecuteFlags); |
| 313 |
| 314 minidump_file_writer.AddStream(&misc_info_writer); |
| 315 |
| 316 StringFileWriter file_writer; |
| 317 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 318 |
| 319 const MINIDUMP_MISC_INFO_3* observed; |
| 320 GetMiscInfoStream(file_writer.string(), &observed); |
| 321 if (Test::HasFatalFailure()) { |
| 322 return; |
| 323 } |
| 324 |
| 325 MINIDUMP_MISC_INFO_3 expected = {}; |
| 326 expected.Flags1 = MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS; |
| 327 expected.ProcessExecuteFlags = kProcessExecuteFlags; |
| 328 |
| 329 ExpectMiscInfoEqual(&expected, observed); |
| 330 } |
| 331 |
| 332 TEST(MinidumpMiscInfoWriter, ProtectedProcess) { |
| 333 MinidumpFileWriter minidump_file_writer; |
| 334 MinidumpMiscInfoWriter misc_info_writer; |
| 335 |
| 336 const uint32_t kProtectedProcess = 1; |
| 337 |
| 338 misc_info_writer.SetProtectedProcess(kProtectedProcess); |
| 339 |
| 340 minidump_file_writer.AddStream(&misc_info_writer); |
| 341 |
| 342 StringFileWriter file_writer; |
| 343 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 344 |
| 345 const MINIDUMP_MISC_INFO_3* observed; |
| 346 GetMiscInfoStream(file_writer.string(), &observed); |
| 347 if (Test::HasFatalFailure()) { |
| 348 return; |
| 349 } |
| 350 |
| 351 MINIDUMP_MISC_INFO_3 expected = {}; |
| 352 expected.Flags1 = MINIDUMP_MISC3_PROTECTED_PROCESS; |
| 353 expected.ProtectedProcess = kProtectedProcess; |
| 354 |
| 355 ExpectMiscInfoEqual(&expected, observed); |
| 356 } |
| 357 |
| 358 TEST(MinidumpMiscInfoWriter, TimeZone) { |
| 359 MinidumpFileWriter minidump_file_writer; |
| 360 MinidumpMiscInfoWriter misc_info_writer; |
| 361 |
| 362 const uint32_t kTimeZoneId = 2; |
| 363 const int32_t kBias = 300; |
| 364 const char kStandardName[] = "EST"; |
| 365 const SYSTEMTIME kStandardDate = {0, 11, 1, 0, 2, 0, 0, 0}; |
| 366 const int32_t kStandardBias = 0; |
| 367 const char kDaylightName[] = "EDT"; |
| 368 const SYSTEMTIME kDaylightDate = {0, 3, 2, 0, 2, 0, 0, 0}; |
| 369 const int32_t kDaylightBias = -60; |
| 370 |
| 371 misc_info_writer.SetTimeZone(kTimeZoneId, |
| 372 kBias, |
| 373 kStandardName, |
| 374 kStandardDate, |
| 375 kStandardBias, |
| 376 kDaylightName, |
| 377 kDaylightDate, |
| 378 kDaylightBias); |
| 379 |
| 380 minidump_file_writer.AddStream(&misc_info_writer); |
| 381 |
| 382 StringFileWriter file_writer; |
| 383 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 384 |
| 385 const MINIDUMP_MISC_INFO_3* observed; |
| 386 GetMiscInfoStream(file_writer.string(), &observed); |
| 387 if (Test::HasFatalFailure()) { |
| 388 return; |
| 389 } |
| 390 |
| 391 MINIDUMP_MISC_INFO_3 expected = {}; |
| 392 expected.Flags1 = MINIDUMP_MISC3_TIMEZONE; |
| 393 expected.TimeZoneId = kTimeZoneId; |
| 394 expected.TimeZone.Bias = kBias; |
| 395 string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName); |
| 396 c16lcpy(expected.TimeZone.StandardName, |
| 397 standard_name_utf16.c_str(), |
| 398 arraysize(expected.TimeZone.StandardName)); |
| 399 memcpy(&expected.TimeZone.StandardDate, |
| 400 &kStandardDate, |
| 401 sizeof(expected.TimeZone.StandardDate)); |
| 402 expected.TimeZone.StandardBias = kStandardBias; |
| 403 string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName); |
| 404 c16lcpy(expected.TimeZone.DaylightName, |
| 405 daylight_name_utf16.c_str(), |
| 406 arraysize(expected.TimeZone.DaylightName)); |
| 407 memcpy(&expected.TimeZone.DaylightDate, |
| 408 &kDaylightDate, |
| 409 sizeof(expected.TimeZone.DaylightDate)); |
| 410 expected.TimeZone.DaylightBias = kDaylightBias; |
| 411 |
| 412 ExpectMiscInfoEqual(&expected, observed); |
| 413 } |
| 414 |
| 415 TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) { |
| 416 // This test makes sure that the time zone name strings are truncated properly |
| 417 // to the widths of their fields. |
| 418 |
| 419 MinidumpFileWriter minidump_file_writer; |
| 420 MinidumpMiscInfoWriter misc_info_writer; |
| 421 |
| 422 const uint32_t kTimeZoneId = 2; |
| 423 const int32_t kBias = 300; |
| 424 std::string standard_name( |
| 425 arraysize(decltype(MINIDUMP_MISC_INFO_N::TimeZone)::StandardName) + 1, |
| 426 's'); |
| 427 const int32_t kStandardBias = 0; |
| 428 std::string daylight_name( |
| 429 arraysize(decltype(MINIDUMP_MISC_INFO_N::TimeZone)::DaylightName), 'd'); |
| 430 const int32_t kDaylightBias = -60; |
| 431 |
| 432 // Test using kSystemTimeZero, because not all platforms will be able to |
| 433 // provide daylight saving time transition times. |
| 434 const SYSTEMTIME kSystemTimeZero = {}; |
| 435 |
| 436 misc_info_writer.SetTimeZone(kTimeZoneId, |
| 437 kBias, |
| 438 standard_name, |
| 439 kSystemTimeZero, |
| 440 kStandardBias, |
| 441 daylight_name, |
| 442 kSystemTimeZero, |
| 443 kDaylightBias); |
| 444 |
| 445 minidump_file_writer.AddStream(&misc_info_writer); |
| 446 |
| 447 StringFileWriter file_writer; |
| 448 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 449 |
| 450 const MINIDUMP_MISC_INFO_3* observed; |
| 451 GetMiscInfoStream(file_writer.string(), &observed); |
| 452 if (Test::HasFatalFailure()) { |
| 453 return; |
| 454 } |
| 455 |
| 456 MINIDUMP_MISC_INFO_3 expected = {}; |
| 457 expected.Flags1 = MINIDUMP_MISC3_TIMEZONE; |
| 458 expected.TimeZoneId = kTimeZoneId; |
| 459 expected.TimeZone.Bias = kBias; |
| 460 string16 standard_name_utf16 = base::UTF8ToUTF16(standard_name); |
| 461 c16lcpy(expected.TimeZone.StandardName, |
| 462 standard_name_utf16.c_str(), |
| 463 arraysize(expected.TimeZone.StandardName)); |
| 464 memcpy(&expected.TimeZone.StandardDate, |
| 465 &kSystemTimeZero, |
| 466 sizeof(expected.TimeZone.StandardDate)); |
| 467 expected.TimeZone.StandardBias = kStandardBias; |
| 468 string16 daylight_name_utf16 = base::UTF8ToUTF16(daylight_name); |
| 469 c16lcpy(expected.TimeZone.DaylightName, |
| 470 daylight_name_utf16.c_str(), |
| 471 arraysize(expected.TimeZone.DaylightName)); |
| 472 memcpy(&expected.TimeZone.DaylightDate, |
| 473 &kSystemTimeZero, |
| 474 sizeof(expected.TimeZone.DaylightDate)); |
| 475 expected.TimeZone.DaylightBias = kDaylightBias; |
| 476 |
| 477 ExpectMiscInfoEqual(&expected, observed); |
| 478 } |
| 479 |
| 480 TEST(MinidumpMiscInfoWriter, BuildStrings) { |
| 481 MinidumpFileWriter minidump_file_writer; |
| 482 MinidumpMiscInfoWriter misc_info_writer; |
| 483 |
| 484 const char kBuildString[] = "build string"; |
| 485 const char kDebugBuildString[] = "debug build string"; |
| 486 |
| 487 misc_info_writer.SetBuildString(kBuildString, kDebugBuildString); |
| 488 |
| 489 minidump_file_writer.AddStream(&misc_info_writer); |
| 490 |
| 491 StringFileWriter file_writer; |
| 492 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 493 |
| 494 const MINIDUMP_MISC_INFO_4* observed; |
| 495 GetMiscInfoStream(file_writer.string(), &observed); |
| 496 if (Test::HasFatalFailure()) { |
| 497 return; |
| 498 } |
| 499 |
| 500 MINIDUMP_MISC_INFO_4 expected = {}; |
| 501 expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING; |
| 502 string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString); |
| 503 c16lcpy(expected.BuildString, |
| 504 build_string_utf16.c_str(), |
| 505 arraysize(expected.BuildString)); |
| 506 string16 debug_build_string_utf16 = base::UTF8ToUTF16(kDebugBuildString); |
| 507 c16lcpy(expected.DbgBldStr, |
| 508 debug_build_string_utf16.c_str(), |
| 509 arraysize(expected.DbgBldStr)); |
| 510 |
| 511 ExpectMiscInfoEqual(&expected, observed); |
| 512 } |
| 513 |
| 514 TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) { |
| 515 // This test makes sure that the build strings are truncated properly to the |
| 516 // widths of their fields. |
| 517 |
| 518 MinidumpFileWriter minidump_file_writer; |
| 519 MinidumpMiscInfoWriter misc_info_writer; |
| 520 |
| 521 std::string build_string(arraysize(MINIDUMP_MISC_INFO_N::BuildString) + 1, |
| 522 'B'); |
| 523 std::string debug_build_string(arraysize(MINIDUMP_MISC_INFO_N::DbgBldStr), |
| 524 'D'); |
| 525 |
| 526 misc_info_writer.SetBuildString(build_string, debug_build_string); |
| 527 |
| 528 minidump_file_writer.AddStream(&misc_info_writer); |
| 529 |
| 530 StringFileWriter file_writer; |
| 531 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 532 |
| 533 const MINIDUMP_MISC_INFO_4* observed; |
| 534 GetMiscInfoStream(file_writer.string(), &observed); |
| 535 if (Test::HasFatalFailure()) { |
| 536 return; |
| 537 } |
| 538 |
| 539 MINIDUMP_MISC_INFO_4 expected = {}; |
| 540 expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING; |
| 541 string16 build_string_utf16 = base::UTF8ToUTF16(build_string); |
| 542 c16lcpy(expected.BuildString, |
| 543 build_string_utf16.c_str(), |
| 544 arraysize(expected.BuildString)); |
| 545 string16 debug_build_string_utf16 = base::UTF8ToUTF16(debug_build_string); |
| 546 c16lcpy(expected.DbgBldStr, |
| 547 debug_build_string_utf16.c_str(), |
| 548 arraysize(expected.DbgBldStr)); |
| 549 |
| 550 ExpectMiscInfoEqual(&expected, observed); |
| 551 } |
| 552 |
| 553 TEST(MinidumpMiscInfoWriter, Everything) { |
| 554 MinidumpFileWriter minidump_file_writer; |
| 555 MinidumpMiscInfoWriter misc_info_writer; |
| 556 |
| 557 const uint32_t kProcessId = 12345; |
| 558 const time_t kProcessCreateTime = 0x15252f00; |
| 559 const uint32_t kProcessUserTime = 10; |
| 560 const uint32_t kProcessKernelTime = 5; |
| 561 const uint32_t kProcessorMaxMhz = 2800; |
| 562 const uint32_t kProcessorCurrentMhz = 2300; |
| 563 const uint32_t kProcessorMhzLimit = 3300; |
| 564 const uint32_t kProcessorMaxIdleState = 5; |
| 565 const uint32_t kProcessorCurrentIdleState = 1; |
| 566 const uint32_t kProcessIntegrityLevel = 0x2000; |
| 567 const uint32_t kProcessExecuteFlags = 0x13579bdf; |
| 568 const uint32_t kProtectedProcess = 1; |
| 569 const uint32_t kTimeZoneId = 2; |
| 570 const int32_t kBias = 300; |
| 571 const char kStandardName[] = "EST"; |
| 572 const int32_t kStandardBias = 0; |
| 573 const char kDaylightName[] = "EDT"; |
| 574 const int32_t kDaylightBias = -60; |
| 575 const SYSTEMTIME kSystemTimeZero = {}; |
| 576 const char kBuildString[] = "build string"; |
| 577 const char kDebugBuildString[] = "debug build string"; |
| 578 |
| 579 misc_info_writer.SetProcessId(kProcessId); |
| 580 misc_info_writer.SetProcessTimes( |
| 581 kProcessCreateTime, kProcessUserTime, kProcessKernelTime); |
| 582 misc_info_writer.SetProcessorPowerInfo(kProcessorMaxMhz, |
| 583 kProcessorCurrentMhz, |
| 584 kProcessorMhzLimit, |
| 585 kProcessorMaxIdleState, |
| 586 kProcessorCurrentIdleState); |
| 587 misc_info_writer.SetProcessIntegrityLevel(kProcessIntegrityLevel); |
| 588 misc_info_writer.SetProcessExecuteFlags(kProcessExecuteFlags); |
| 589 misc_info_writer.SetProtectedProcess(kProtectedProcess); |
| 590 misc_info_writer.SetTimeZone(kTimeZoneId, |
| 591 kBias, |
| 592 kStandardName, |
| 593 kSystemTimeZero, |
| 594 kStandardBias, |
| 595 kDaylightName, |
| 596 kSystemTimeZero, |
| 597 kDaylightBias); |
| 598 misc_info_writer.SetBuildString(kBuildString, kDebugBuildString); |
| 599 |
| 600 minidump_file_writer.AddStream(&misc_info_writer); |
| 601 |
| 602 StringFileWriter file_writer; |
| 603 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 604 |
| 605 const MINIDUMP_MISC_INFO_4* observed; |
| 606 GetMiscInfoStream(file_writer.string(), &observed); |
| 607 if (Test::HasFatalFailure()) { |
| 608 return; |
| 609 } |
| 610 |
| 611 MINIDUMP_MISC_INFO_4 expected = {}; |
| 612 expected.Flags1 = |
| 613 MINIDUMP_MISC1_PROCESS_ID | MINIDUMP_MISC1_PROCESS_TIMES | |
| 614 MINIDUMP_MISC1_PROCESSOR_POWER_INFO | MINIDUMP_MISC3_PROCESS_INTEGRITY | |
| 615 MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS | MINIDUMP_MISC3_PROTECTED_PROCESS | |
| 616 MINIDUMP_MISC3_TIMEZONE | MINIDUMP_MISC4_BUILDSTRING; |
| 617 expected.ProcessId = kProcessId; |
| 618 expected.ProcessCreateTime = kProcessCreateTime; |
| 619 expected.ProcessUserTime = kProcessUserTime; |
| 620 expected.ProcessKernelTime = kProcessKernelTime; |
| 621 expected.ProcessorMaxMhz = kProcessorMaxMhz; |
| 622 expected.ProcessorCurrentMhz = kProcessorCurrentMhz; |
| 623 expected.ProcessorMhzLimit = kProcessorMhzLimit; |
| 624 expected.ProcessorMaxIdleState = kProcessorMaxIdleState; |
| 625 expected.ProcessorCurrentIdleState = kProcessorCurrentIdleState; |
| 626 expected.ProcessIntegrityLevel = kProcessIntegrityLevel; |
| 627 expected.ProcessExecuteFlags = kProcessExecuteFlags; |
| 628 expected.ProtectedProcess = kProtectedProcess; |
| 629 expected.TimeZoneId = kTimeZoneId; |
| 630 expected.TimeZone.Bias = kBias; |
| 631 string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName); |
| 632 c16lcpy(expected.TimeZone.StandardName, |
| 633 standard_name_utf16.c_str(), |
| 634 arraysize(expected.TimeZone.StandardName)); |
| 635 memcpy(&expected.TimeZone.StandardDate, |
| 636 &kSystemTimeZero, |
| 637 sizeof(expected.TimeZone.StandardDate)); |
| 638 expected.TimeZone.StandardBias = kStandardBias; |
| 639 string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName); |
| 640 c16lcpy(expected.TimeZone.DaylightName, |
| 641 daylight_name_utf16.c_str(), |
| 642 arraysize(expected.TimeZone.DaylightName)); |
| 643 memcpy(&expected.TimeZone.DaylightDate, |
| 644 &kSystemTimeZero, |
| 645 sizeof(expected.TimeZone.DaylightDate)); |
| 646 expected.TimeZone.DaylightBias = kDaylightBias; |
| 647 string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString); |
| 648 c16lcpy(expected.BuildString, |
| 649 build_string_utf16.c_str(), |
| 650 arraysize(expected.BuildString)); |
| 651 string16 debug_build_string_utf16 = base::UTF8ToUTF16(kDebugBuildString); |
| 652 c16lcpy(expected.DbgBldStr, |
| 653 debug_build_string_utf16.c_str(), |
| 654 arraysize(expected.DbgBldStr)); |
| 655 |
| 656 ExpectMiscInfoEqual(&expected, observed); |
| 657 } |
| 658 |
| 659 } // namespace |
OLD | NEW |