OLD | NEW |
(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 that |
| 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: |
| 39 SystemSnapshotMacTest() |
| 40 : Test(), |
| 41 process_reader_(), |
| 42 snapshot_time_(), |
| 43 system_snapshot_() { |
| 44 } |
| 45 |
| 46 const internal::SystemSnapshotMac& system_snapshot() const { |
| 47 return system_snapshot_; |
| 48 } |
| 49 |
| 50 // testing::Test: |
| 51 virtual void SetUp() override { |
| 52 ASSERT_TRUE(process_reader_.Initialize(mach_task_self())); |
| 53 ASSERT_EQ(0, gettimeofday(&snapshot_time_, NULL)) |
| 54 << ErrnoMessage("gettimeofday"); |
| 55 system_snapshot_.Initialize(&process_reader_, &snapshot_time_); |
| 56 } |
| 57 |
| 58 private: |
| 59 ProcessReader process_reader_; |
| 60 timeval snapshot_time_; |
| 61 internal::SystemSnapshotMac system_snapshot_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(SystemSnapshotMacTest); |
| 64 }; |
| 65 |
| 66 TEST_F(SystemSnapshotMacTest, GetCPUArchitecture) { |
| 67 CPUArchitecture cpu_architecture = system_snapshot().GetCPUArchitecture(); |
| 68 |
| 69 #if defined(ARCH_CPU_X86) |
| 70 EXPECT_EQ(kCPUArchitectureX86, cpu_architecture); |
| 71 #elif defined(ARCH_CPU_X86_64) |
| 72 EXPECT_EQ(kCPUArchitectureX86_64, cpu_architecture); |
| 73 #else |
| 74 #error port to your architecture |
| 75 #endif |
| 76 } |
| 77 |
| 78 TEST_F(SystemSnapshotMacTest, CPUCount) { |
| 79 EXPECT_GE(system_snapshot().CPUCount(), 1); |
| 80 } |
| 81 |
| 82 TEST_F(SystemSnapshotMacTest, CPUVendor) { |
| 83 std::string cpu_vendor = system_snapshot().CPUVendor(); |
| 84 |
| 85 #if defined(ARCH_CPU_X86_FAMILY) |
| 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; |
| 90 } |
| 91 #else |
| 92 #error port to your architecture |
| 93 #endif |
| 94 } |
| 95 |
| 96 #if defined(ARCH_CPU_X86_FAMILY) |
| 97 |
| 98 TEST_F(SystemSnapshotMacTest, CPUX86SupportsDAZ) { |
| 99 // All x86-family CPUs that Apple is known to have shipped should support DAZ. |
| 100 EXPECT_TRUE(system_snapshot().CPUX86SupportsDAZ()); |
| 101 } |
| 102 |
| 103 #endif |
| 104 |
| 105 TEST_F(SystemSnapshotMacTest, GetOperatingSystem) { |
| 106 EXPECT_EQ(SystemSnapshot::kOperatingSystemMacOSX, |
| 107 system_snapshot().GetOperatingSystem()); |
| 108 } |
| 109 |
| 110 TEST_F(SystemSnapshotMacTest, OSVersion) { |
| 111 int major; |
| 112 int minor; |
| 113 int bugfix; |
| 114 std::string build; |
| 115 system_snapshot().OSVersion(&major, &minor, &bugfix, &build); |
| 116 |
| 117 EXPECT_EQ(10, major); |
| 118 EXPECT_EQ(MacOSXMinorVersion(), minor); |
| 119 EXPECT_FALSE(build.empty()); |
| 120 } |
| 121 |
| 122 TEST_F(SystemSnapshotMacTest, OSVersionFull) { |
| 123 EXPECT_FALSE(system_snapshot().OSVersionFull().empty()); |
| 124 } |
| 125 |
| 126 TEST_F(SystemSnapshotMacTest, MachineDescription) { |
| 127 EXPECT_FALSE(system_snapshot().MachineDescription().empty()); |
| 128 } |
| 129 |
| 130 } // namespace |
OLD | NEW |