OLD | NEW |
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_system_info_writer.h" | 15 #include "minidump/minidump_system_info_writer.h" |
16 | 16 |
17 #include <dbghelp.h> | 17 #include <dbghelp.h> |
18 #include <string.h> | 18 #include <string.h> |
19 #include <sys/types.h> | 19 #include <sys/types.h> |
20 | 20 |
| 21 #include <algorithm> |
21 #include <string> | 22 #include <string> |
22 | 23 |
23 #include "gtest/gtest.h" | 24 #include "gtest/gtest.h" |
24 #include "minidump/minidump_file_writer.h" | 25 #include "minidump/minidump_file_writer.h" |
25 #include "minidump/test/minidump_file_writer_test_util.h" | 26 #include "minidump/test/minidump_file_writer_test_util.h" |
26 #include "minidump/test/minidump_string_writer_test_util.h" | 27 #include "minidump/test/minidump_string_writer_test_util.h" |
27 #include "minidump/test/minidump_writable_test_util.h" | 28 #include "minidump/test/minidump_writable_test_util.h" |
| 29 #include "snapshot/test/test_system_snapshot.h" |
28 #include "util/file/string_file_writer.h" | 30 #include "util/file/string_file_writer.h" |
29 | 31 |
30 namespace crashpad { | 32 namespace crashpad { |
31 namespace test { | 33 namespace test { |
32 namespace { | 34 namespace { |
33 | 35 |
34 void GetSystemInfoStream(const std::string& file_contents, | 36 void GetSystemInfoStream(const std::string& file_contents, |
35 size_t csd_version_length, | 37 size_t csd_version_length, |
36 const MINIDUMP_SYSTEM_INFO** system_info, | 38 const MINIDUMP_SYSTEM_INFO** system_info, |
37 const MINIDUMP_STRING** csd_version) { | 39 const MINIDUMP_STRING** csd_version) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 EXPECT_EQ(cpu_vendor_registers[2], system_info->Cpu.X86CpuInfo.VendorId[2]); | 176 EXPECT_EQ(cpu_vendor_registers[2], system_info->Cpu.X86CpuInfo.VendorId[2]); |
175 EXPECT_EQ(kCPUVersion, system_info->Cpu.X86CpuInfo.VersionInformation); | 177 EXPECT_EQ(kCPUVersion, system_info->Cpu.X86CpuInfo.VersionInformation); |
176 EXPECT_EQ(kCPUFeatures, system_info->Cpu.X86CpuInfo.FeatureInformation); | 178 EXPECT_EQ(kCPUFeatures, system_info->Cpu.X86CpuInfo.FeatureInformation); |
177 EXPECT_EQ(kAMDFeatures, system_info->Cpu.X86CpuInfo.AMDExtendedCpuFeatures); | 179 EXPECT_EQ(kAMDFeatures, system_info->Cpu.X86CpuInfo.AMDExtendedCpuFeatures); |
178 | 180 |
179 for (size_t index = 0; index < strlen(kCSDVersion); ++index) { | 181 for (size_t index = 0; index < strlen(kCSDVersion); ++index) { |
180 EXPECT_EQ(kCSDVersion[index], csd_version->Buffer[index]) << index; | 182 EXPECT_EQ(kCSDVersion[index], csd_version->Buffer[index]) << index; |
181 } | 183 } |
182 } | 184 } |
183 | 185 |
184 TEST(MinidumpSystemInfoWriter, X86_64_Mac) { | 186 TEST(MinidumpSystemInfoWriter, AMD64_Mac) { |
185 MinidumpFileWriter minidump_file_writer; | 187 MinidumpFileWriter minidump_file_writer; |
186 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); | 188 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
187 | 189 |
188 const MinidumpCPUArchitecture kCPUArchitecture = | 190 const MinidumpCPUArchitecture kCPUArchitecture = |
189 kMinidumpCPUArchitectureAMD64; | 191 kMinidumpCPUArchitectureAMD64; |
190 const uint16_t kCPULevel = 0x0006; | 192 const uint16_t kCPULevel = 0x0006; |
191 const uint16_t kCPURevision = 0x3a09; | 193 const uint16_t kCPURevision = 0x3a09; |
192 const uint8_t kCPUCount = 8; | 194 const uint8_t kCPUCount = 8; |
193 const MinidumpOS kOS = kMinidumpOSMacOSX; | 195 const MinidumpOS kOS = kMinidumpOSMacOSX; |
194 const MinidumpOSType kOSType = kMinidumpOSTypeWorkstation; | 196 const MinidumpOSType kOSType = kMinidumpOSTypeWorkstation; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); | 264 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); |
263 | 265 |
264 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); | 266 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); |
265 EXPECT_EQ(0u, system_info->ProcessorLevel); | 267 EXPECT_EQ(0u, system_info->ProcessorLevel); |
266 EXPECT_EQ(kCPUVendor[0], system_info->Cpu.X86CpuInfo.VendorId[0]); | 268 EXPECT_EQ(kCPUVendor[0], system_info->Cpu.X86CpuInfo.VendorId[0]); |
267 EXPECT_EQ(kCPUVendor[1], system_info->Cpu.X86CpuInfo.VendorId[1]); | 269 EXPECT_EQ(kCPUVendor[1], system_info->Cpu.X86CpuInfo.VendorId[1]); |
268 EXPECT_EQ(kCPUVendor[2], system_info->Cpu.X86CpuInfo.VendorId[2]); | 270 EXPECT_EQ(kCPUVendor[2], system_info->Cpu.X86CpuInfo.VendorId[2]); |
269 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.VersionInformation); | 271 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.VersionInformation); |
270 } | 272 } |
271 | 273 |
| 274 TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_X86) { |
| 275 MINIDUMP_SYSTEM_INFO expect_system_info = {}; |
| 276 |
| 277 const uint16_t kCPUFamily = 6; |
| 278 const uint8_t kCPUModel = 70; |
| 279 const uint8_t kCPUStepping = 1; |
| 280 |
| 281 const uint8_t kCPUBasicFamily = |
| 282 std::min(kCPUFamily, static_cast<uint16_t>(15)); |
| 283 const uint8_t kCPUExtendedFamily = kCPUFamily - kCPUBasicFamily; |
| 284 |
| 285 // These checks ensure that even if the constants above change, they represent |
| 286 // something that can legitimately be encoded in the form used by cpuid 1 eax. |
| 287 EXPECT_LE(kCPUFamily, 270); |
| 288 EXPECT_LE(kCPUStepping, 15); |
| 289 EXPECT_TRUE(kCPUBasicFamily == 6 || kCPUBasicFamily == 15 || kCPUModel <= 15); |
| 290 |
| 291 const uint8_t kCPUBasicModel = kCPUModel & 0xf; |
| 292 const uint8_t kCPUExtendedModel = kCPUModel >> 4; |
| 293 const uint32_t kCPUSignature = |
| 294 (kCPUExtendedFamily << 20) | (kCPUExtendedModel << 16) | |
| 295 (kCPUBasicFamily << 8) | (kCPUBasicModel << 4) | kCPUStepping; |
| 296 const uint64_t kCPUX86Features = 0x7ffafbffbfebfbff; |
| 297 expect_system_info.ProcessorArchitecture = kMinidumpCPUArchitectureX86; |
| 298 expect_system_info.ProcessorLevel = kCPUFamily; |
| 299 expect_system_info.ProcessorRevision = (kCPUModel << 8) | kCPUStepping; |
| 300 expect_system_info.NumberOfProcessors = 8; |
| 301 expect_system_info.ProductType = kMinidumpOSTypeServer; |
| 302 expect_system_info.MajorVersion = 10; |
| 303 expect_system_info.MinorVersion = 9; |
| 304 expect_system_info.BuildNumber = 5; |
| 305 expect_system_info.PlatformId = kMinidumpOSMacOSX; |
| 306 expect_system_info.SuiteMask = 0; |
| 307 expect_system_info.Cpu.X86CpuInfo.VendorId[0] = 'uneG'; |
| 308 expect_system_info.Cpu.X86CpuInfo.VendorId[1] = 'Ieni'; |
| 309 expect_system_info.Cpu.X86CpuInfo.VendorId[2] = 'letn'; |
| 310 expect_system_info.Cpu.X86CpuInfo.VersionInformation = kCPUSignature; |
| 311 expect_system_info.Cpu.X86CpuInfo.FeatureInformation = |
| 312 kCPUX86Features & 0xffffffff; |
| 313 const char kCPUVendor[] = "GenuineIntel"; |
| 314 const char kOSVersionBuild[] = "13F34"; |
| 315 |
| 316 TestSystemSnapshot system_snapshot; |
| 317 system_snapshot.SetCPUArchitecture(kCPUArchitectureX86); |
| 318 system_snapshot.SetCPURevision( |
| 319 (kCPUFamily << 16) | (kCPUModel << 8) | kCPUStepping); |
| 320 system_snapshot.SetCPUCount(expect_system_info.NumberOfProcessors); |
| 321 system_snapshot.SetCPUVendor(kCPUVendor); |
| 322 system_snapshot.SetCPUX86Signature(kCPUSignature); |
| 323 system_snapshot.SetCPUX86Features(kCPUX86Features); |
| 324 system_snapshot.SetOperatingSystem(SystemSnapshot::kOperatingSystemMacOSX); |
| 325 system_snapshot.SetOSServer(true); |
| 326 system_snapshot.SetOSVersion(expect_system_info.MajorVersion, |
| 327 expect_system_info.MinorVersion, |
| 328 expect_system_info.BuildNumber, |
| 329 kOSVersionBuild); |
| 330 |
| 331 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
| 332 system_info_writer->InitializeFromSnapshot(&system_snapshot); |
| 333 |
| 334 MinidumpFileWriter minidump_file_writer; |
| 335 minidump_file_writer.AddStream(system_info_writer.Pass()); |
| 336 |
| 337 StringFileWriter file_writer; |
| 338 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 339 |
| 340 const MINIDUMP_SYSTEM_INFO* system_info; |
| 341 const MINIDUMP_STRING* csd_version; |
| 342 |
| 343 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(), |
| 344 strlen(kOSVersionBuild), |
| 345 &system_info, |
| 346 &csd_version)); |
| 347 |
| 348 EXPECT_EQ(expect_system_info.ProcessorArchitecture, |
| 349 system_info->ProcessorArchitecture); |
| 350 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel); |
| 351 EXPECT_EQ(expect_system_info.ProcessorRevision, |
| 352 system_info->ProcessorRevision); |
| 353 EXPECT_EQ(expect_system_info.NumberOfProcessors, |
| 354 system_info->NumberOfProcessors); |
| 355 EXPECT_EQ(expect_system_info.ProductType, system_info->ProductType); |
| 356 EXPECT_EQ(expect_system_info.MajorVersion, system_info->MajorVersion); |
| 357 EXPECT_EQ(expect_system_info.MinorVersion, system_info->MinorVersion); |
| 358 EXPECT_EQ(expect_system_info.BuildNumber, system_info->BuildNumber); |
| 359 EXPECT_EQ(expect_system_info.PlatformId, system_info->PlatformId); |
| 360 EXPECT_EQ(expect_system_info.SuiteMask, system_info->SuiteMask); |
| 361 EXPECT_EQ(expect_system_info.Cpu.X86CpuInfo.VendorId[0], |
| 362 system_info->Cpu.X86CpuInfo.VendorId[0]); |
| 363 EXPECT_EQ(expect_system_info.Cpu.X86CpuInfo.VendorId[1], |
| 364 system_info->Cpu.X86CpuInfo.VendorId[1]); |
| 365 EXPECT_EQ(expect_system_info.Cpu.X86CpuInfo.VendorId[2], |
| 366 system_info->Cpu.X86CpuInfo.VendorId[2]); |
| 367 EXPECT_EQ(expect_system_info.Cpu.X86CpuInfo.VersionInformation, |
| 368 system_info->Cpu.X86CpuInfo.VersionInformation); |
| 369 EXPECT_EQ(expect_system_info.Cpu.X86CpuInfo.FeatureInformation, |
| 370 system_info->Cpu.X86CpuInfo.FeatureInformation); |
| 371 |
| 372 for (size_t index = 0; index < strlen(kOSVersionBuild); ++index) { |
| 373 EXPECT_EQ(kOSVersionBuild[index], csd_version->Buffer[index]) << index; |
| 374 } |
| 375 } |
| 376 |
| 377 TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_AMD64) { |
| 378 MINIDUMP_SYSTEM_INFO expect_system_info = {}; |
| 379 |
| 380 const uint8_t kCPUFamily = 6; |
| 381 const uint8_t kCPUModel = 70; |
| 382 const uint8_t kCPUStepping = 1; |
| 383 expect_system_info.ProcessorArchitecture = kMinidumpCPUArchitectureAMD64; |
| 384 expect_system_info.ProcessorLevel = kCPUFamily; |
| 385 expect_system_info.ProcessorRevision = (kCPUModel << 8) | kCPUStepping; |
| 386 expect_system_info.NumberOfProcessors = 8; |
| 387 expect_system_info.ProductType = kMinidumpOSTypeServer; |
| 388 expect_system_info.MajorVersion = 10; |
| 389 expect_system_info.MinorVersion = 9; |
| 390 expect_system_info.BuildNumber = 5; |
| 391 expect_system_info.PlatformId = kMinidumpOSMacOSX; |
| 392 expect_system_info.SuiteMask = 0; |
| 393 expect_system_info.Cpu.OtherCpuInfo.ProcessorFeatures[0] = |
| 394 (1 << PF_COMPARE_EXCHANGE_DOUBLE) | |
| 395 (1 << PF_MMX_INSTRUCTIONS_AVAILABLE) | |
| 396 (1 << PF_XMMI_INSTRUCTIONS_AVAILABLE) | |
| 397 (1 << PF_RDTSC_INSTRUCTION_AVAILABLE) | |
| 398 (1 << PF_PAE_ENABLED) | |
| 399 (1 << PF_XMMI64_INSTRUCTIONS_AVAILABLE) | |
| 400 (1 << PF_SSE_DAZ_MODE_AVAILABLE) | |
| 401 (1 << PF_NX_ENABLED) | |
| 402 (1 << PF_SSE3_INSTRUCTIONS_AVAILABLE) | |
| 403 (1 << PF_COMPARE_EXCHANGE128) | |
| 404 (1 << PF_XSAVE_ENABLED) | |
| 405 (1 << PF_RDWRFSGSBASE_AVAILABLE) | |
| 406 (1 << PF_RDRAND_INSTRUCTION_AVAILABLE); |
| 407 expect_system_info.Cpu.OtherCpuInfo.ProcessorFeatures[1] = 0; |
| 408 const char kOSVersionBuild[] = "13F34"; |
| 409 |
| 410 TestSystemSnapshot system_snapshot; |
| 411 system_snapshot.SetCPUArchitecture(kCPUArchitectureX86_64); |
| 412 system_snapshot.SetCPURevision( |
| 413 (kCPUFamily << 16) | (kCPUModel << 8) | kCPUStepping); |
| 414 system_snapshot.SetCPUCount(expect_system_info.NumberOfProcessors); |
| 415 system_snapshot.SetCPUX86Features(0x7ffafbffbfebfbff); |
| 416 system_snapshot.SetCPUX86ExtendedFeatures(0x000000212c100900); |
| 417 system_snapshot.SetCPUX86Leaf7Features(0x00002fbb); |
| 418 system_snapshot.SetCPUX86SupportsDAZ(true); |
| 419 system_snapshot.SetOperatingSystem(SystemSnapshot::kOperatingSystemMacOSX); |
| 420 system_snapshot.SetOSServer(true); |
| 421 system_snapshot.SetOSVersion(expect_system_info.MajorVersion, |
| 422 expect_system_info.MinorVersion, |
| 423 expect_system_info.BuildNumber, |
| 424 kOSVersionBuild); |
| 425 system_snapshot.SetNXEnabled(true); |
| 426 |
| 427 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
| 428 system_info_writer->InitializeFromSnapshot(&system_snapshot); |
| 429 |
| 430 MinidumpFileWriter minidump_file_writer; |
| 431 minidump_file_writer.AddStream(system_info_writer.Pass()); |
| 432 |
| 433 StringFileWriter file_writer; |
| 434 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 435 |
| 436 const MINIDUMP_SYSTEM_INFO* system_info; |
| 437 const MINIDUMP_STRING* csd_version; |
| 438 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(), |
| 439 strlen(kOSVersionBuild), |
| 440 &system_info, |
| 441 &csd_version)); |
| 442 |
| 443 EXPECT_EQ(expect_system_info.ProcessorArchitecture, |
| 444 system_info->ProcessorArchitecture); |
| 445 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel); |
| 446 EXPECT_EQ(expect_system_info.ProcessorRevision, |
| 447 system_info->ProcessorRevision); |
| 448 EXPECT_EQ(expect_system_info.NumberOfProcessors, |
| 449 system_info->NumberOfProcessors); |
| 450 EXPECT_EQ(expect_system_info.ProductType, system_info->ProductType); |
| 451 EXPECT_EQ(expect_system_info.MajorVersion, system_info->MajorVersion); |
| 452 EXPECT_EQ(expect_system_info.MinorVersion, system_info->MinorVersion); |
| 453 EXPECT_EQ(expect_system_info.BuildNumber, system_info->BuildNumber); |
| 454 EXPECT_EQ(expect_system_info.PlatformId, system_info->PlatformId); |
| 455 EXPECT_EQ(expect_system_info.SuiteMask, system_info->SuiteMask); |
| 456 EXPECT_EQ(expect_system_info.Cpu.OtherCpuInfo.ProcessorFeatures[0], |
| 457 system_info->Cpu.OtherCpuInfo.ProcessorFeatures[0]); |
| 458 EXPECT_EQ(expect_system_info.Cpu.OtherCpuInfo.ProcessorFeatures[1], |
| 459 system_info->Cpu.OtherCpuInfo.ProcessorFeatures[1]); |
| 460 |
| 461 for (size_t index = 0; index < strlen(kOSVersionBuild); ++index) { |
| 462 EXPECT_EQ(kOSVersionBuild[index], csd_version->Buffer[index]) << index; |
| 463 } |
| 464 } |
| 465 |
272 TEST(MinidumpSystemInfoWriterDeathTest, NoCSDVersion) { | 466 TEST(MinidumpSystemInfoWriterDeathTest, NoCSDVersion) { |
273 MinidumpFileWriter minidump_file_writer; | 467 MinidumpFileWriter minidump_file_writer; |
274 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); | 468 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
275 minidump_file_writer.AddStream(system_info_writer.Pass()); | 469 minidump_file_writer.AddStream(system_info_writer.Pass()); |
276 | 470 |
277 StringFileWriter file_writer; | 471 StringFileWriter file_writer; |
278 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), | 472 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), |
279 "csd_version_"); | 473 "csd_version_"); |
280 } | 474 } |
281 | 475 |
282 } // namespace | 476 } // namespace |
283 } // namespace test | 477 } // namespace test |
284 } // namespace crashpad | 478 } // namespace crashpad |
OLD | NEW |