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

Side by Side Diff: minidump/minidump_system_info_writer_test.cc

Issue 454073002: Add MinidumpMiscInfoWriter and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 4 months 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 19
20 #include <string> 20 #include <string>
21 21
22 #include "gtest/gtest.h" 22 #include "gtest/gtest.h"
23 #include "minidump/minidump_file_writer.h" 23 #include "minidump/minidump_file_writer.h"
24 #include "util/file/string_file_writer.h" 24 #include "util/file/string_file_writer.h"
25 25
26 namespace { 26 namespace {
27 27
28 using namespace crashpad; 28 using namespace crashpad;
29 using namespace testing;
29 30
30 void GetSystemInfoStream(const std::string& file_contents, 31 void GetSystemInfoStream(const std::string& file_contents,
31 size_t csd_version_length, 32 size_t csd_version_length,
32 const MINIDUMP_SYSTEM_INFO** system_info, 33 const MINIDUMP_SYSTEM_INFO** system_info,
33 const MINIDUMP_STRING** csd_version) { 34 const MINIDUMP_STRING** csd_version) {
34 // The expected number of bytes for the CSD version’s MINIDUMP_STRING::Buffer. 35 // The expected number of bytes for the CSD version’s MINIDUMP_STRING::Buffer.
35 const size_t kCSDVersionBytes = 36 const size_t kCSDVersionBytes =
36 csd_version_length * sizeof(MINIDUMP_STRING::Buffer[0]); 37 csd_version_length * sizeof(MINIDUMP_STRING::Buffer[0]);
37 const size_t kCSDVersionBytesWithNUL = 38 const size_t kCSDVersionBytesWithNUL =
38 kCSDVersionBytes + sizeof(MINIDUMP_STRING::Buffer[0]); 39 kCSDVersionBytes + sizeof(MINIDUMP_STRING::Buffer[0]);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 86
86 minidump_file_writer.AddStream(&system_info_writer); 87 minidump_file_writer.AddStream(&system_info_writer);
87 88
88 StringFileWriter file_writer; 89 StringFileWriter file_writer;
89 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 90 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
90 91
91 const MINIDUMP_SYSTEM_INFO* system_info; 92 const MINIDUMP_SYSTEM_INFO* system_info;
92 const MINIDUMP_STRING* csd_version; 93 const MINIDUMP_STRING* csd_version;
93 94
94 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version); 95 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version);
96 if (Test::HasFatalFailure()) {
97 return;
98 }
95 99
96 EXPECT_EQ(kMinidumpCPUArchitectureUnknown, 100 EXPECT_EQ(kMinidumpCPUArchitectureUnknown,
97 system_info->ProcessorArchitecture); 101 system_info->ProcessorArchitecture);
98 EXPECT_EQ(0u, system_info->ProcessorLevel); 102 EXPECT_EQ(0u, system_info->ProcessorLevel);
99 EXPECT_EQ(0u, system_info->ProcessorRevision); 103 EXPECT_EQ(0u, system_info->ProcessorRevision);
100 EXPECT_EQ(0u, system_info->NumberOfProcessors); 104 EXPECT_EQ(0u, system_info->NumberOfProcessors);
101 EXPECT_EQ(0u, system_info->ProductType); 105 EXPECT_EQ(0u, system_info->ProductType);
102 EXPECT_EQ(0u, system_info->MajorVersion); 106 EXPECT_EQ(0u, system_info->MajorVersion);
103 EXPECT_EQ(0u, system_info->MinorVersion); 107 EXPECT_EQ(0u, system_info->MinorVersion);
104 EXPECT_EQ(0u, system_info->BuildNumber); 108 EXPECT_EQ(0u, system_info->BuildNumber);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 minidump_file_writer.AddStream(&system_info_writer); 160 minidump_file_writer.AddStream(&system_info_writer);
157 161
158 StringFileWriter file_writer; 162 StringFileWriter file_writer;
159 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 163 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
160 164
161 const MINIDUMP_SYSTEM_INFO* system_info; 165 const MINIDUMP_SYSTEM_INFO* system_info;
162 const MINIDUMP_STRING* csd_version; 166 const MINIDUMP_STRING* csd_version;
163 167
164 GetSystemInfoStream( 168 GetSystemInfoStream(
165 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version); 169 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version);
170 if (Test::HasFatalFailure()) {
171 return;
172 }
166 173
167 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); 174 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
168 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel); 175 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel);
169 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision); 176 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision);
170 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors); 177 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors);
171 EXPECT_EQ(kOSType, system_info->ProductType); 178 EXPECT_EQ(kOSType, system_info->ProductType);
172 EXPECT_EQ(kOSVersionMajor, system_info->MajorVersion); 179 EXPECT_EQ(kOSVersionMajor, system_info->MajorVersion);
173 EXPECT_EQ(kOSVersionMinor, system_info->MinorVersion); 180 EXPECT_EQ(kOSVersionMinor, system_info->MinorVersion);
174 EXPECT_EQ(kOSVersionBuild, system_info->BuildNumber); 181 EXPECT_EQ(kOSVersionBuild, system_info->BuildNumber);
175 EXPECT_EQ(kOS, system_info->PlatformId); 182 EXPECT_EQ(kOS, system_info->PlatformId);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 minidump_file_writer.AddStream(&system_info_writer); 223 minidump_file_writer.AddStream(&system_info_writer);
217 224
218 StringFileWriter file_writer; 225 StringFileWriter file_writer;
219 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 226 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
220 227
221 const MINIDUMP_SYSTEM_INFO* system_info; 228 const MINIDUMP_SYSTEM_INFO* system_info;
222 const MINIDUMP_STRING* csd_version; 229 const MINIDUMP_STRING* csd_version;
223 230
224 GetSystemInfoStream( 231 GetSystemInfoStream(
225 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version); 232 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version);
233 if (Test::HasFatalFailure()) {
234 return;
235 }
226 236
227 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); 237 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
228 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel); 238 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel);
229 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision); 239 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision);
230 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors); 240 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors);
231 EXPECT_EQ(kOSType, system_info->ProductType); 241 EXPECT_EQ(kOSType, system_info->ProductType);
232 EXPECT_EQ(kOSVersionMajor, system_info->MajorVersion); 242 EXPECT_EQ(kOSVersionMajor, system_info->MajorVersion);
233 EXPECT_EQ(kOSVersionMinor, system_info->MinorVersion); 243 EXPECT_EQ(kOSVersionMinor, system_info->MinorVersion);
234 EXPECT_EQ(kOSVersionBuild, system_info->BuildNumber); 244 EXPECT_EQ(kOSVersionBuild, system_info->BuildNumber);
235 EXPECT_EQ(kOS, system_info->PlatformId); 245 EXPECT_EQ(kOS, system_info->PlatformId);
(...skipping 21 matching lines...) Expand all
257 267
258 minidump_file_writer.AddStream(&system_info_writer); 268 minidump_file_writer.AddStream(&system_info_writer);
259 269
260 StringFileWriter file_writer; 270 StringFileWriter file_writer;
261 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 271 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
262 272
263 const MINIDUMP_SYSTEM_INFO* system_info; 273 const MINIDUMP_SYSTEM_INFO* system_info;
264 const MINIDUMP_STRING* csd_version; 274 const MINIDUMP_STRING* csd_version;
265 275
266 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version); 276 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version);
277 if (Test::HasFatalFailure()) {
278 return;
279 }
267 280
268 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); 281 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
269 EXPECT_EQ(0u, system_info->ProcessorLevel); 282 EXPECT_EQ(0u, system_info->ProcessorLevel);
270 EXPECT_EQ(kCPUVendor[0], system_info->Cpu.X86CpuInfo.VendorId[0]); 283 EXPECT_EQ(kCPUVendor[0], system_info->Cpu.X86CpuInfo.VendorId[0]);
271 EXPECT_EQ(kCPUVendor[1], system_info->Cpu.X86CpuInfo.VendorId[1]); 284 EXPECT_EQ(kCPUVendor[1], system_info->Cpu.X86CpuInfo.VendorId[1]);
272 EXPECT_EQ(kCPUVendor[2], system_info->Cpu.X86CpuInfo.VendorId[2]); 285 EXPECT_EQ(kCPUVendor[2], system_info->Cpu.X86CpuInfo.VendorId[2]);
273 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.VersionInformation); 286 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.VersionInformation);
274 } 287 }
275 288
276 TEST(MinidumpSystemInfoWriterDeathTest, NoCSDVersion) { 289 TEST(MinidumpSystemInfoWriterDeathTest, NoCSDVersion) {
277 MinidumpFileWriter minidump_file_writer; 290 MinidumpFileWriter minidump_file_writer;
278 MinidumpSystemInfoWriter system_info_writer; 291 MinidumpSystemInfoWriter system_info_writer;
279 minidump_file_writer.AddStream(&system_info_writer); 292 minidump_file_writer.AddStream(&system_info_writer);
280 293
281 StringFileWriter file_writer; 294 StringFileWriter file_writer;
282 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), 295 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer),
283 "csd_version_"); 296 "csd_version_");
284 } 297 }
285 298
286 } // namespace 299 } // namespace
OLDNEW
« minidump/minidump_misc_info_writer_test.cc ('K') | « minidump/minidump_misc_info_writer_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698