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

Side by Side Diff: minidump/minidump_system_info_writer_test.cc

Issue 936153002: Add FileReaderInterface. Move StringFileWriter to StringFile and (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Remove unused #include Created 5 years, 10 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
« no previous file with comments | « minidump/minidump_string_writer_test.cc ('k') | minidump/minidump_thread_writer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
(...skipping 11 matching lines...) Expand all
22 #include <algorithm> 22 #include <algorithm>
23 #include <string> 23 #include <string>
24 24
25 #include "base/compiler_specific.h" 25 #include "base/compiler_specific.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_string_writer_test_util.h" 29 #include "minidump/test/minidump_string_writer_test_util.h"
30 #include "minidump/test/minidump_writable_test_util.h" 30 #include "minidump/test/minidump_writable_test_util.h"
31 #include "snapshot/test/test_system_snapshot.h" 31 #include "snapshot/test/test_system_snapshot.h"
32 #include "util/file/string_file_writer.h" 32 #include "util/file/string_file.h"
33 33
34 namespace crashpad { 34 namespace crashpad {
35 namespace test { 35 namespace test {
36 namespace { 36 namespace {
37 37
38 void GetSystemInfoStream(const std::string& file_contents, 38 void GetSystemInfoStream(const std::string& file_contents,
39 size_t csd_version_length, 39 size_t csd_version_length,
40 const MINIDUMP_SYSTEM_INFO** system_info, 40 const MINIDUMP_SYSTEM_INFO** system_info,
41 const MINIDUMP_STRING** csd_version) { 41 const MINIDUMP_STRING** csd_version) {
42 // 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.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 TEST(MinidumpSystemInfoWriter, Empty) { 79 TEST(MinidumpSystemInfoWriter, Empty) {
80 MinidumpFileWriter minidump_file_writer; 80 MinidumpFileWriter minidump_file_writer;
81 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); 81 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter());
82 82
83 system_info_writer->SetCSDVersion(std::string()); 83 system_info_writer->SetCSDVersion(std::string());
84 84
85 minidump_file_writer.AddStream(system_info_writer.Pass()); 85 minidump_file_writer.AddStream(system_info_writer.Pass());
86 86
87 StringFileWriter file_writer; 87 StringFile string_file;
88 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 88 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
89 89
90 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; 90 const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
91 const MINIDUMP_STRING* csd_version = nullptr; 91 const MINIDUMP_STRING* csd_version = nullptr;
92 92
93 ASSERT_NO_FATAL_FAILURE( 93 ASSERT_NO_FATAL_FAILURE(
94 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); 94 GetSystemInfoStream(string_file.string(), 0, &system_info, &csd_version));
95 95
96 EXPECT_EQ(kMinidumpCPUArchitectureUnknown, 96 EXPECT_EQ(kMinidumpCPUArchitectureUnknown,
97 system_info->ProcessorArchitecture); 97 system_info->ProcessorArchitecture);
98 EXPECT_EQ(0u, system_info->ProcessorLevel); 98 EXPECT_EQ(0u, system_info->ProcessorLevel);
99 EXPECT_EQ(0u, system_info->ProcessorRevision); 99 EXPECT_EQ(0u, system_info->ProcessorRevision);
100 EXPECT_EQ(0u, system_info->NumberOfProcessors); 100 EXPECT_EQ(0u, system_info->NumberOfProcessors);
101 EXPECT_EQ(0u, system_info->ProductType); 101 EXPECT_EQ(0u, system_info->ProductType);
102 EXPECT_EQ(0u, system_info->MajorVersion); 102 EXPECT_EQ(0u, system_info->MajorVersion);
103 EXPECT_EQ(0u, system_info->MinorVersion); 103 EXPECT_EQ(0u, system_info->MinorVersion);
104 EXPECT_EQ(0u, system_info->BuildNumber); 104 EXPECT_EQ(0u, system_info->BuildNumber);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 system_info_writer->SetOSVersion( 148 system_info_writer->SetOSVersion(
149 kOSVersionMajor, kOSVersionMinor, kOSVersionBuild); 149 kOSVersionMajor, kOSVersionMinor, kOSVersionBuild);
150 system_info_writer->SetCSDVersion(kCSDVersion); 150 system_info_writer->SetCSDVersion(kCSDVersion);
151 system_info_writer->SetSuiteMask(kSuiteMask); 151 system_info_writer->SetSuiteMask(kSuiteMask);
152 system_info_writer->SetCPUX86VendorString(kCPUVendor); 152 system_info_writer->SetCPUX86VendorString(kCPUVendor);
153 system_info_writer->SetCPUX86VersionAndFeatures(kCPUVersion, kCPUFeatures); 153 system_info_writer->SetCPUX86VersionAndFeatures(kCPUVersion, kCPUFeatures);
154 system_info_writer->SetCPUX86AMDExtendedFeatures(kAMDFeatures); 154 system_info_writer->SetCPUX86AMDExtendedFeatures(kAMDFeatures);
155 155
156 minidump_file_writer.AddStream(system_info_writer.Pass()); 156 minidump_file_writer.AddStream(system_info_writer.Pass());
157 157
158 StringFileWriter file_writer; 158 StringFile string_file;
159 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 159 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
160 160
161 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; 161 const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
162 const MINIDUMP_STRING* csd_version = nullptr; 162 const MINIDUMP_STRING* csd_version = nullptr;
163 163
164 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream( 164 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(
165 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version)); 165 string_file.string(), strlen(kCSDVersion), &system_info, &csd_version));
166 166
167 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); 167 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
168 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel); 168 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel);
169 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision); 169 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision);
170 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors); 170 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors);
171 EXPECT_EQ(kOSType, system_info->ProductType); 171 EXPECT_EQ(kOSType, system_info->ProductType);
172 EXPECT_EQ(kOSVersionMajor, system_info->MajorVersion); 172 EXPECT_EQ(kOSVersionMajor, system_info->MajorVersion);
173 EXPECT_EQ(kOSVersionMinor, system_info->MinorVersion); 173 EXPECT_EQ(kOSVersionMinor, system_info->MinorVersion);
174 EXPECT_EQ(kOSVersionBuild, system_info->BuildNumber); 174 EXPECT_EQ(kOSVersionBuild, system_info->BuildNumber);
175 EXPECT_EQ(kOS, system_info->PlatformId); 175 EXPECT_EQ(kOS, system_info->PlatformId);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 system_info_writer->SetCPUCount(kCPUCount); 208 system_info_writer->SetCPUCount(kCPUCount);
209 system_info_writer->SetOS(kOS); 209 system_info_writer->SetOS(kOS);
210 system_info_writer->SetOSType(kMinidumpOSTypeWorkstation); 210 system_info_writer->SetOSType(kMinidumpOSTypeWorkstation);
211 system_info_writer->SetOSVersion( 211 system_info_writer->SetOSVersion(
212 kOSVersionMajor, kOSVersionMinor, kOSVersionBuild); 212 kOSVersionMajor, kOSVersionMinor, kOSVersionBuild);
213 system_info_writer->SetCSDVersion(kCSDVersion); 213 system_info_writer->SetCSDVersion(kCSDVersion);
214 system_info_writer->SetCPUOtherFeatures(kCPUFeatures[0], kCPUFeatures[1]); 214 system_info_writer->SetCPUOtherFeatures(kCPUFeatures[0], kCPUFeatures[1]);
215 215
216 minidump_file_writer.AddStream(system_info_writer.Pass()); 216 minidump_file_writer.AddStream(system_info_writer.Pass());
217 217
218 StringFileWriter file_writer; 218 StringFile string_file;
219 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 219 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
220 220
221 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; 221 const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
222 const MINIDUMP_STRING* csd_version; 222 const MINIDUMP_STRING* csd_version;
223 223
224 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream( 224 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(
225 file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version)); 225 string_file.string(), strlen(kCSDVersion), &system_info, &csd_version));
226 226
227 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); 227 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
228 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel); 228 EXPECT_EQ(kCPULevel, system_info->ProcessorLevel);
229 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision); 229 EXPECT_EQ(kCPURevision, system_info->ProcessorRevision);
230 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors); 230 EXPECT_EQ(kCPUCount, system_info->NumberOfProcessors);
231 EXPECT_EQ(kOSType, system_info->ProductType); 231 EXPECT_EQ(kOSType, system_info->ProductType);
232 EXPECT_EQ(kOSVersionMajor, system_info->MajorVersion); 232 EXPECT_EQ(kOSVersionMajor, system_info->MajorVersion);
233 EXPECT_EQ(kOSVersionMinor, system_info->MinorVersion); 233 EXPECT_EQ(kOSVersionMinor, system_info->MinorVersion);
234 EXPECT_EQ(kOSVersionBuild, system_info->BuildNumber); 234 EXPECT_EQ(kOSVersionBuild, system_info->BuildNumber);
235 EXPECT_EQ(kOS, system_info->PlatformId); 235 EXPECT_EQ(kOS, system_info->PlatformId);
(...skipping 14 matching lines...) Expand all
250 const MinidumpCPUArchitecture kCPUArchitecture = kMinidumpCPUArchitectureX86; 250 const MinidumpCPUArchitecture kCPUArchitecture = kMinidumpCPUArchitectureX86;
251 const uint32_t kCPUVendor[] = {'uneG', 'Ieni', 'letn'}; 251 const uint32_t kCPUVendor[] = {'uneG', 'Ieni', 'letn'};
252 252
253 system_info_writer->SetCPUArchitecture(kCPUArchitecture); 253 system_info_writer->SetCPUArchitecture(kCPUArchitecture);
254 system_info_writer->SetCPUX86Vendor( 254 system_info_writer->SetCPUX86Vendor(
255 kCPUVendor[0], kCPUVendor[1], kCPUVendor[2]); 255 kCPUVendor[0], kCPUVendor[1], kCPUVendor[2]);
256 system_info_writer->SetCSDVersion(std::string()); 256 system_info_writer->SetCSDVersion(std::string());
257 257
258 minidump_file_writer.AddStream(system_info_writer.Pass()); 258 minidump_file_writer.AddStream(system_info_writer.Pass());
259 259
260 StringFileWriter file_writer; 260 StringFile string_file;
261 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 261 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
262 262
263 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; 263 const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
264 const MINIDUMP_STRING* csd_version; 264 const MINIDUMP_STRING* csd_version;
265 265
266 ASSERT_NO_FATAL_FAILURE( 266 ASSERT_NO_FATAL_FAILURE(
267 GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version)); 267 GetSystemInfoStream(string_file.string(), 0, &system_info, &csd_version));
268 268
269 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture); 269 EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
270 EXPECT_EQ(0u, system_info->ProcessorLevel); 270 EXPECT_EQ(0u, system_info->ProcessorLevel);
271 EXPECT_EQ(kCPUVendor[0], system_info->Cpu.X86CpuInfo.VendorId[0]); 271 EXPECT_EQ(kCPUVendor[0], system_info->Cpu.X86CpuInfo.VendorId[0]);
272 EXPECT_EQ(kCPUVendor[1], system_info->Cpu.X86CpuInfo.VendorId[1]); 272 EXPECT_EQ(kCPUVendor[1], system_info->Cpu.X86CpuInfo.VendorId[1]);
273 EXPECT_EQ(kCPUVendor[2], system_info->Cpu.X86CpuInfo.VendorId[2]); 273 EXPECT_EQ(kCPUVendor[2], system_info->Cpu.X86CpuInfo.VendorId[2]);
274 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.VersionInformation); 274 EXPECT_EQ(0u, system_info->Cpu.X86CpuInfo.VersionInformation);
275 } 275 }
276 276
277 TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_X86) { 277 TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_X86) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 expect_system_info.MinorVersion, 330 expect_system_info.MinorVersion,
331 expect_system_info.BuildNumber, 331 expect_system_info.BuildNumber,
332 kOSVersionBuild); 332 kOSVersionBuild);
333 333
334 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); 334 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter());
335 system_info_writer->InitializeFromSnapshot(&system_snapshot); 335 system_info_writer->InitializeFromSnapshot(&system_snapshot);
336 336
337 MinidumpFileWriter minidump_file_writer; 337 MinidumpFileWriter minidump_file_writer;
338 minidump_file_writer.AddStream(system_info_writer.Pass()); 338 minidump_file_writer.AddStream(system_info_writer.Pass());
339 339
340 StringFileWriter file_writer; 340 StringFile string_file;
341 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 341 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
342 342
343 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; 343 const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
344 const MINIDUMP_STRING* csd_version = nullptr; 344 const MINIDUMP_STRING* csd_version = nullptr;
345 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(), 345 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(string_file.string(),
346 strlen(kOSVersionBuild), 346 strlen(kOSVersionBuild),
347 &system_info, 347 &system_info,
348 &csd_version)); 348 &csd_version));
349 349
350 EXPECT_EQ(expect_system_info.ProcessorArchitecture, 350 EXPECT_EQ(expect_system_info.ProcessorArchitecture,
351 system_info->ProcessorArchitecture); 351 system_info->ProcessorArchitecture);
352 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel); 352 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel);
353 EXPECT_EQ(expect_system_info.ProcessorRevision, 353 EXPECT_EQ(expect_system_info.ProcessorRevision,
354 system_info->ProcessorRevision); 354 system_info->ProcessorRevision);
355 EXPECT_EQ(expect_system_info.NumberOfProcessors, 355 EXPECT_EQ(expect_system_info.NumberOfProcessors,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 expect_system_info.BuildNumber, 425 expect_system_info.BuildNumber,
426 kOSVersionBuild); 426 kOSVersionBuild);
427 system_snapshot.SetNXEnabled(true); 427 system_snapshot.SetNXEnabled(true);
428 428
429 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); 429 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter());
430 system_info_writer->InitializeFromSnapshot(&system_snapshot); 430 system_info_writer->InitializeFromSnapshot(&system_snapshot);
431 431
432 MinidumpFileWriter minidump_file_writer; 432 MinidumpFileWriter minidump_file_writer;
433 minidump_file_writer.AddStream(system_info_writer.Pass()); 433 minidump_file_writer.AddStream(system_info_writer.Pass());
434 434
435 StringFileWriter file_writer; 435 StringFile string_file;
436 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 436 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
437 437
438 const MINIDUMP_SYSTEM_INFO* system_info = nullptr; 438 const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
439 const MINIDUMP_STRING* csd_version = nullptr; 439 const MINIDUMP_STRING* csd_version = nullptr;
440 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(), 440 ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(string_file.string(),
441 strlen(kOSVersionBuild), 441 strlen(kOSVersionBuild),
442 &system_info, 442 &system_info,
443 &csd_version)); 443 &csd_version));
444 444
445 EXPECT_EQ(expect_system_info.ProcessorArchitecture, 445 EXPECT_EQ(expect_system_info.ProcessorArchitecture,
446 system_info->ProcessorArchitecture); 446 system_info->ProcessorArchitecture);
447 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel); 447 EXPECT_EQ(expect_system_info.ProcessorLevel, system_info->ProcessorLevel);
448 EXPECT_EQ(expect_system_info.ProcessorRevision, 448 EXPECT_EQ(expect_system_info.ProcessorRevision,
449 system_info->ProcessorRevision); 449 system_info->ProcessorRevision);
450 EXPECT_EQ(expect_system_info.NumberOfProcessors, 450 EXPECT_EQ(expect_system_info.NumberOfProcessors,
(...skipping 12 matching lines...) Expand all
463 for (size_t index = 0; index < strlen(kOSVersionBuild); ++index) { 463 for (size_t index = 0; index < strlen(kOSVersionBuild); ++index) {
464 EXPECT_EQ(kOSVersionBuild[index], csd_version->Buffer[index]) << index; 464 EXPECT_EQ(kOSVersionBuild[index], csd_version->Buffer[index]) << index;
465 } 465 }
466 } 466 }
467 467
468 TEST(MinidumpSystemInfoWriterDeathTest, NoCSDVersion) { 468 TEST(MinidumpSystemInfoWriterDeathTest, NoCSDVersion) {
469 MinidumpFileWriter minidump_file_writer; 469 MinidumpFileWriter minidump_file_writer;
470 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter()); 470 auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter());
471 minidump_file_writer.AddStream(system_info_writer.Pass()); 471 minidump_file_writer.AddStream(system_info_writer.Pass());
472 472
473 StringFileWriter file_writer; 473 StringFile string_file;
474 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), 474 ASSERT_DEATH(minidump_file_writer.WriteEverything(&string_file),
475 "csd_version_"); 475 "csd_version_");
476 } 476 }
477 477
478 } // namespace 478 } // namespace
479 } // namespace test 479 } // namespace test
480 } // namespace crashpad 480 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_string_writer_test.cc ('k') | minidump/minidump_thread_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698