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