OLD | NEW |
---|---|
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 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 "snapshot/mac/system_snapshot_mac.h" | 15 #include "snapshot/win/system_snapshot_win.h" |
16 | 16 |
17 #include <sys/time.h> | 17 #include <sys/time.h> |
18 #include <time.h> | 18 #include <time.h> |
19 | 19 |
20 #include <string> | 20 #include <string> |
21 | 21 |
22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
23 #include "gtest/gtest.h" | 23 #include "gtest/gtest.h" |
24 #include "snapshot/mac/process_reader.h" | 24 #include "snapshot/win/process_reader_win.h" |
25 #include "util/mac/mac_util.h" | |
26 #include "util/test/errors.h" | |
27 | 25 |
28 namespace crashpad { | 26 namespace crashpad { |
29 namespace test { | 27 namespace test { |
30 namespace { | 28 namespace { |
31 | 29 |
32 // SystemSnapshotMac objects would be cumbersome to construct in each test that | 30 class SystemSnapshotWinTest : public testing::Test { |
33 // requires one, because of the repetitive and mechanical work necessary to set | |
34 // up a ProcessReader and timeval, along with the checks to verify that these | |
35 // operations succeed. This test fixture class handles the initialization work | |
36 // so that individual tests don’t have to. | |
37 class SystemSnapshotMacTest : public testing::Test { | |
38 public: | 31 public: |
39 SystemSnapshotMacTest() | 32 SystemSnapshotWinTest() |
40 : Test(), | 33 : Test(), |
41 process_reader_(), | 34 process_reader_(), |
42 snapshot_time_(), | |
43 system_snapshot_() { | 35 system_snapshot_() { |
44 } | 36 } |
45 | 37 |
46 const internal::SystemSnapshotMac& system_snapshot() const { | 38 const internal::SystemSnapshotWin& system_snapshot() const { |
47 return system_snapshot_; | 39 return system_snapshot_; |
48 } | 40 } |
49 | 41 |
50 // testing::Test: | 42 // testing::Test: |
51 void SetUp() override { | 43 void SetUp() override { |
52 ASSERT_TRUE(process_reader_.Initialize(mach_task_self())); | 44 ASSERT_TRUE(process_reader_.Initialize(GetCurrentProcess())); |
53 ASSERT_EQ(0, gettimeofday(&snapshot_time_, nullptr)) | 45 system_snapshot_.Initialize(&process_reader_); |
54 << ErrnoMessage("gettimeofday"); | |
55 system_snapshot_.Initialize(&process_reader_, &snapshot_time_); | |
56 } | 46 } |
57 | 47 |
58 private: | 48 private: |
59 ProcessReader process_reader_; | 49 ProcessReaderWin process_reader_; |
60 timeval snapshot_time_; | 50 internal::SystemSnapshotWin system_snapshot_; |
61 internal::SystemSnapshotMac system_snapshot_; | |
62 | 51 |
63 DISALLOW_COPY_AND_ASSIGN(SystemSnapshotMacTest); | 52 DISALLOW_COPY_AND_ASSIGN(SystemSnapshotWinTest); |
64 }; | 53 }; |
65 | 54 |
66 TEST_F(SystemSnapshotMacTest, GetCPUArchitecture) { | 55 TEST_F(SystemSnapshotWinTest, GetCPUArchitecture) { |
67 CPUArchitecture cpu_architecture = system_snapshot().GetCPUArchitecture(); | 56 CPUArchitecture cpu_architecture = system_snapshot().GetCPUArchitecture(); |
68 | 57 |
69 #if defined(ARCH_CPU_X86) | 58 #if defined(ARCH_CPU_X86) |
70 EXPECT_EQ(kCPUArchitectureX86, cpu_architecture); | 59 EXPECT_EQ(kCPUArchitectureX86, cpu_architecture); |
71 #elif defined(ARCH_CPU_X86_64) | 60 #elif defined(ARCH_CPU_X86_64) |
72 EXPECT_EQ(kCPUArchitectureX86_64, cpu_architecture); | 61 EXPECT_EQ(kCPUArchitectureX86_64, cpu_architecture); |
73 #else | |
74 #error port to your architecture | |
75 #endif | 62 #endif |
76 } | 63 } |
77 | 64 |
78 TEST_F(SystemSnapshotMacTest, CPUCount) { | 65 TEST_F(SystemSnapshotWinTest, CPUCount) { |
79 EXPECT_GE(system_snapshot().CPUCount(), 1); | 66 EXPECT_GE(system_snapshot().CPUCount(), 1); |
80 } | 67 } |
81 | 68 |
82 TEST_F(SystemSnapshotMacTest, CPUVendor) { | 69 TEST_F(SystemSnapshotWinTest, CPUVendor) { |
83 std::string cpu_vendor = system_snapshot().CPUVendor(); | 70 std::string cpu_vendor = system_snapshot().CPUVendor(); |
84 | 71 |
85 #if defined(ARCH_CPU_X86_FAMILY) | 72 EXPECT_TRUE(cpu_vendor == "GenuineIntel" || cpu_vendor == "AuthenticAMD"); |
Mark Mentovai
2015/02/20 18:58:52
This deserves a comment at least acknowledging tha
scottmg
2015/02/20 22:00:45
It may actually fail on bots if they report "VMwar
| |
86 // Apple has only shipped Intel x86-family CPUs, but here’s a small nod to the | |
87 // “Hackintosh” crowd. | |
88 if (cpu_vendor != "GenuineIntel" && cpu_vendor != "AuthenticAMD") { | |
89 FAIL() << "cpu_vendor " << cpu_vendor; | |
90 } | |
91 #else | |
92 #error port to your architecture | |
93 #endif | |
94 } | 73 } |
95 | 74 |
96 #if defined(ARCH_CPU_X86_FAMILY) | 75 TEST_F(SystemSnapshotWinTest, CPUX86SupportsDAZ) { |
97 | 76 // Most SSE2+ machines support Denormals-Are-Zero. This may fail if run on |
98 TEST_F(SystemSnapshotMacTest, CPUX86SupportsDAZ) { | 77 // older machines. |
99 // All x86-family CPUs that Apple is known to have shipped should support DAZ. | |
100 EXPECT_TRUE(system_snapshot().CPUX86SupportsDAZ()); | 78 EXPECT_TRUE(system_snapshot().CPUX86SupportsDAZ()); |
101 } | 79 } |
102 | 80 |
103 #endif | 81 TEST_F(SystemSnapshotWinTest, GetOperatingSystem) { |
104 | 82 EXPECT_EQ(SystemSnapshot::kOperatingSystemWindows, |
105 TEST_F(SystemSnapshotMacTest, GetOperatingSystem) { | |
106 EXPECT_EQ(SystemSnapshot::kOperatingSystemMacOSX, | |
107 system_snapshot().GetOperatingSystem()); | 83 system_snapshot().GetOperatingSystem()); |
108 } | 84 } |
109 | 85 |
110 TEST_F(SystemSnapshotMacTest, OSVersion) { | 86 TEST_F(SystemSnapshotWinTest, OSVersion) { |
111 int major; | 87 int major; |
112 int minor; | 88 int minor; |
113 int bugfix; | 89 int bugfix; |
114 std::string build; | 90 std::string build; |
115 system_snapshot().OSVersion(&major, &minor, &bugfix, &build); | 91 system_snapshot().OSVersion(&major, &minor, &bugfix, &build); |
116 | 92 |
117 EXPECT_EQ(10, major); | 93 EXPECT_GE(major, 5); |
118 EXPECT_EQ(MacOSXMinorVersion(), minor); | 94 if (major == 5) |
95 EXPECT_GE(minor, 1); | |
96 if (major == 6) | |
97 EXPECT_TRUE(minor >= 0 && minor <= 3); | |
119 EXPECT_FALSE(build.empty()); | 98 EXPECT_FALSE(build.empty()); |
120 } | 99 } |
121 | 100 |
122 TEST_F(SystemSnapshotMacTest, OSVersionFull) { | 101 TEST_F(SystemSnapshotWinTest, OSVersionFull) { |
123 EXPECT_FALSE(system_snapshot().OSVersionFull().empty()); | 102 EXPECT_FALSE(system_snapshot().OSVersionFull().empty()); |
124 } | 103 } |
125 | 104 |
126 TEST_F(SystemSnapshotMacTest, MachineDescription) { | 105 TEST_F(SystemSnapshotWinTest, MachineDescription) { |
127 EXPECT_FALSE(system_snapshot().MachineDescription().empty()); | 106 EXPECT_TRUE(system_snapshot().MachineDescription().empty()); |
128 } | 107 } |
129 | 108 |
130 TEST_F(SystemSnapshotMacTest, TimeZone) { | 109 TEST_F(SystemSnapshotWinTest, TimeZone) { |
131 SystemSnapshot::DaylightSavingTimeStatus dst_status; | 110 SystemSnapshot::DaylightSavingTimeStatus dst_status; |
132 int standard_offset_seconds; | 111 int standard_offset_seconds; |
133 int daylight_offset_seconds; | 112 int daylight_offset_seconds; |
134 std::string standard_name; | 113 std::string standard_name; |
135 std::string daylight_name; | 114 std::string daylight_name; |
136 | 115 |
137 system_snapshot().TimeZone(&dst_status, | 116 system_snapshot().TimeZone(&dst_status, |
138 &standard_offset_seconds, | 117 &standard_offset_seconds, |
139 &daylight_offset_seconds, | 118 &daylight_offset_seconds, |
140 &standard_name, | 119 &standard_name, |
(...skipping 26 matching lines...) Expand all Loading... | |
167 FAIL() << "dst_delta_seconds " << dst_delta_seconds; | 146 FAIL() << "dst_delta_seconds " << dst_delta_seconds; |
168 } | 147 } |
169 | 148 |
170 EXPECT_NE(standard_name, daylight_name); | 149 EXPECT_NE(standard_name, daylight_name); |
171 } | 150 } |
172 } | 151 } |
173 | 152 |
174 } // namespace | 153 } // namespace |
175 } // namespace test | 154 } // namespace test |
176 } // namespace crashpad | 155 } // namespace crashpad |
OLD | NEW |