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 <windows.h> | 17 #include <windows.h> |
18 #include <dbghelp.h> | 18 #include <dbghelp.h> |
19 #include <string.h> | 19 #include <string.h> |
20 | 20 |
21 #include <string> | 21 #include <string> |
22 | 22 |
23 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
| 24 #include "base/compiler_specific.h" |
24 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
25 #include "base/strings/string16.h" | 26 #include "base/strings/string16.h" |
26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
27 #include "gtest/gtest.h" | 28 #include "gtest/gtest.h" |
28 #include "minidump/minidump_file_writer.h" | 29 #include "minidump/minidump_file_writer.h" |
29 #include "minidump/test/minidump_file_writer_test_util.h" | 30 #include "minidump/test/minidump_file_writer_test_util.h" |
30 #include "minidump/test/minidump_writable_test_util.h" | 31 #include "minidump/test/minidump_writable_test_util.h" |
31 #include "snapshot/test/test_process_snapshot.h" | 32 #include "snapshot/test/test_process_snapshot.h" |
32 #include "snapshot/test/test_system_snapshot.h" | 33 #include "snapshot/test/test_system_snapshot.h" |
33 #include "util/file/string_file_writer.h" | 34 #include "util/file/string_file_writer.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 EXPECT_EQ(expected->ProcessId, observed->ProcessId); | 93 EXPECT_EQ(expected->ProcessId, observed->ProcessId); |
93 EXPECT_EQ(expected->ProcessCreateTime, observed->ProcessCreateTime); | 94 EXPECT_EQ(expected->ProcessCreateTime, observed->ProcessCreateTime); |
94 EXPECT_EQ(expected->ProcessUserTime, observed->ProcessUserTime); | 95 EXPECT_EQ(expected->ProcessUserTime, observed->ProcessUserTime); |
95 EXPECT_EQ(expected->ProcessKernelTime, observed->ProcessKernelTime); | 96 EXPECT_EQ(expected->ProcessKernelTime, observed->ProcessKernelTime); |
96 } | 97 } |
97 | 98 |
98 template <> | 99 template <> |
99 void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_2>( | 100 void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_2>( |
100 const MINIDUMP_MISC_INFO_2* expected, | 101 const MINIDUMP_MISC_INFO_2* expected, |
101 const MINIDUMP_MISC_INFO_2* observed) { | 102 const MINIDUMP_MISC_INFO_2* observed) { |
102 ExpectMiscInfoEqual<MINIDUMP_MISC_INFO>(expected, observed); | 103 ExpectMiscInfoEqual<MINIDUMP_MISC_INFO>( |
| 104 reinterpret_cast<const MINIDUMP_MISC_INFO*>(expected), |
| 105 reinterpret_cast<const MINIDUMP_MISC_INFO*>(observed)); |
103 EXPECT_EQ(expected->ProcessorMaxMhz, observed->ProcessorMaxMhz); | 106 EXPECT_EQ(expected->ProcessorMaxMhz, observed->ProcessorMaxMhz); |
104 EXPECT_EQ(expected->ProcessorCurrentMhz, observed->ProcessorCurrentMhz); | 107 EXPECT_EQ(expected->ProcessorCurrentMhz, observed->ProcessorCurrentMhz); |
105 EXPECT_EQ(expected->ProcessorMhzLimit, observed->ProcessorMhzLimit); | 108 EXPECT_EQ(expected->ProcessorMhzLimit, observed->ProcessorMhzLimit); |
106 EXPECT_EQ(expected->ProcessorMaxIdleState, observed->ProcessorMaxIdleState); | 109 EXPECT_EQ(expected->ProcessorMaxIdleState, observed->ProcessorMaxIdleState); |
107 EXPECT_EQ(expected->ProcessorCurrentIdleState, | 110 EXPECT_EQ(expected->ProcessorCurrentIdleState, |
108 observed->ProcessorCurrentIdleState); | 111 observed->ProcessorCurrentIdleState); |
109 } | 112 } |
110 | 113 |
111 template <> | 114 template <> |
112 void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>( | 115 void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>( |
113 const MINIDUMP_MISC_INFO_3* expected, | 116 const MINIDUMP_MISC_INFO_3* expected, |
114 const MINIDUMP_MISC_INFO_3* observed) { | 117 const MINIDUMP_MISC_INFO_3* observed) { |
115 ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_2>(expected, observed); | 118 ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_2>( |
| 119 reinterpret_cast<const MINIDUMP_MISC_INFO_2*>(expected), |
| 120 reinterpret_cast<const MINIDUMP_MISC_INFO_2*>(observed)); |
116 EXPECT_EQ(expected->ProcessIntegrityLevel, observed->ProcessIntegrityLevel); | 121 EXPECT_EQ(expected->ProcessIntegrityLevel, observed->ProcessIntegrityLevel); |
117 EXPECT_EQ(expected->ProcessExecuteFlags, observed->ProcessExecuteFlags); | 122 EXPECT_EQ(expected->ProcessExecuteFlags, observed->ProcessExecuteFlags); |
118 EXPECT_EQ(expected->ProtectedProcess, observed->ProtectedProcess); | 123 EXPECT_EQ(expected->ProtectedProcess, observed->ProtectedProcess); |
119 EXPECT_EQ(expected->TimeZoneId, observed->TimeZoneId); | 124 EXPECT_EQ(expected->TimeZoneId, observed->TimeZoneId); |
120 EXPECT_EQ(expected->TimeZone.Bias, observed->TimeZone.Bias); | 125 EXPECT_EQ(expected->TimeZone.Bias, observed->TimeZone.Bias); |
121 { | 126 { |
122 SCOPED_TRACE("Standard"); | 127 SCOPED_TRACE("Standard"); |
123 ExpectNULPaddedString16Equal(expected->TimeZone.StandardName, | 128 ExpectNULPaddedString16Equal(expected->TimeZone.StandardName, |
124 observed->TimeZone.StandardName, | 129 observed->TimeZone.StandardName, |
125 arraysize(expected->TimeZone.StandardName)); | 130 arraysize(expected->TimeZone.StandardName)); |
126 ExpectSystemTimeEqual(&expected->TimeZone.StandardDate, | 131 ExpectSystemTimeEqual(&expected->TimeZone.StandardDate, |
127 &observed->TimeZone.StandardDate); | 132 &observed->TimeZone.StandardDate); |
128 EXPECT_EQ(expected->TimeZone.StandardBias, observed->TimeZone.StandardBias); | 133 EXPECT_EQ(expected->TimeZone.StandardBias, observed->TimeZone.StandardBias); |
129 } | 134 } |
130 { | 135 { |
131 SCOPED_TRACE("Daylight"); | 136 SCOPED_TRACE("Daylight"); |
132 ExpectNULPaddedString16Equal(expected->TimeZone.DaylightName, | 137 ExpectNULPaddedString16Equal(expected->TimeZone.DaylightName, |
133 observed->TimeZone.DaylightName, | 138 observed->TimeZone.DaylightName, |
134 arraysize(expected->TimeZone.DaylightName)); | 139 arraysize(expected->TimeZone.DaylightName)); |
135 ExpectSystemTimeEqual(&expected->TimeZone.DaylightDate, | 140 ExpectSystemTimeEqual(&expected->TimeZone.DaylightDate, |
136 &observed->TimeZone.DaylightDate); | 141 &observed->TimeZone.DaylightDate); |
137 EXPECT_EQ(expected->TimeZone.DaylightBias, observed->TimeZone.DaylightBias); | 142 EXPECT_EQ(expected->TimeZone.DaylightBias, observed->TimeZone.DaylightBias); |
138 } | 143 } |
139 } | 144 } |
140 | 145 |
141 template <> | 146 template <> |
142 void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_4>( | 147 void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_4>( |
143 const MINIDUMP_MISC_INFO_4* expected, | 148 const MINIDUMP_MISC_INFO_4* expected, |
144 const MINIDUMP_MISC_INFO_4* observed) { | 149 const MINIDUMP_MISC_INFO_4* observed) { |
145 ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>(expected, observed); | 150 ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>( |
| 151 reinterpret_cast<const MINIDUMP_MISC_INFO_3*>(expected), |
| 152 reinterpret_cast<const MINIDUMP_MISC_INFO_3*>(observed)); |
146 { | 153 { |
147 SCOPED_TRACE("BuildString"); | 154 SCOPED_TRACE("BuildString"); |
148 ExpectNULPaddedString16Equal(expected->BuildString, | 155 ExpectNULPaddedString16Equal(expected->BuildString, |
149 observed->BuildString, | 156 observed->BuildString, |
150 arraysize(expected->BuildString)); | 157 arraysize(expected->BuildString)); |
151 } | 158 } |
152 { | 159 { |
153 SCOPED_TRACE("DbgBldStr"); | 160 SCOPED_TRACE("DbgBldStr"); |
154 ExpectNULPaddedString16Equal(expected->DbgBldStr, | 161 ExpectNULPaddedString16Equal(expected->DbgBldStr, |
155 observed->DbgBldStr, | 162 observed->DbgBldStr, |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 392 |
386 TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) { | 393 TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) { |
387 // This test makes sure that the time zone name strings are truncated properly | 394 // This test makes sure that the time zone name strings are truncated properly |
388 // to the widths of their fields. | 395 // to the widths of their fields. |
389 | 396 |
390 MinidumpFileWriter minidump_file_writer; | 397 MinidumpFileWriter minidump_file_writer; |
391 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter()); | 398 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter()); |
392 | 399 |
393 const uint32_t kTimeZoneId = 2; | 400 const uint32_t kTimeZoneId = 2; |
394 const int32_t kBias = 300; | 401 const int32_t kBias = 300; |
395 std::string standard_name( | 402 MINIDUMP_MISC_INFO_N tmp; |
396 arraysize(decltype(MINIDUMP_MISC_INFO_N::TimeZone)::StandardName) + 1, | 403 ALLOW_UNUSED_LOCAL(tmp); |
397 's'); | 404 std::string standard_name(arraysize(tmp.TimeZone.StandardName) + 1, 's'); |
398 const int32_t kStandardBias = 0; | 405 const int32_t kStandardBias = 0; |
399 std::string daylight_name( | 406 std::string daylight_name(arraysize(tmp.TimeZone.DaylightName), 'd'); |
400 arraysize(decltype(MINIDUMP_MISC_INFO_N::TimeZone)::DaylightName), 'd'); | |
401 const int32_t kDaylightBias = -60; | 407 const int32_t kDaylightBias = -60; |
402 | 408 |
403 // Test using kSystemTimeZero, because not all platforms will be able to | 409 // Test using kSystemTimeZero, because not all platforms will be able to |
404 // provide daylight saving time transition times. | 410 // provide daylight saving time transition times. |
405 const SYSTEMTIME kSystemTimeZero = {}; | 411 const SYSTEMTIME kSystemTimeZero = {}; |
406 | 412 |
407 misc_info_writer->SetTimeZone(kTimeZoneId, | 413 misc_info_writer->SetTimeZone(kTimeZoneId, |
408 kBias, | 414 kBias, |
409 standard_name, | 415 standard_name, |
410 kSystemTimeZero, | 416 kSystemTimeZero, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 ExpectMiscInfoEqual(&expected, observed); | 483 ExpectMiscInfoEqual(&expected, observed); |
478 } | 484 } |
479 | 485 |
480 TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) { | 486 TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) { |
481 // This test makes sure that the build strings are truncated properly to the | 487 // This test makes sure that the build strings are truncated properly to the |
482 // widths of their fields. | 488 // widths of their fields. |
483 | 489 |
484 MinidumpFileWriter minidump_file_writer; | 490 MinidumpFileWriter minidump_file_writer; |
485 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter()); | 491 auto misc_info_writer = make_scoped_ptr(new MinidumpMiscInfoWriter()); |
486 | 492 |
487 std::string build_string(arraysize(MINIDUMP_MISC_INFO_N::BuildString) + 1, | 493 MINIDUMP_MISC_INFO_4 tmp; |
488 'B'); | 494 ALLOW_UNUSED_LOCAL(tmp); |
489 std::string debug_build_string(arraysize(MINIDUMP_MISC_INFO_N::DbgBldStr), | 495 std::string build_string(arraysize(tmp.BuildString) + 1, 'B'); |
490 'D'); | 496 std::string debug_build_string(arraysize(tmp.DbgBldStr), 'D'); |
491 | 497 |
492 misc_info_writer->SetBuildString(build_string, debug_build_string); | 498 misc_info_writer->SetBuildString(build_string, debug_build_string); |
493 | 499 |
494 minidump_file_writer.AddStream(misc_info_writer.Pass()); | 500 minidump_file_writer.AddStream(misc_info_writer.Pass()); |
495 | 501 |
496 StringFileWriter file_writer; | 502 StringFileWriter file_writer; |
497 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 503 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
498 | 504 |
499 const MINIDUMP_MISC_INFO_4* observed; | 505 const MINIDUMP_MISC_INFO_4* observed; |
500 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); | 506 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed)); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 arraysize(expect_misc_info.TimeZone.DaylightName)); | 669 arraysize(expect_misc_info.TimeZone.DaylightName)); |
664 expect_misc_info.TimeZone.DaylightBias = -60; | 670 expect_misc_info.TimeZone.DaylightBias = -60; |
665 c16lcpy(expect_misc_info.BuildString, | 671 c16lcpy(expect_misc_info.BuildString, |
666 build_string_utf16.c_str(), | 672 build_string_utf16.c_str(), |
667 arraysize(expect_misc_info.BuildString)); | 673 arraysize(expect_misc_info.BuildString)); |
668 c16lcpy(expect_misc_info.DbgBldStr, | 674 c16lcpy(expect_misc_info.DbgBldStr, |
669 debug_build_string_utf16.c_str(), | 675 debug_build_string_utf16.c_str(), |
670 arraysize(expect_misc_info.DbgBldStr)); | 676 arraysize(expect_misc_info.DbgBldStr)); |
671 | 677 |
672 const timeval kStartTime = | 678 const timeval kStartTime = |
673 { implicit_cast<time_t>(expect_misc_info.ProcessCreateTime), 0 }; | 679 { static_cast<time_t>(expect_misc_info.ProcessCreateTime), 0 }; |
674 const timeval kUserCPUTime = | 680 const timeval kUserCPUTime = |
675 { implicit_cast<time_t>(expect_misc_info.ProcessUserTime), 0 }; | 681 { static_cast<time_t>(expect_misc_info.ProcessUserTime), 0 }; |
676 const timeval kSystemCPUTime = | 682 const timeval kSystemCPUTime = |
677 { implicit_cast<time_t>(expect_misc_info.ProcessKernelTime), 0 }; | 683 { static_cast<time_t>(expect_misc_info.ProcessKernelTime), 0 }; |
678 | 684 |
679 TestProcessSnapshot process_snapshot; | 685 TestProcessSnapshot process_snapshot; |
680 process_snapshot.SetProcessID(expect_misc_info.ProcessId); | 686 process_snapshot.SetProcessID(expect_misc_info.ProcessId); |
681 process_snapshot.SetProcessStartTime(kStartTime); | 687 process_snapshot.SetProcessStartTime(kStartTime); |
682 process_snapshot.SetProcessCPUTimes(kUserCPUTime, kSystemCPUTime); | 688 process_snapshot.SetProcessCPUTimes(kUserCPUTime, kSystemCPUTime); |
683 | 689 |
684 auto system_snapshot = make_scoped_ptr(new TestSystemSnapshot()); | 690 auto system_snapshot = make_scoped_ptr(new TestSystemSnapshot()); |
685 const uint64_t kHzPerMHz = 1E6; | 691 const uint64_t kHzPerMHz = static_cast<uint64_t>(1E6); |
686 system_snapshot->SetCPUFrequency( | 692 system_snapshot->SetCPUFrequency( |
687 expect_misc_info.ProcessorCurrentMhz * kHzPerMHz, | 693 expect_misc_info.ProcessorCurrentMhz * kHzPerMHz, |
688 expect_misc_info.ProcessorMaxMhz * kHzPerMHz); | 694 expect_misc_info.ProcessorMaxMhz * kHzPerMHz); |
689 system_snapshot->SetTimeZone(SystemSnapshot::kObservingStandardTime, | 695 system_snapshot->SetTimeZone(SystemSnapshot::kObservingStandardTime, |
690 expect_misc_info.TimeZone.Bias * -60, | 696 expect_misc_info.TimeZone.Bias * -60, |
691 (expect_misc_info.TimeZone.Bias + | 697 (expect_misc_info.TimeZone.Bias + |
692 expect_misc_info.TimeZone.DaylightBias) * -60, | 698 expect_misc_info.TimeZone.DaylightBias) * -60, |
693 kStandardTimeName, | 699 kStandardTimeName, |
694 kDaylightTimeName); | 700 kDaylightTimeName); |
695 system_snapshot->SetOSVersionFull(kOSVersionFull); | 701 system_snapshot->SetOSVersionFull(kOSVersionFull); |
(...skipping 12 matching lines...) Expand all Loading... |
708 | 714 |
709 const MINIDUMP_MISC_INFO_4* misc_info; | 715 const MINIDUMP_MISC_INFO_4* misc_info; |
710 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &misc_info)); | 716 ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &misc_info)); |
711 | 717 |
712 ExpectMiscInfoEqual(&expect_misc_info, misc_info); | 718 ExpectMiscInfoEqual(&expect_misc_info, misc_info); |
713 } | 719 } |
714 | 720 |
715 } // namespace | 721 } // namespace |
716 } // namespace test | 722 } // namespace test |
717 } // namespace crashpad | 723 } // namespace crashpad |
OLD | NEW |