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

Side by Side Diff: snapshot/system_snapshot_mac_test.cc

Issue 626013002: Add SystemSnapshotMac and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 2 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
(Empty)
1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "snapshot/system_snapshot_mac.h"
16
17 #include <sys/time.h>
18
19 #include <string>
20
21 #include "build/build_config.h"
22 #include "gtest/gtest.h"
23 #include "util/mac/mac_util.h"
24 #include "util/mac/process_reader.h"
25 #include "util/test/errors.h"
26
27 namespace {
28
29 using namespace crashpad;
30 using namespace crashpad::test;
31
32 // SystemSnapshotMac objects would be cumbersome to construct in each test
33 // case that requires one, because of the repetitive and mechanical work
34 // necessary to set up a ProcessReader and timeval. This class handles the
35 // initialization work so that test cases need only instantiate and Initialize()
36 // a single object.
37 class TestSystemSnapshotMac {
Robert Sesek 2014/10/03 18:05:45 Why not do this in a testing::TestCase::SetUp() ?
38 public:
39 TestSystemSnapshotMac()
40 : process_reader_(),
41 snapshot_time_(),
42 system_snapshot_() {
43 }
44
45 void Initialize() {
46 ASSERT_TRUE(process_reader_.Initialize(mach_task_self()));
47 ASSERT_EQ(0, gettimeofday(&snapshot_time_, NULL))
48 << ErrnoMessage("gettimeofday");
49 system_snapshot_.Initialize(&process_reader_, &snapshot_time_);
50 }
51
52 const internal::SystemSnapshotMac* get() const { return &system_snapshot_; }
53
54 private:
55 ProcessReader process_reader_;
56 timeval snapshot_time_;
57 internal::SystemSnapshotMac system_snapshot_;
58
59 DISALLOW_COPY_AND_ASSIGN(TestSystemSnapshotMac);
60 };
61
62 TEST(SystemSnapshotMac, GetCPUArchitecture) {
63 TestSystemSnapshotMac system_snapshot;
64 system_snapshot.Initialize();
65 if (Test::HasFatalFailure()) {
66 return;
67 }
68
69 CPUArchitecture cpu_architecture =
70 system_snapshot.get()->GetCPUArchitecture();
71
72 #if defined(ARCH_CPU_X86)
73 EXPECT_EQ(kCPUArchitectureX86, cpu_architecture);
74 #elif defined(ARCH_CPU_X86_64)
75 EXPECT_EQ(kCPUArchitectureX86_64, cpu_architecture);
76 #endif
77 }
78
79 TEST(SystemSnapshotMac, CPUCount) {
80 TestSystemSnapshotMac system_snapshot;
81 system_snapshot.Initialize();
82 if (Test::HasFatalFailure()) {
83 return;
84 }
85
86 EXPECT_GE(system_snapshot.get()->CPUCount(), 1);
87 }
88
89 TEST(SystemSnapshotMac, CPUVendor) {
90 TestSystemSnapshotMac system_snapshot;
91 system_snapshot.Initialize();
92 if (Test::HasFatalFailure()) {
93 return;
94 }
95
96 std::string cpu_vendor = system_snapshot.get()->CPUVendor();
97
98 #if defined(ARCH_CPU_X86_FAMILY)
99 // Apple has only shipped Intel x86-family CPUs, but here’s a small nod to the
100 // “Hackintosh” crowd.
101 if (cpu_vendor != "GenuineIntel" && cpu_vendor != "AuthenticAMD") {
102 FAIL() << cpu_vendor;
103 }
104 #endif
105 }
106
107 #if defined(ARCH_CPU_X86_FAMILY)
108
109 TEST(SystemSnapshotMac, CPUX86SupportsDAZ) {
110 TestSystemSnapshotMac system_snapshot;
111 system_snapshot.Initialize();
112 if (Test::HasFatalFailure()) {
113 return;
114 }
115
116 // All x86-family CPUs that Apple is known to have shipped should support DAZ.
117 EXPECT_TRUE(system_snapshot.get()->CPUX86SupportsDAZ());
118 }
119
120 #endif
121
122 TEST(SystemSnapshotMac, GetOperatingSystem) {
123 TestSystemSnapshotMac system_snapshot;
124 system_snapshot.Initialize();
125 if (Test::HasFatalFailure()) {
126 return;
127 }
128
129 EXPECT_EQ(SystemSnapshot::kOperatingSystemMacOSX,
130 system_snapshot.get()->GetOperatingSystem());
131 }
132
133 TEST(SystemSnapshotMac, OSVersion) {
134 TestSystemSnapshotMac system_snapshot;
135 system_snapshot.Initialize();
136 if (Test::HasFatalFailure()) {
137 return;
138 }
139
140 int major;
141 int minor;
142 int bugfix;
143 std::string build;
144 system_snapshot.get()->OSVersion(&major, &minor, &bugfix, &build);
145
146 EXPECT_EQ(10, major);
147 EXPECT_EQ(MacOSXMinorVersion(), minor);
148 EXPECT_FALSE(build.empty());
149 }
150
151 TEST(SystemSnapshotMac, OSVersionFull) {
152 TestSystemSnapshotMac system_snapshot;
153 system_snapshot.Initialize();
154 if (Test::HasFatalFailure()) {
155 return;
156 }
157
158 std::string os_version_full = system_snapshot.get()->OSVersionFull();
159
160 EXPECT_FALSE(os_version_full.empty());
161 }
162
163 TEST(SystemSnapshotMac, MachineDescription) {
164 TestSystemSnapshotMac system_snapshot;
165 system_snapshot.Initialize();
166 if (Test::HasFatalFailure()) {
167 return;
168 }
169
170 std::string machine_description = system_snapshot.get()->MachineDescription();
171
172 EXPECT_FALSE(machine_description.empty());
173 }
174
175 } // namespace
OLDNEW
« snapshot/system_snapshot_mac.cc ('K') | « snapshot/system_snapshot_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698