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

Side by Side Diff: minidump/minidump_system_info_writer_test.cc

Issue 694063003: Add MinidumpSystemInfoWriter::InitializeFromSnapshot() and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Rebase 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
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_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
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
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 EXPECT_LE(kCPUFamily, 270);
Robert Sesek 2014/11/05 18:35:37 What's the point of these checks, up to line 285?
Mark Mentovai 2014/11/05 19:08:40 Added a comment.
281 EXPECT_LE(kCPUStepping, 15);
282 const uint8_t kCPUBasicFamily =
283 std::min(kCPUFamily, static_cast<uint16_t>(15));
284 const uint8_t kCPUExtendedFamily = kCPUFamily - kCPUBasicFamily;
285 EXPECT_TRUE(kCPUBasicFamily == 6 || kCPUBasicFamily == 15 || kCPUModel <= 15);
286 const uint8_t kCPUBasicModel = kCPUModel & 0xf;
287 const uint8_t kCPUExtendedModel = kCPUModel >> 4;
288 const uint32_t kCPUSignature =
289 (kCPUExtendedFamily << 20) | (kCPUExtendedModel << 16) |
290 (kCPUBasicFamily << 8) | (kCPUBasicModel << 4) | kCPUStepping;
291 const uint64_t kCPUX86Features = 0x7ffafbffbfebfbff;
292 expect_system_info.ProcessorArchitecture = kMinidumpCPUArchitectureX86;
293 expect_system_info.ProcessorLevel = kCPUFamily;
294 expect_system_info.ProcessorRevision = (kCPUModel << 8) | kCPUStepping;
295 expect_system_info.NumberOfProcessors = 8;
296 expect_system_info.ProductType = kMinidumpOSTypeServer;
297 expect_system_info.MajorVersion = 10;
298 expect_system_info.MinorVersion = 9;
299 expect_system_info.BuildNumber = 5;
300 expect_system_info.PlatformId = kMinidumpOSMacOSX;
301 expect_system_info.SuiteMask = 0;
302 expect_system_info.Cpu.X86CpuInfo.VendorId[0] = 'uneG';
303 expect_system_info.Cpu.X86CpuInfo.VendorId[1] = 'Ieni';
304 expect_system_info.Cpu.X86CpuInfo.VendorId[2] = 'letn';
305 expect_system_info.Cpu.X86CpuInfo.VersionInformation = kCPUSignature;
306 expect_system_info.Cpu.X86CpuInfo.FeatureInformation =
307 kCPUX86Features & 0xffffffff;
308 const char kCPUVendor[] = "GenuineIntel";
309 const char kOSVersionBuild[] = "13F34";
310
311 TestSystemSnapshot system_snapshot;
312 system_snapshot.SetCPUArchitecture(kCPUArchitectureX86);
313 system_snapshot.SetCPURevision(
314 (kCPUFamily << 16) | (kCPUModel << 8) | kCPUStepping);
315 system_snapshot.SetCPUCount(expect_system_info.NumberOfProcessors);
316 system_snapshot.SetCPUVendor(kCPUVendor);
317 system_snapshot.SetCPUX86Signature(kCPUSignature);
318 system_snapshot.SetCPUX86Features(kCPUX86Features);
319 system_snapshot.SetOperatingSystem(SystemSnapshot::kOperatingSystemMacOSX);
320 system_snapshot.SetOSServer(true);
321 system_snapshot.SetOSVersion(expect_system_info.MajorVersion,
322 expect_system_info.MinorVersion,
323 expect_system_info.BuildNumber,
324 kOSVersionBuild);
325
326 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter());
327 system_info_writer->InitializeFromSnapshot(&system_snapshot);
328
329 MinidumpFileWriter minidump_file_writer;
330 minidump_file_writer.AddStream(system_info_writer.Pass());
331
332 StringFileWriter file_writer;
333 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
334
335 const MINIDUMP_SYSTEM_INFO* system_info;
336 const MINIDUMP_STRING* csd_version;
337
338 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(),
339 strlen(kOSVersionBuild),
340 &system_info,
341 &csd_version));
342
343 EXPECT_EQ(expect_system_info.ProcessorArchitecture,
344 system_info->ProcessorArchitecture);
345 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel);
346 EXPECT_EQ(expect_system_info.ProcessorRevision,
347 system_info->ProcessorRevision);
348 EXPECT_EQ(expect_system_info.NumberOfProcessors,
349 system_info->NumberOfProcessors);
350 EXPECT_EQ(expect_system_info.ProductType, system_info->ProductType);
351 EXPECT_EQ(expect_system_info.MajorVersion, system_info->MajorVersion);
352 EXPECT_EQ(expect_system_info.MinorVersion, system_info->MinorVersion);
353 EXPECT_EQ(expect_system_info.BuildNumber, system_info->BuildNumber);
354 EXPECT_EQ(expect_system_info.PlatformId, system_info->PlatformId);
355 EXPECT_EQ(expect_system_info.SuiteMask, system_info->SuiteMask);
356 EXPECT_EQ(expect_system_info.Cpu.X86CpuInfo.VendorId[0],
357 system_info->Cpu.X86CpuInfo.VendorId[0]);
358 EXPECT_EQ(expect_system_info.Cpu.X86CpuInfo.VendorId[1],
359 system_info->Cpu.X86CpuInfo.VendorId[1]);
360 EXPECT_EQ(expect_system_info.Cpu.X86CpuInfo.VendorId[2],
361 system_info->Cpu.X86CpuInfo.VendorId[2]);
362 EXPECT_EQ(expect_system_info.Cpu.X86CpuInfo.VersionInformation,
363 system_info->Cpu.X86CpuInfo.VersionInformation);
364 EXPECT_EQ(expect_system_info.Cpu.X86CpuInfo.FeatureInformation,
365 system_info->Cpu.X86CpuInfo.FeatureInformation);
366
367 for (size_t index = 0; index < strlen(kOSVersionBuild); ++index) {
368 EXPECT_EQ(kOSVersionBuild[index], csd_version->Buffer[index]) << index;
369 }
370 }
371
372 TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_AMD64) {
373 MINIDUMP_SYSTEM_INFO expect_system_info = {};
374
375 const uint8_t kCPUFamily = 6;
376 const uint8_t kCPUModel = 70;
377 const uint8_t kCPUStepping = 1;
378 expect_system_info.ProcessorArchitecture = kMinidumpCPUArchitectureAMD64;
379 expect_system_info.ProcessorLevel = kCPUFamily;
380 expect_system_info.ProcessorRevision = (kCPUModel << 8) | kCPUStepping;
381 expect_system_info.NumberOfProcessors = 8;
382 expect_system_info.ProductType = kMinidumpOSTypeServer;
383 expect_system_info.MajorVersion = 10;
384 expect_system_info.MinorVersion = 9;
385 expect_system_info.BuildNumber = 5;
386 expect_system_info.PlatformId = kMinidumpOSMacOSX;
387 expect_system_info.SuiteMask = 0;
388 expect_system_info.Cpu.OtherCpuInfo.ProcessorFeatures[0] =
389 (1 << PF_COMPARE_EXCHANGE_DOUBLE) |
390 (1 << PF_MMX_INSTRUCTIONS_AVAILABLE) |
391 (1 << PF_XMMI_INSTRUCTIONS_AVAILABLE) |
392 (1 << PF_RDTSC_INSTRUCTION_AVAILABLE) |
393 (1 << PF_PAE_ENABLED) |
394 (1 << PF_XMMI64_INSTRUCTIONS_AVAILABLE) |
395 (1 << PF_SSE_DAZ_MODE_AVAILABLE) |
396 (1 << PF_NX_ENABLED) |
397 (1 << PF_SSE3_INSTRUCTIONS_AVAILABLE) |
398 (1 << PF_COMPARE_EXCHANGE128) |
399 (1 << PF_XSAVE_ENABLED) |
400 (1 << PF_RDWRFSGSBASE_AVAILABLE) |
401 (1 << PF_RDRAND_INSTRUCTION_AVAILABLE);
402 expect_system_info.Cpu.OtherCpuInfo.ProcessorFeatures[1] = 0;
403 const char kOSVersionBuild[] = "13F34";
404
405 TestSystemSnapshot system_snapshot;
406 system_snapshot.SetCPUArchitecture(kCPUArchitectureX86_64);
407 system_snapshot.SetCPURevision(
408 (kCPUFamily << 16) | (kCPUModel << 8) | kCPUStepping);
409 system_snapshot.SetCPUCount(expect_system_info.NumberOfProcessors);
410 system_snapshot.SetCPUX86Features(0x7ffafbffbfebfbff);
411 system_snapshot.SetCPUX86ExtendedFeatures(0x000000212c100900);
412 system_snapshot.SetCPUX86Leaf7Features(0x00002fbb);
413 system_snapshot.SetCPUX86SupportsDAZ(true);
414 system_snapshot.SetOperatingSystem(SystemSnapshot::kOperatingSystemMacOSX);
415 system_snapshot.SetOSServer(true);
416 system_snapshot.SetOSVersion(expect_system_info.MajorVersion,
417 expect_system_info.MinorVersion,
418 expect_system_info.BuildNumber,
419 kOSVersionBuild);
420 system_snapshot.SetNXEnabled(true);
421
422 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter());
423 system_info_writer->InitializeFromSnapshot(&system_snapshot);
424
425 MinidumpFileWriter minidump_file_writer;
426 minidump_file_writer.AddStream(system_info_writer.Pass());
427
428 StringFileWriter file_writer;
429 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
430
431 const MINIDUMP_SYSTEM_INFO* system_info;
432 const MINIDUMP_STRING* csd_version;
433
434 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(),
435 strlen(kOSVersionBuild),
436 &system_info,
437 &csd_version));
438
439 EXPECT_EQ(expect_system_info.ProcessorArchitecture,
440 system_info->ProcessorArchitecture);
441 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel);
442 EXPECT_EQ(expect_system_info.ProcessorRevision,
443 system_info->ProcessorRevision);
444 EXPECT_EQ(expect_system_info.NumberOfProcessors,
445 system_info->NumberOfProcessors);
446 EXPECT_EQ(expect_system_info.ProductType, system_info->ProductType);
447 EXPECT_EQ(expect_system_info.MajorVersion, system_info->MajorVersion);
448 EXPECT_EQ(expect_system_info.MinorVersion, system_info->MinorVersion);
449 EXPECT_EQ(expect_system_info.BuildNumber, system_info->BuildNumber);
450 EXPECT_EQ(expect_system_info.PlatformId, system_info->PlatformId);
451 EXPECT_EQ(expect_system_info.SuiteMask, system_info->SuiteMask);
452 EXPECT_EQ(expect_system_info.Cpu.OtherCpuInfo.ProcessorFeatures[0],
453 system_info->Cpu.OtherCpuInfo.ProcessorFeatures[0]);
454 EXPECT_EQ(expect_system_info.Cpu.OtherCpuInfo.ProcessorFeatures[1],
455 system_info->Cpu.OtherCpuInfo.ProcessorFeatures[1]);
456
457 for (size_t index = 0; index < strlen(kOSVersionBuild); ++index) {
458 EXPECT_EQ(kOSVersionBuild[index], csd_version->Buffer[index]) << index;
459 }
460 }
461
272 TEST(MinidumpSystemInfoWriterDeathTest, NoCSDVersion) { 462 TEST(MinidumpSystemInfoWriterDeathTest, NoCSDVersion) {
273 MinidumpFileWriter minidump_file_writer; 463 MinidumpFileWriter minidump_file_writer;
274 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); 464 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter());
275 minidump_file_writer.AddStream(system_info_writer.Pass()); 465 minidump_file_writer.AddStream(system_info_writer.Pass());
276 466
277 StringFileWriter file_writer; 467 StringFileWriter file_writer;
278 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), 468 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer),
279 "csd_version_"); 469 "csd_version_");
280 } 470 }
281 471
282 } // namespace 472 } // namespace
283 } // namespace test 473 } // namespace test
284 } // namespace crashpad 474 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698