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_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/memory/scoped_ptr.h" |
24 #include "base/strings/string16.h" | 24 #include "base/strings/string16.h" |
25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
26 #include "gtest/gtest.h" | 26 #include "gtest/gtest.h" |
27 #include "minidump/minidump_file_writer.h" | 27 #include "minidump/minidump_file_writer.h" |
28 #include "minidump/test/minidump_file_writer_test_util.h" | 28 #include "minidump/test/minidump_file_writer_test_util.h" |
29 #include "minidump/test/minidump_writable_test_util.h" | 29 #include "minidump/test/minidump_writable_test_util.h" |
| 30 #include "snapshot/test/test_process_snapshot.h" |
| 31 #include "snapshot/test/test_system_snapshot.h" |
30 #include "util/file/string_file_writer.h" | 32 #include "util/file/string_file_writer.h" |
31 #include "util/stdlib/strlcpy.h" | 33 #include "util/stdlib/strlcpy.h" |
32 | 34 |
33 namespace crashpad { | 35 namespace crashpad { |
34 namespace test { | 36 namespace test { |
35 namespace { | 37 namespace { |
36 | 38 |
37 template <typename T> | 39 template <typename T> |
38 void GetMiscInfoStream(const std::string& file_contents, const T** misc_info) { | 40 void GetMiscInfoStream(const std::string& file_contents, const T** misc_info) { |
39 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 41 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 172 |
171 ExpectMiscInfoEqual(&expected, observed); | 173 ExpectMiscInfoEqual(&expected, observed); |
172 } | 174 } |
173 | 175 |
174 TEST(MinidumpMiscInfoWriter, ProcessId) { | 176 TEST(MinidumpMiscInfoWriter, ProcessId) { |
175 MinidumpFileWriter minidump_file_writer; | 177 MinidumpFileWriter minidump_file_writer; |
176 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter()); | 178 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter()); |
177 | 179 |
178 const uint32_t kProcessId = 12345; | 180 const uint32_t kProcessId = 12345; |
179 | 181 |
180 misc_info_writer->SetProcessId(kProcessId); | 182 misc_info_writer->SetProcessID(kProcessId); |
181 | 183 |
182 minidump_file_writer.AddStream(misc_info_writer.Pass()); | 184 minidump_file_writer.AddStream(misc_info_writer.Pass()); |
183 | 185 |
184 StringFileWriter file_writer; | 186 StringFileWriter file_writer; |
185 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 187 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
186 | 188 |
187 const MINIDUMP_MISC_INFO* observed; | 189 const MINIDUMP_MISC_INFO* observed; |
188 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); | 190 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); |
189 | 191 |
190 MINIDUMP_MISC_INFO expected = {}; | 192 MINIDUMP_MISC_INFO expected = {}; |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 const uint32_t kTimeZoneId = 2; | 530 const uint32_t kTimeZoneId = 2; |
529 const int32_t kBias = 300; | 531 const int32_t kBias = 300; |
530 const char kStandardName[] = "EST"; | 532 const char kStandardName[] = "EST"; |
531 const int32_t kStandardBias = 0; | 533 const int32_t kStandardBias = 0; |
532 const char kDaylightName[] = "EDT"; | 534 const char kDaylightName[] = "EDT"; |
533 const int32_t kDaylightBias = -60; | 535 const int32_t kDaylightBias = -60; |
534 const SYSTEMTIME kSystemTimeZero = {}; | 536 const SYSTEMTIME kSystemTimeZero = {}; |
535 const char kBuildString[] = "build string"; | 537 const char kBuildString[] = "build string"; |
536 const char kDebugBuildString[] = "debug build string"; | 538 const char kDebugBuildString[] = "debug build string"; |
537 | 539 |
538 misc_info_writer->SetProcessId(kProcessId); | 540 misc_info_writer->SetProcessID(kProcessId); |
539 misc_info_writer->SetProcessTimes( | 541 misc_info_writer->SetProcessTimes( |
540 kProcessCreateTime, kProcessUserTime, kProcessKernelTime); | 542 kProcessCreateTime, kProcessUserTime, kProcessKernelTime); |
541 misc_info_writer->SetProcessorPowerInfo(kProcessorMaxMhz, | 543 misc_info_writer->SetProcessorPowerInfo(kProcessorMaxMhz, |
542 kProcessorCurrentMhz, | 544 kProcessorCurrentMhz, |
543 kProcessorMhzLimit, | 545 kProcessorMhzLimit, |
544 kProcessorMaxIdleState, | 546 kProcessorMaxIdleState, |
545 kProcessorCurrentIdleState); | 547 kProcessorCurrentIdleState); |
546 misc_info_writer->SetProcessIntegrityLevel(kProcessIntegrityLevel); | 548 misc_info_writer->SetProcessIntegrityLevel(kProcessIntegrityLevel); |
547 misc_info_writer->SetProcessExecuteFlags(kProcessExecuteFlags); | 549 misc_info_writer->SetProcessExecuteFlags(kProcessExecuteFlags); |
548 misc_info_writer->SetProtectedProcess(kProtectedProcess); | 550 misc_info_writer->SetProtectedProcess(kProtectedProcess); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 build_string_utf16.c_str(), | 607 build_string_utf16.c_str(), |
606 arraysize(expected.BuildString)); | 608 arraysize(expected.BuildString)); |
607 string16 debug_build_string_utf16 = base::UTF8ToUTF16(kDebugBuildString); | 609 string16 debug_build_string_utf16 = base::UTF8ToUTF16(kDebugBuildString); |
608 c16lcpy(expected.DbgBldStr, | 610 c16lcpy(expected.DbgBldStr, |
609 debug_build_string_utf16.c_str(), | 611 debug_build_string_utf16.c_str(), |
610 arraysize(expected.DbgBldStr)); | 612 arraysize(expected.DbgBldStr)); |
611 | 613 |
612 ExpectMiscInfoEqual(&expected, observed); | 614 ExpectMiscInfoEqual(&expected, observed); |
613 } | 615 } |
614 | 616 |
| 617 TEST(MinidumpMiscInfoWriter, InitializeFromSnapshot) { |
| 618 MINIDUMP_MISC_INFO_4 expect_misc_info = {}; |
| 619 |
| 620 const char kStandardTimeName[] = "EST"; |
| 621 const char kDaylightTimeName[] = "EDT"; |
| 622 const char kOSVersionFull[] = |
| 623 "Mac OS X 10.9.5 (13F34); " |
| 624 "Darwin 13.4.0 Darwin Kernel Version 13.4.0: " |
| 625 "Sun Aug 17 19:50:11 PDT 2014; " |
| 626 "root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"; |
| 627 const char kMachineDescription[] = "MacBookPro11,3 (Mac-2BD1B31983FE1663)"; |
| 628 string16 standard_time_name_utf16 = base::UTF8ToUTF16(kStandardTimeName); |
| 629 string16 daylight_time_name_utf16 = base::UTF8ToUTF16(kDaylightTimeName); |
| 630 string16 build_string_utf16 = base::UTF8ToUTF16( |
| 631 std::string(kOSVersionFull) + "; " + kMachineDescription); |
| 632 std::string debug_build_string = internal::MinidumpMiscInfoDebugBuildString(); |
| 633 EXPECT_FALSE(debug_build_string.empty()); |
| 634 string16 debug_build_string_utf16 = base::UTF8ToUTF16(debug_build_string); |
| 635 |
| 636 expect_misc_info.SizeOfInfo = sizeof(expect_misc_info); |
| 637 expect_misc_info.Flags1 = MINIDUMP_MISC1_PROCESS_ID | |
| 638 MINIDUMP_MISC1_PROCESS_TIMES | |
| 639 MINIDUMP_MISC1_PROCESSOR_POWER_INFO | |
| 640 MINIDUMP_MISC3_TIMEZONE | |
| 641 MINIDUMP_MISC4_BUILDSTRING; |
| 642 expect_misc_info.ProcessId = 12345; |
| 643 expect_misc_info.ProcessCreateTime = 0x555c7740; |
| 644 expect_misc_info.ProcessUserTime = 60; |
| 645 expect_misc_info.ProcessKernelTime = 15; |
| 646 expect_misc_info.ProcessorCurrentMhz = 2800; |
| 647 expect_misc_info.ProcessorMaxMhz = 2800; |
| 648 expect_misc_info.TimeZoneId = 1; |
| 649 expect_misc_info.TimeZone.Bias = 300; |
| 650 c16lcpy(expect_misc_info.TimeZone.StandardName, |
| 651 standard_time_name_utf16.c_str(), |
| 652 arraysize(expect_misc_info.TimeZone.StandardName)); |
| 653 expect_misc_info.TimeZone.StandardBias = 0; |
| 654 c16lcpy(expect_misc_info.TimeZone.DaylightName, |
| 655 daylight_time_name_utf16.c_str(), |
| 656 arraysize(expect_misc_info.TimeZone.DaylightName)); |
| 657 expect_misc_info.TimeZone.DaylightBias = -60; |
| 658 c16lcpy(expect_misc_info.BuildString, |
| 659 build_string_utf16.c_str(), |
| 660 arraysize(expect_misc_info.BuildString)); |
| 661 c16lcpy(expect_misc_info.DbgBldStr, |
| 662 debug_build_string_utf16.c_str(), |
| 663 arraysize(expect_misc_info.DbgBldStr)); |
| 664 |
| 665 const timeval kStartTime = { expect_misc_info.ProcessCreateTime, 0 }; |
| 666 const timeval kUserCPUTime = { expect_misc_info.ProcessUserTime, 0 }; |
| 667 const timeval kSystemCPUTime = { expect_misc_info.ProcessKernelTime, 0 }; |
| 668 |
| 669 TestProcessSnapshot process_snapshot; |
| 670 process_snapshot.SetProcessID(expect_misc_info.ProcessId); |
| 671 process_snapshot.SetProcessStartTime(kStartTime); |
| 672 process_snapshot.SetProcessCPUTimes(kUserCPUTime, kSystemCPUTime); |
| 673 |
| 674 auto system_snapshot = make_scoped_ptr(new TestSystemSnapshot()); |
| 675 const uint64_t kHzPerMHz = 1E6; |
| 676 system_snapshot->SetCPUFrequency( |
| 677 expect_misc_info.ProcessorCurrentMhz * kHzPerMHz, |
| 678 expect_misc_info.ProcessorMaxMhz * kHzPerMHz); |
| 679 system_snapshot->SetTimeZone(SystemSnapshot::kObservingStandardTime, |
| 680 expect_misc_info.TimeZone.Bias * -60, |
| 681 (expect_misc_info.TimeZone.Bias + |
| 682 expect_misc_info.TimeZone.DaylightBias) * -60, |
| 683 kStandardTimeName, |
| 684 kDaylightTimeName); |
| 685 system_snapshot->SetOSVersionFull(kOSVersionFull); |
| 686 system_snapshot->SetMachineDescription(kMachineDescription); |
| 687 |
| 688 process_snapshot.SetSystem(system_snapshot.Pass()); |
| 689 |
| 690 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter()); |
| 691 misc_info_writer->InitializeFromSnapshot(&process_snapshot); |
| 692 |
| 693 MinidumpFileWriter minidump_file_writer; |
| 694 minidump_file_writer.AddStream(misc_info_writer.Pass()); |
| 695 |
| 696 StringFileWriter file_writer; |
| 697 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 698 |
| 699 const MINIDUMP_MISC_INFO_4* misc_info; |
| 700 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &misc_info)); |
| 701 |
| 702 ExpectMiscInfoEqual(&expect_misc_info, misc_info); |
| 703 } |
| 704 |
615 } // namespace | 705 } // namespace |
616 } // namespace test | 706 } // namespace test |
617 } // namespace crashpad | 707 } // namespace crashpad |
OLD | NEW |