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 <windows.h> | 17 #include <windows.h> |
18 #include <dbghelp.h> | 18 #include <dbghelp.h> |
19 #include <string.h> | 19 #include <string.h> |
20 #include <sys/types.h> | 20 #include <sys/types.h> |
21 | 21 |
22 #include <algorithm> | 22 #include <algorithm> |
23 #include <string> | 23 #include <string> |
24 | 24 |
25 #include "base/compiler_specific.h" | |
25 #include "gtest/gtest.h" | 26 #include "gtest/gtest.h" |
26 #include "minidump/minidump_file_writer.h" | 27 #include "minidump/minidump_file_writer.h" |
27 #include "minidump/test/minidump_file_writer_test_util.h" | 28 #include "minidump/test/minidump_file_writer_test_util.h" |
28 #include "minidump/test/minidump_string_writer_test_util.h" | 29 #include "minidump/test/minidump_string_writer_test_util.h" |
29 #include "minidump/test/minidump_writable_test_util.h" | 30 #include "minidump/test/minidump_writable_test_util.h" |
30 #include "snapshot/test/test_system_snapshot.h" | 31 #include "snapshot/test/test_system_snapshot.h" |
31 #include "util/file/string_file_writer.h" | 32 #include "util/file/string_file_writer.h" |
32 | 33 |
33 namespace crashpad { | 34 namespace crashpad { |
34 namespace test { | 35 namespace test { |
35 namespace { | 36 namespace { |
36 | 37 |
37 void GetSystemInfoStream(const std::string& file_contents, | 38 void GetSystemInfoStream(const std::string& file_contents, |
38 size_t csd_version_length, | 39 size_t csd_version_length, |
39 const MINIDUMP_SYSTEM_INFO** system_info, | 40 const MINIDUMP_SYSTEM_INFO** system_info, |
40 const MINIDUMP_STRING** csd_version) { | 41 const MINIDUMP_STRING** csd_version) { |
41 // The expected number of bytes for the CSD version’s MINIDUMP_STRING::Buffer. | 42 // The expected number of bytes for the CSD version’s MINIDUMP_STRING::Buffer. |
42 const size_t kCSDVersionBytes = | 43 MINIDUMP_STRING tmp = {0}; |
Mark Mentovai
2015/02/05 17:13:02
Is the initialization required?
scottmg
2015/02/05 17:39:44
Yes, it otherwise complains that:
warning C4815:
| |
43 csd_version_length * sizeof(MINIDUMP_STRING::Buffer[0]); | 44 ALLOW_UNUSED_LOCAL(tmp); |
45 const size_t kCSDVersionBytes = csd_version_length * sizeof(tmp.Buffer[0]); | |
44 const size_t kCSDVersionBytesWithNUL = | 46 const size_t kCSDVersionBytesWithNUL = |
45 kCSDVersionBytes + sizeof(MINIDUMP_STRING::Buffer[0]); | 47 kCSDVersionBytes + sizeof(tmp.Buffer[0]); |
46 | 48 |
47 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 49 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
48 const size_t kSystemInfoStreamOffset = | 50 const size_t kSystemInfoStreamOffset = |
49 kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); | 51 kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY); |
50 const size_t kCSDVersionOffset = | 52 const size_t kCSDVersionOffset = |
51 kSystemInfoStreamOffset + sizeof(MINIDUMP_SYSTEM_INFO); | 53 kSystemInfoStreamOffset + sizeof(MINIDUMP_SYSTEM_INFO); |
52 const size_t kFileSize = | 54 const size_t kFileSize = |
53 kCSDVersionOffset + sizeof(MINIDUMP_STRING) + kCSDVersionBytesWithNUL; | 55 kCSDVersionOffset + sizeof(MINIDUMP_STRING) + kCSDVersionBytesWithNUL; |
54 | 56 |
55 ASSERT_EQ(kFileSize, file_contents.size()); | 57 ASSERT_EQ(kFileSize, file_contents.size()); |
(...skipping 22 matching lines...) Expand all Loading... | |
78 MinidumpFileWriter minidump_file_writer; | 80 MinidumpFileWriter minidump_file_writer; |
79 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); | 81 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
80 | 82 |
81 system_info_writer->SetCSDVersion(std::string()); | 83 system_info_writer->SetCSDVersion(std::string()); |
82 | 84 |
83 minidump_file_writer.AddStream(system_info_writer.Pass()); | 85 minidump_file_writer.AddStream(system_info_writer.Pass()); |
84 | 86 |
85 StringFileWriter file_writer; | 87 StringFileWriter file_writer; |
86 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 88 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
87 | 89 |
88 const MINIDUMP_SYSTEM_INFO* system_info; | 90 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; |
89 const MINIDUMP_STRING* csd_version; | 91 const MINIDUMP_STRING* csd_version = nullptr; |
90 | 92 |
91 ASSERT_NO_FATAL_FAILURE( | 93 ASSERT_NO_FATAL_FAILURE( |
92 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); | 94 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); |
93 | 95 |
94 EXPECT_EQ(kMinidumpCPUArchitectureUnknown, | 96 EXPECT_EQ(kMinidumpCPUArchitectureUnknown, |
95 system_info->ProcessorArchitecture); | 97 system_info->ProcessorArchitecture); |
96 EXPECT_EQ(0u, system_info->ProcessorLevel); | 98 EXPECT_EQ(0u, system_info->ProcessorLevel); |
97 EXPECT_EQ(0u, system_info->ProcessorRevision); | 99 EXPECT_EQ(0u, system_info->ProcessorRevision); |
98 EXPECT_EQ(0u, system_info->NumberOfProcessors); | 100 EXPECT_EQ(0u, system_info->NumberOfProcessors); |
99 EXPECT_EQ(0u, system_info->ProductType); | 101 EXPECT_EQ(0u, system_info->ProductType); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 system_info_writer->SetSuiteMask(kSuiteMask); | 151 system_info_writer->SetSuiteMask(kSuiteMask); |
150 system_info_writer->SetCPUX86VendorString(kCPUVendor); | 152 system_info_writer->SetCPUX86VendorString(kCPUVendor); |
151 system_info_writer->SetCPUX86VersionAndFeatures(kCPUVersion, kCPUFeatures); | 153 system_info_writer->SetCPUX86VersionAndFeatures(kCPUVersion, kCPUFeatures); |
152 system_info_writer->SetCPUX86AMDExtendedFeatures(kAMDFeatures); | 154 system_info_writer->SetCPUX86AMDExtendedFeatures(kAMDFeatures); |
153 | 155 |
154 minidump_file_writer.AddStream(system_info_writer.Pass()); | 156 minidump_file_writer.AddStream(system_info_writer.Pass()); |
155 | 157 |
156 StringFileWriter file_writer; | 158 StringFileWriter file_writer; |
157 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 159 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
158 | 160 |
159 const MINIDUMP_SYSTEM_INFO* system_info; | 161 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; |
160 const MINIDUMP_STRING* csd_version; | 162 const MINIDUMP_STRING* csd_version = nullptr; |
161 | 163 |
162 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream( | 164 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream( |
163 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version)); | 165 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version)); |
164 | 166 |
165 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); | 167 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); |
166 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel); | 168 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel); |
167 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision); | 169 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision); |
168 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors); | 170 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors); |
169 EXPECT_EQ(kOSType, system_info->ProductType); | 171 EXPECT_EQ(kOSType, system_info->ProductType); |
170 EXPECT_EQ(kOSVersionMajor, system_info->MajorVersion); | 172 EXPECT_EQ(kOSVersionMajor, system_info->MajorVersion); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 system_info_writer->SetOSVersion( | 211 system_info_writer->SetOSVersion( |
210 kOSVersionMajor, kOSVersionMinor, kOSVersionBuild); | 212 kOSVersionMajor, kOSVersionMinor, kOSVersionBuild); |
211 system_info_writer->SetCSDVersion(kCSDVersion); | 213 system_info_writer->SetCSDVersion(kCSDVersion); |
212 system_info_writer->SetCPUOtherFeatures(kCPUFeatures[0], kCPUFeatures[1]); | 214 system_info_writer->SetCPUOtherFeatures(kCPUFeatures[0], kCPUFeatures[1]); |
213 | 215 |
214 minidump_file_writer.AddStream(system_info_writer.Pass()); | 216 minidump_file_writer.AddStream(system_info_writer.Pass()); |
215 | 217 |
216 StringFileWriter file_writer; | 218 StringFileWriter file_writer; |
217 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 219 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
218 | 220 |
219 const MINIDUMP_SYSTEM_INFO* system_info; | 221 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; |
220 const MINIDUMP_STRING* csd_version; | 222 const MINIDUMP_STRING* csd_version; |
221 | 223 |
222 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream( | 224 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream( |
223 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version)); | 225 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version)); |
224 | 226 |
225 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); | 227 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); |
226 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel); | 228 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel); |
227 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision); | 229 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision); |
228 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors); | 230 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors); |
229 EXPECT_EQ(kOSType, system_info->ProductType); | 231 EXPECT_EQ(kOSType, system_info->ProductType); |
(...skipping 21 matching lines...) Expand all Loading... | |
251 system_info_writer->SetCPUArchitecture(kCPUArchitecture); | 253 system_info_writer->SetCPUArchitecture(kCPUArchitecture); |
252 system_info_writer->SetCPUX86Vendor( | 254 system_info_writer->SetCPUX86Vendor( |
253 kCPUVendor[0], kCPUVendor[1], kCPUVendor[2]); | 255 kCPUVendor[0], kCPUVendor[1], kCPUVendor[2]); |
254 system_info_writer->SetCSDVersion(std::string()); | 256 system_info_writer->SetCSDVersion(std::string()); |
255 | 257 |
256 minidump_file_writer.AddStream(system_info_writer.Pass()); | 258 minidump_file_writer.AddStream(system_info_writer.Pass()); |
257 | 259 |
258 StringFileWriter file_writer; | 260 StringFileWriter file_writer; |
259 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 261 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
260 | 262 |
261 const MINIDUMP_SYSTEM_INFO* system_info; | 263 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; |
262 const MINIDUMP_STRING* csd_version; | 264 const MINIDUMP_STRING* csd_version; |
263 | 265 |
264 ASSERT_NO_FATAL_FAILURE( | 266 ASSERT_NO_FATAL_FAILURE( |
265 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); | 267 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); |
266 | 268 |
267 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); | 269 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); |
268 EXPECT_EQ(0u, system_info->ProcessorLevel); | 270 EXPECT_EQ(0u, system_info->ProcessorLevel); |
269 EXPECT_EQ(kCPUVendor[0], system_info->Cpu.X86CpuInfo.VendorId[0]); | 271 EXPECT_EQ(kCPUVendor[0], system_info->Cpu.X86CpuInfo.VendorId[0]); |
270 EXPECT_EQ(kCPUVendor[1], system_info->Cpu.X86CpuInfo.VendorId[1]); | 272 EXPECT_EQ(kCPUVendor[1], system_info->Cpu.X86CpuInfo.VendorId[1]); |
271 EXPECT_EQ(kCPUVendor[2], system_info->Cpu.X86CpuInfo.VendorId[2]); | 273 EXPECT_EQ(kCPUVendor[2], system_info->Cpu.X86CpuInfo.VendorId[2]); |
272 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.VersionInformation); | 274 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.VersionInformation); |
273 } | 275 } |
274 | 276 |
275 TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_X86) { | 277 TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_X86) { |
276 MINIDUMP_SYSTEM_INFO expect_system_info = {}; | 278 MINIDUMP_SYSTEM_INFO expect_system_info = {}; |
277 | 279 |
278 const uint16_t kCPUFamily = 6; | 280 const uint16_t kCPUFamily = 6; |
279 const uint8_t kCPUModel = 70; | 281 const uint8_t kCPUModel = 70; |
280 const uint8_t kCPUStepping = 1; | 282 const uint8_t kCPUStepping = 1; |
281 | 283 |
282 const uint8_t kCPUBasicFamily = | 284 const uint8_t kCPUBasicFamily = |
283 std::min(kCPUFamily, implicit_cast<uint16_t>(15)); | 285 static_cast<uint8_t>(std::min(kCPUFamily, static_cast<uint16_t>(15))); |
284 const uint8_t kCPUExtendedFamily = kCPUFamily - kCPUBasicFamily; | 286 const uint8_t kCPUExtendedFamily = kCPUFamily - kCPUBasicFamily; |
285 | 287 |
286 // These checks ensure that even if the constants above change, they represent | 288 // These checks ensure that even if the constants above change, they represent |
287 // something that can legitimately be encoded in the form used by cpuid 1 eax. | 289 // something that can legitimately be encoded in the form used by cpuid 1 eax. |
288 EXPECT_LE(kCPUFamily, 270); | 290 EXPECT_LE(kCPUFamily, 270); |
289 EXPECT_LE(kCPUStepping, 15); | 291 EXPECT_LE(kCPUStepping, 15); |
290 EXPECT_TRUE(kCPUBasicFamily == 6 || kCPUBasicFamily == 15 || kCPUModel <= 15); | 292 EXPECT_TRUE(kCPUBasicFamily == 6 || kCPUBasicFamily == 15 || kCPUModel <= 15); |
291 | 293 |
292 const uint8_t kCPUBasicModel = kCPUModel & 0xf; | 294 const uint8_t kCPUBasicModel = kCPUModel & 0xf; |
293 const uint8_t kCPUExtendedModel = kCPUModel >> 4; | 295 const uint8_t kCPUExtendedModel = kCPUModel >> 4; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 | 333 |
332 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); | 334 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
333 system_info_writer->InitializeFromSnapshot(&system_snapshot); | 335 system_info_writer->InitializeFromSnapshot(&system_snapshot); |
334 | 336 |
335 MinidumpFileWriter minidump_file_writer; | 337 MinidumpFileWriter minidump_file_writer; |
336 minidump_file_writer.AddStream(system_info_writer.Pass()); | 338 minidump_file_writer.AddStream(system_info_writer.Pass()); |
337 | 339 |
338 StringFileWriter file_writer; | 340 StringFileWriter file_writer; |
339 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 341 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
340 | 342 |
341 const MINIDUMP_SYSTEM_INFO* system_info; | 343 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; |
342 const MINIDUMP_STRING* csd_version; | 344 const MINIDUMP_STRING* csd_version = nullptr; |
343 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(), | 345 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(), |
344 strlen(kOSVersionBuild), | 346 strlen(kOSVersionBuild), |
345 &system_info, | 347 &system_info, |
346 &csd_version)); | 348 &csd_version)); |
347 | 349 |
348 EXPECT_EQ(expect_system_info.ProcessorArchitecture, | 350 EXPECT_EQ(expect_system_info.ProcessorArchitecture, |
349 system_info->ProcessorArchitecture); | 351 system_info->ProcessorArchitecture); |
350 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel); | 352 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel); |
351 EXPECT_EQ(expect_system_info.ProcessorRevision, | 353 EXPECT_EQ(expect_system_info.ProcessorRevision, |
352 system_info->ProcessorRevision); | 354 system_info->ProcessorRevision); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 | 428 |
427 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); | 429 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
428 system_info_writer->InitializeFromSnapshot(&system_snapshot); | 430 system_info_writer->InitializeFromSnapshot(&system_snapshot); |
429 | 431 |
430 MinidumpFileWriter minidump_file_writer; | 432 MinidumpFileWriter minidump_file_writer; |
431 minidump_file_writer.AddStream(system_info_writer.Pass()); | 433 minidump_file_writer.AddStream(system_info_writer.Pass()); |
432 | 434 |
433 StringFileWriter file_writer; | 435 StringFileWriter file_writer; |
434 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 436 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
435 | 437 |
436 const MINIDUMP_SYSTEM_INFO* system_info; | 438 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; |
437 const MINIDUMP_STRING* csd_version; | 439 const MINIDUMP_STRING* csd_version = nullptr; |
438 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(), | 440 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(), |
439 strlen(kOSVersionBuild), | 441 strlen(kOSVersionBuild), |
440 &system_info, | 442 &system_info, |
441 &csd_version)); | 443 &csd_version)); |
442 | 444 |
443 EXPECT_EQ(expect_system_info.ProcessorArchitecture, | 445 EXPECT_EQ(expect_system_info.ProcessorArchitecture, |
444 system_info->ProcessorArchitecture); | 446 system_info->ProcessorArchitecture); |
445 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel); | 447 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel); |
446 EXPECT_EQ(expect_system_info.ProcessorRevision, | 448 EXPECT_EQ(expect_system_info.ProcessorRevision, |
447 system_info->ProcessorRevision); | 449 system_info->ProcessorRevision); |
(...skipping 21 matching lines...) Expand all Loading... | |
469 minidump_file_writer.AddStream(system_info_writer.Pass()); | 471 minidump_file_writer.AddStream(system_info_writer.Pass()); |
470 | 472 |
471 StringFileWriter file_writer; | 473 StringFileWriter file_writer; |
472 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), | 474 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), |
473 "csd_version_"); | 475 "csd_version_"); |
474 } | 476 } |
475 | 477 |
476 } // namespace | 478 } // namespace |
477 } // namespace test | 479 } // namespace test |
478 } // namespace crashpad | 480 } // namespace crashpad |
OLD | NEW |