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, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 EXPECT_EQ(kCSDVersionOffset, (*system_info)->CSDVersionRva); | 67 EXPECT_EQ(kCSDVersionOffset, (*system_info)->CSDVersionRva); |
68 | 68 |
69 *csd_version = | 69 *csd_version = |
70 MinidumpStringAtRVA(file_contents, (*system_info)->CSDVersionRva); | 70 MinidumpStringAtRVA(file_contents, (*system_info)->CSDVersionRva); |
71 EXPECT_EQ(kCSDVersionBytes, (*csd_version)->Length); | 71 EXPECT_EQ(kCSDVersionBytes, (*csd_version)->Length); |
72 } | 72 } |
73 | 73 |
74 TEST(MinidumpSystemInfoWriter, Empty) { | 74 TEST(MinidumpSystemInfoWriter, Empty) { |
75 MinidumpFileWriter minidump_file_writer; | 75 MinidumpFileWriter minidump_file_writer; |
76 MinidumpSystemInfoWriter system_info_writer; | 76 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
77 | 77 |
78 system_info_writer.SetCSDVersion(std::string()); | 78 system_info_writer->SetCSDVersion(std::string()); |
79 | 79 |
80 minidump_file_writer.AddStream(&system_info_writer); | 80 minidump_file_writer.AddStream(system_info_writer.Pass()); |
81 | 81 |
82 StringFileWriter file_writer; | 82 StringFileWriter file_writer; |
83 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 83 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
84 | 84 |
85 const MINIDUMP_SYSTEM_INFO* system_info; | 85 const MINIDUMP_SYSTEM_INFO* system_info; |
86 const MINIDUMP_STRING* csd_version; | 86 const MINIDUMP_STRING* csd_version; |
87 | 87 |
88 ASSERT_NO_FATAL_FAILURE( | 88 ASSERT_NO_FATAL_FAILURE( |
89 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); | 89 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); |
90 | 90 |
(...skipping 15 matching lines...) Expand all Loading... |
106 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.FeatureInformation); | 106 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.FeatureInformation); |
107 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.AMDExtendedCpuFeatures); | 107 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.AMDExtendedCpuFeatures); |
108 EXPECT_EQ(0u, system_info->Cpu.OtherCpuInfo.ProcessorFeatures[0]); | 108 EXPECT_EQ(0u, system_info->Cpu.OtherCpuInfo.ProcessorFeatures[0]); |
109 EXPECT_EQ(0u, system_info->Cpu.OtherCpuInfo.ProcessorFeatures[1]); | 109 EXPECT_EQ(0u, system_info->Cpu.OtherCpuInfo.ProcessorFeatures[1]); |
110 | 110 |
111 EXPECT_EQ('\0', csd_version->Buffer[0]); | 111 EXPECT_EQ('\0', csd_version->Buffer[0]); |
112 } | 112 } |
113 | 113 |
114 TEST(MinidumpSystemInfoWriter, X86_Win) { | 114 TEST(MinidumpSystemInfoWriter, X86_Win) { |
115 MinidumpFileWriter minidump_file_writer; | 115 MinidumpFileWriter minidump_file_writer; |
116 MinidumpSystemInfoWriter system_info_writer; | 116 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
117 | 117 |
118 const MinidumpCPUArchitecture kCPUArchitecture = kMinidumpCPUArchitectureX86; | 118 const MinidumpCPUArchitecture kCPUArchitecture = kMinidumpCPUArchitectureX86; |
119 const uint16_t kCPULevel = 0x0010; | 119 const uint16_t kCPULevel = 0x0010; |
120 const uint16_t kCPURevision = 0x0602; | 120 const uint16_t kCPURevision = 0x0602; |
121 const uint8_t kCPUCount = 1; | 121 const uint8_t kCPUCount = 1; |
122 const MinidumpOS kOS = kMinidumpOSWin32NT; | 122 const MinidumpOS kOS = kMinidumpOSWin32NT; |
123 const MinidumpOSType kOSType = kMinidumpOSTypeWorkstation; | 123 const MinidumpOSType kOSType = kMinidumpOSTypeWorkstation; |
124 const uint32_t kOSVersionMajor = 6; | 124 const uint32_t kOSVersionMajor = 6; |
125 const uint32_t kOSVersionMinor = 1; | 125 const uint32_t kOSVersionMinor = 1; |
126 const uint32_t kOSVersionBuild = 7601; | 126 const uint32_t kOSVersionBuild = 7601; |
127 const char kCSDVersion[] = "Service Pack 1"; | 127 const char kCSDVersion[] = "Service Pack 1"; |
128 const uint16_t kSuiteMask = VER_SUITE_SINGLEUSERTS; | 128 const uint16_t kSuiteMask = VER_SUITE_SINGLEUSERTS; |
129 const char kCPUVendor[] = "AuthenticAMD"; | 129 const char kCPUVendor[] = "AuthenticAMD"; |
130 const uint32_t kCPUVersion = 0x00100f62; | 130 const uint32_t kCPUVersion = 0x00100f62; |
131 const uint32_t kCPUFeatures = 0x078bfbff; | 131 const uint32_t kCPUFeatures = 0x078bfbff; |
132 const uint32_t kAMDFeatures = 0xefd3fbff; | 132 const uint32_t kAMDFeatures = 0xefd3fbff; |
133 | 133 |
134 uint32_t cpu_vendor_registers[3]; | 134 uint32_t cpu_vendor_registers[3]; |
135 ASSERT_EQ(sizeof(cpu_vendor_registers), strlen(kCPUVendor)); | 135 ASSERT_EQ(sizeof(cpu_vendor_registers), strlen(kCPUVendor)); |
136 memcpy(cpu_vendor_registers, kCPUVendor, sizeof(cpu_vendor_registers)); | 136 memcpy(cpu_vendor_registers, kCPUVendor, sizeof(cpu_vendor_registers)); |
137 | 137 |
138 system_info_writer.SetCPUArchitecture(kCPUArchitecture); | 138 system_info_writer->SetCPUArchitecture(kCPUArchitecture); |
139 system_info_writer.SetCPULevelAndRevision(kCPULevel, kCPURevision); | 139 system_info_writer->SetCPULevelAndRevision(kCPULevel, kCPURevision); |
140 system_info_writer.SetCPUCount(kCPUCount); | 140 system_info_writer->SetCPUCount(kCPUCount); |
141 system_info_writer.SetOS(kOS); | 141 system_info_writer->SetOS(kOS); |
142 system_info_writer.SetOSType(kMinidumpOSTypeWorkstation); | 142 system_info_writer->SetOSType(kMinidumpOSTypeWorkstation); |
143 system_info_writer.SetOSVersion( | 143 system_info_writer->SetOSVersion( |
144 kOSVersionMajor, kOSVersionMinor, kOSVersionBuild); | 144 kOSVersionMajor, kOSVersionMinor, kOSVersionBuild); |
145 system_info_writer.SetCSDVersion(kCSDVersion); | 145 system_info_writer->SetCSDVersion(kCSDVersion); |
146 system_info_writer.SetSuiteMask(kSuiteMask); | 146 system_info_writer->SetSuiteMask(kSuiteMask); |
147 system_info_writer.SetCPUX86VendorString(kCPUVendor); | 147 system_info_writer->SetCPUX86VendorString(kCPUVendor); |
148 system_info_writer.SetCPUX86VersionAndFeatures(kCPUVersion, kCPUFeatures); | 148 system_info_writer->SetCPUX86VersionAndFeatures(kCPUVersion, kCPUFeatures); |
149 system_info_writer.SetCPUX86AMDExtendedFeatures(kAMDFeatures); | 149 system_info_writer->SetCPUX86AMDExtendedFeatures(kAMDFeatures); |
150 | 150 |
151 minidump_file_writer.AddStream(&system_info_writer); | 151 minidump_file_writer.AddStream(system_info_writer.Pass()); |
152 | 152 |
153 StringFileWriter file_writer; | 153 StringFileWriter file_writer; |
154 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 154 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
155 | 155 |
156 const MINIDUMP_SYSTEM_INFO* system_info; | 156 const MINIDUMP_SYSTEM_INFO* system_info; |
157 const MINIDUMP_STRING* csd_version; | 157 const MINIDUMP_STRING* csd_version; |
158 | 158 |
159 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream( | 159 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream( |
160 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version)); | 160 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version)); |
161 | 161 |
(...skipping 14 matching lines...) Expand all Loading... |
176 EXPECT_EQ(kCPUFeatures, system_info->Cpu.X86CpuInfo.FeatureInformation); | 176 EXPECT_EQ(kCPUFeatures, system_info->Cpu.X86CpuInfo.FeatureInformation); |
177 EXPECT_EQ(kAMDFeatures, system_info->Cpu.X86CpuInfo.AMDExtendedCpuFeatures); | 177 EXPECT_EQ(kAMDFeatures, system_info->Cpu.X86CpuInfo.AMDExtendedCpuFeatures); |
178 | 178 |
179 for (size_t index = 0; index < strlen(kCSDVersion); ++index) { | 179 for (size_t index = 0; index < strlen(kCSDVersion); ++index) { |
180 EXPECT_EQ(kCSDVersion[index], csd_version->Buffer[index]) << index; | 180 EXPECT_EQ(kCSDVersion[index], csd_version->Buffer[index]) << index; |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 TEST(MinidumpSystemInfoWriter, X86_64_Mac) { | 184 TEST(MinidumpSystemInfoWriter, X86_64_Mac) { |
185 MinidumpFileWriter minidump_file_writer; | 185 MinidumpFileWriter minidump_file_writer; |
186 MinidumpSystemInfoWriter system_info_writer; | 186 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
187 | 187 |
188 const MinidumpCPUArchitecture kCPUArchitecture = | 188 const MinidumpCPUArchitecture kCPUArchitecture = |
189 kMinidumpCPUArchitectureAMD64; | 189 kMinidumpCPUArchitectureAMD64; |
190 const uint16_t kCPULevel = 0x0006; | 190 const uint16_t kCPULevel = 0x0006; |
191 const uint16_t kCPURevision = 0x3a09; | 191 const uint16_t kCPURevision = 0x3a09; |
192 const uint8_t kCPUCount = 8; | 192 const uint8_t kCPUCount = 8; |
193 const MinidumpOS kOS = kMinidumpOSMacOSX; | 193 const MinidumpOS kOS = kMinidumpOSMacOSX; |
194 const MinidumpOSType kOSType = kMinidumpOSTypeWorkstation; | 194 const MinidumpOSType kOSType = kMinidumpOSTypeWorkstation; |
195 const uint32_t kOSVersionMajor = 10; | 195 const uint32_t kOSVersionMajor = 10; |
196 const uint32_t kOSVersionMinor = 9; | 196 const uint32_t kOSVersionMinor = 9; |
197 const uint32_t kOSVersionBuild = 4; | 197 const uint32_t kOSVersionBuild = 4; |
198 const char kCSDVersion[] = "13E28"; | 198 const char kCSDVersion[] = "13E28"; |
199 const uint64_t kCPUFeatures[2] = {0x10427f4c, 0x00000000}; | 199 const uint64_t kCPUFeatures[2] = {0x10427f4c, 0x00000000}; |
200 | 200 |
201 system_info_writer.SetCPUArchitecture(kCPUArchitecture); | 201 system_info_writer->SetCPUArchitecture(kCPUArchitecture); |
202 system_info_writer.SetCPULevelAndRevision(kCPULevel, kCPURevision); | 202 system_info_writer->SetCPULevelAndRevision(kCPULevel, kCPURevision); |
203 system_info_writer.SetCPUCount(kCPUCount); | 203 system_info_writer->SetCPUCount(kCPUCount); |
204 system_info_writer.SetOS(kOS); | 204 system_info_writer->SetOS(kOS); |
205 system_info_writer.SetOSType(kMinidumpOSTypeWorkstation); | 205 system_info_writer->SetOSType(kMinidumpOSTypeWorkstation); |
206 system_info_writer.SetOSVersion( | 206 system_info_writer->SetOSVersion( |
207 kOSVersionMajor, kOSVersionMinor, kOSVersionBuild); | 207 kOSVersionMajor, kOSVersionMinor, kOSVersionBuild); |
208 system_info_writer.SetCSDVersion(kCSDVersion); | 208 system_info_writer->SetCSDVersion(kCSDVersion); |
209 system_info_writer.SetCPUOtherFeatures(kCPUFeatures[0], kCPUFeatures[1]); | 209 system_info_writer->SetCPUOtherFeatures(kCPUFeatures[0], kCPUFeatures[1]); |
210 | 210 |
211 minidump_file_writer.AddStream(&system_info_writer); | 211 minidump_file_writer.AddStream(system_info_writer.Pass()); |
212 | 212 |
213 StringFileWriter file_writer; | 213 StringFileWriter file_writer; |
214 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 214 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
215 | 215 |
216 const MINIDUMP_SYSTEM_INFO* system_info; | 216 const MINIDUMP_SYSTEM_INFO* system_info; |
217 const MINIDUMP_STRING* csd_version; | 217 const MINIDUMP_STRING* csd_version; |
218 | 218 |
219 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream( | 219 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream( |
220 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version)); | 220 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version)); |
221 | 221 |
(...skipping 11 matching lines...) Expand all Loading... |
233 system_info->Cpu.OtherCpuInfo.ProcessorFeatures[0]); | 233 system_info->Cpu.OtherCpuInfo.ProcessorFeatures[0]); |
234 EXPECT_EQ(kCPUFeatures[1], | 234 EXPECT_EQ(kCPUFeatures[1], |
235 system_info->Cpu.OtherCpuInfo.ProcessorFeatures[1]); | 235 system_info->Cpu.OtherCpuInfo.ProcessorFeatures[1]); |
236 } | 236 } |
237 | 237 |
238 TEST(MinidumpSystemInfoWriter, X86_CPUVendorFromRegisters) { | 238 TEST(MinidumpSystemInfoWriter, X86_CPUVendorFromRegisters) { |
239 // MinidumpSystemInfoWriter.X86_Win already tested SetCPUX86VendorString(). | 239 // MinidumpSystemInfoWriter.X86_Win already tested SetCPUX86VendorString(). |
240 // This test exercises SetCPUX86Vendor() to set the vendor from register | 240 // This test exercises SetCPUX86Vendor() to set the vendor from register |
241 // values. | 241 // values. |
242 MinidumpFileWriter minidump_file_writer; | 242 MinidumpFileWriter minidump_file_writer; |
243 MinidumpSystemInfoWriter system_info_writer; | 243 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
244 | 244 |
245 const MinidumpCPUArchitecture kCPUArchitecture = kMinidumpCPUArchitectureX86; | 245 const MinidumpCPUArchitecture kCPUArchitecture = kMinidumpCPUArchitectureX86; |
246 const uint32_t kCPUVendor[] = {'uneG', 'Ieni', 'letn'}; | 246 const uint32_t kCPUVendor[] = {'uneG', 'Ieni', 'letn'}; |
247 | 247 |
248 system_info_writer.SetCPUArchitecture(kCPUArchitecture); | 248 system_info_writer->SetCPUArchitecture(kCPUArchitecture); |
249 system_info_writer.SetCPUX86Vendor( | 249 system_info_writer->SetCPUX86Vendor( |
250 kCPUVendor[0], kCPUVendor[1], kCPUVendor[2]); | 250 kCPUVendor[0], kCPUVendor[1], kCPUVendor[2]); |
251 system_info_writer.SetCSDVersion(std::string()); | 251 system_info_writer->SetCSDVersion(std::string()); |
252 | 252 |
253 minidump_file_writer.AddStream(&system_info_writer); | 253 minidump_file_writer.AddStream(system_info_writer.Pass()); |
254 | 254 |
255 StringFileWriter file_writer; | 255 StringFileWriter file_writer; |
256 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 256 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
257 | 257 |
258 const MINIDUMP_SYSTEM_INFO* system_info; | 258 const MINIDUMP_SYSTEM_INFO* system_info; |
259 const MINIDUMP_STRING* csd_version; | 259 const MINIDUMP_STRING* csd_version; |
260 | 260 |
261 ASSERT_NO_FATAL_FAILURE( | 261 ASSERT_NO_FATAL_FAILURE( |
262 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); | 262 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); |
263 | 263 |
264 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); | 264 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); |
265 EXPECT_EQ(0u, system_info->ProcessorLevel); | 265 EXPECT_EQ(0u, system_info->ProcessorLevel); |
266 EXPECT_EQ(kCPUVendor[0], system_info->Cpu.X86CpuInfo.VendorId[0]); | 266 EXPECT_EQ(kCPUVendor[0], system_info->Cpu.X86CpuInfo.VendorId[0]); |
267 EXPECT_EQ(kCPUVendor[1], system_info->Cpu.X86CpuInfo.VendorId[1]); | 267 EXPECT_EQ(kCPUVendor[1], system_info->Cpu.X86CpuInfo.VendorId[1]); |
268 EXPECT_EQ(kCPUVendor[2], system_info->Cpu.X86CpuInfo.VendorId[2]); | 268 EXPECT_EQ(kCPUVendor[2], system_info->Cpu.X86CpuInfo.VendorId[2]); |
269 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.VersionInformation); | 269 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.VersionInformation); |
270 } | 270 } |
271 | 271 |
272 TEST(MinidumpSystemInfoWriterDeathTest, NoCSDVersion) { | 272 TEST(MinidumpSystemInfoWriterDeathTest, NoCSDVersion) { |
273 MinidumpFileWriter minidump_file_writer; | 273 MinidumpFileWriter minidump_file_writer; |
274 MinidumpSystemInfoWriter system_info_writer; | 274 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); |
275 minidump_file_writer.AddStream(&system_info_writer); | 275 minidump_file_writer.AddStream(system_info_writer.Pass()); |
276 | 276 |
277 StringFileWriter file_writer; | 277 StringFileWriter file_writer; |
278 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), | 278 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), |
279 "csd_version_"); | 279 "csd_version_"); |
280 } | 280 } |
281 | 281 |
282 } // namespace | 282 } // namespace |
283 } // namespace test | 283 } // namespace test |
284 } // namespace crashpad | 284 } // namespace crashpad |
OLD | NEW |