| 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 // There are a variety of other values, but we don't expect to run our tests |
| 86 // Apple has only shipped Intel x86-family CPUs, but here’s a small nod to the | 73 // on them. |
| 87 // “Hackintosh” crowd. | 74 EXPECT_TRUE(cpu_vendor == "GenuineIntel" || cpu_vendor == "AuthenticAMD"); |
| 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 } | 75 } |
| 95 | 76 |
| 96 #if defined(ARCH_CPU_X86_FAMILY) | 77 TEST_F(SystemSnapshotWinTest, CPUX86SupportsDAZ) { |
| 97 | 78 // Most SSE2+ machines support Denormals-Are-Zero. This may fail if run on |
| 98 TEST_F(SystemSnapshotMacTest, CPUX86SupportsDAZ) { | 79 // older machines. |
| 99 // All x86-family CPUs that Apple is known to have shipped should support DAZ. | |
| 100 EXPECT_TRUE(system_snapshot().CPUX86SupportsDAZ()); | 80 EXPECT_TRUE(system_snapshot().CPUX86SupportsDAZ()); |
| 101 } | 81 } |
| 102 | 82 |
| 103 #endif | 83 TEST_F(SystemSnapshotWinTest, GetOperatingSystem) { |
| 104 | 84 EXPECT_EQ(SystemSnapshot::kOperatingSystemWindows, |
| 105 TEST_F(SystemSnapshotMacTest, GetOperatingSystem) { | |
| 106 EXPECT_EQ(SystemSnapshot::kOperatingSystemMacOSX, | |
| 107 system_snapshot().GetOperatingSystem()); | 85 system_snapshot().GetOperatingSystem()); |
| 108 } | 86 } |
| 109 | 87 |
| 110 TEST_F(SystemSnapshotMacTest, OSVersion) { | 88 TEST_F(SystemSnapshotWinTest, OSVersion) { |
| 111 int major; | 89 int major; |
| 112 int minor; | 90 int minor; |
| 113 int bugfix; | 91 int bugfix; |
| 114 std::string build; | 92 std::string build; |
| 115 system_snapshot().OSVersion(&major, &minor, &bugfix, &build); | 93 system_snapshot().OSVersion(&major, &minor, &bugfix, &build); |
| 116 | 94 |
| 117 EXPECT_EQ(10, major); | 95 EXPECT_GE(major, 5); |
| 118 EXPECT_EQ(MacOSXMinorVersion(), minor); | 96 if (major == 5) |
| 119 EXPECT_FALSE(build.empty()); | 97 EXPECT_GE(minor, 1); |
| 98 if (major == 6) |
| 99 EXPECT_TRUE(minor >= 0 && minor <= 3); |
| 120 } | 100 } |
| 121 | 101 |
| 122 TEST_F(SystemSnapshotMacTest, OSVersionFull) { | 102 TEST_F(SystemSnapshotWinTest, OSVersionFull) { |
| 123 EXPECT_FALSE(system_snapshot().OSVersionFull().empty()); | 103 EXPECT_FALSE(system_snapshot().OSVersionFull().empty()); |
| 124 } | 104 } |
| 125 | 105 |
| 126 TEST_F(SystemSnapshotMacTest, MachineDescription) { | 106 TEST_F(SystemSnapshotWinTest, MachineDescription) { |
| 127 EXPECT_FALSE(system_snapshot().MachineDescription().empty()); | 107 EXPECT_TRUE(system_snapshot().MachineDescription().empty()); |
| 128 } | 108 } |
| 129 | 109 |
| 130 TEST_F(SystemSnapshotMacTest, TimeZone) { | 110 TEST_F(SystemSnapshotWinTest, TimeZone) { |
| 131 SystemSnapshot::DaylightSavingTimeStatus dst_status; | 111 SystemSnapshot::DaylightSavingTimeStatus dst_status; |
| 132 int standard_offset_seconds; | 112 int standard_offset_seconds; |
| 133 int daylight_offset_seconds; | 113 int daylight_offset_seconds; |
| 134 std::string standard_name; | 114 std::string standard_name; |
| 135 std::string daylight_name; | 115 std::string daylight_name; |
| 136 | 116 |
| 137 system_snapshot().TimeZone(&dst_status, | 117 system_snapshot().TimeZone(&dst_status, |
| 138 &standard_offset_seconds, | 118 &standard_offset_seconds, |
| 139 &daylight_offset_seconds, | 119 &daylight_offset_seconds, |
| 140 &standard_name, | 120 &standard_name, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 167 FAIL() << "dst_delta_seconds " << dst_delta_seconds; | 147 FAIL() << "dst_delta_seconds " << dst_delta_seconds; |
| 168 } | 148 } |
| 169 | 149 |
| 170 EXPECT_NE(standard_name, daylight_name); | 150 EXPECT_NE(standard_name, daylight_name); |
| 171 } | 151 } |
| 172 } | 152 } |
| 173 | 153 |
| 174 } // namespace | 154 } // namespace |
| 175 } // namespace test | 155 } // namespace test |
| 176 } // namespace crashpad | 156 } // namespace crashpad |
| OLD | NEW |