| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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/win/system_snapshot_win.h" |
| 16 |
| 17 #include <sys/time.h> |
| 18 #include <time.h> |
| 19 |
| 20 #include <string> |
| 21 |
| 22 #include "build/build_config.h" |
| 23 #include "gtest/gtest.h" |
| 24 #include "snapshot/win/process_reader_win.h" |
| 25 |
| 26 namespace crashpad { |
| 27 namespace test { |
| 28 namespace { |
| 29 |
| 30 class SystemSnapshotWinTest : public testing::Test { |
| 31 public: |
| 32 SystemSnapshotWinTest() |
| 33 : Test(), |
| 34 process_reader_(), |
| 35 system_snapshot_() { |
| 36 } |
| 37 |
| 38 const internal::SystemSnapshotWin& system_snapshot() const { |
| 39 return system_snapshot_; |
| 40 } |
| 41 |
| 42 // testing::Test: |
| 43 void SetUp() override { |
| 44 ASSERT_TRUE(process_reader_.Initialize(GetCurrentProcess(), |
| 45 ProcessSuspensionState::kRunning)); |
| 46 system_snapshot_.Initialize(&process_reader_); |
| 47 } |
| 48 |
| 49 private: |
| 50 ProcessReaderWin process_reader_; |
| 51 internal::SystemSnapshotWin system_snapshot_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(SystemSnapshotWinTest); |
| 54 }; |
| 55 |
| 56 TEST_F(SystemSnapshotWinTest, GetCPUArchitecture) { |
| 57 CPUArchitecture cpu_architecture = system_snapshot().GetCPUArchitecture(); |
| 58 |
| 59 #if defined(ARCH_CPU_X86) |
| 60 EXPECT_EQ(kCPUArchitectureX86, cpu_architecture); |
| 61 #elif defined(ARCH_CPU_X86_64) |
| 62 EXPECT_EQ(kCPUArchitectureX86_64, cpu_architecture); |
| 63 #endif |
| 64 } |
| 65 |
| 66 TEST_F(SystemSnapshotWinTest, CPUCount) { |
| 67 EXPECT_GE(system_snapshot().CPUCount(), 1); |
| 68 } |
| 69 |
| 70 TEST_F(SystemSnapshotWinTest, CPUVendor) { |
| 71 std::string cpu_vendor = system_snapshot().CPUVendor(); |
| 72 |
| 73 // There are a variety of other values, but we don't expect to run our tests |
| 74 // on them. |
| 75 EXPECT_TRUE(cpu_vendor == "GenuineIntel" || cpu_vendor == "AuthenticAMD"); |
| 76 } |
| 77 |
| 78 TEST_F(SystemSnapshotWinTest, CPUX86SupportsDAZ) { |
| 79 // Most SSE2+ machines support Denormals-Are-Zero. This may fail if run on |
| 80 // older machines. |
| 81 EXPECT_TRUE(system_snapshot().CPUX86SupportsDAZ()); |
| 82 } |
| 83 |
| 84 TEST_F(SystemSnapshotWinTest, GetOperatingSystem) { |
| 85 EXPECT_EQ(SystemSnapshot::kOperatingSystemWindows, |
| 86 system_snapshot().GetOperatingSystem()); |
| 87 } |
| 88 |
| 89 TEST_F(SystemSnapshotWinTest, OSVersion) { |
| 90 int major; |
| 91 int minor; |
| 92 int bugfix; |
| 93 std::string build; |
| 94 system_snapshot().OSVersion(&major, &minor, &bugfix, &build); |
| 95 |
| 96 EXPECT_GE(major, 5); |
| 97 if (major == 5) |
| 98 EXPECT_GE(minor, 1); |
| 99 if (major == 6) |
| 100 EXPECT_TRUE(minor >= 0 && minor <= 3); |
| 101 } |
| 102 |
| 103 TEST_F(SystemSnapshotWinTest, OSVersionFull) { |
| 104 EXPECT_FALSE(system_snapshot().OSVersionFull().empty()); |
| 105 } |
| 106 |
| 107 TEST_F(SystemSnapshotWinTest, MachineDescription) { |
| 108 EXPECT_TRUE(system_snapshot().MachineDescription().empty()); |
| 109 } |
| 110 |
| 111 TEST_F(SystemSnapshotWinTest, TimeZone) { |
| 112 SystemSnapshot::DaylightSavingTimeStatus dst_status; |
| 113 int standard_offset_seconds; |
| 114 int daylight_offset_seconds; |
| 115 std::string standard_name; |
| 116 std::string daylight_name; |
| 117 |
| 118 system_snapshot().TimeZone(&dst_status, |
| 119 &standard_offset_seconds, |
| 120 &daylight_offset_seconds, |
| 121 &standard_name, |
| 122 &daylight_name); |
| 123 |
| 124 // |standard_offset_seconds| gives seconds east of UTC, and |timezone| gives |
| 125 // seconds west of UTC. |
| 126 #if _MSC_VER >= 1900 |
| 127 long timezone = 0; |
| 128 _get_timezone(&timezone); |
| 129 #endif |
| 130 EXPECT_EQ(-timezone, standard_offset_seconds); |
| 131 |
| 132 // In contemporary usage, most time zones have an integer hour offset from |
| 133 // UTC, although several are at a half-hour offset, and two are at 15-minute |
| 134 // offsets. Throughout history, other variations existed. See |
| 135 // http://www.timeanddate.com/time/time-zones-interesting.html. |
| 136 EXPECT_EQ(0, standard_offset_seconds % (15 * 60)) |
| 137 << "standard_offset_seconds " << standard_offset_seconds; |
| 138 |
| 139 if (dst_status == SystemSnapshot::kDoesNotObserveDaylightSavingTime) { |
| 140 EXPECT_EQ(standard_offset_seconds, daylight_offset_seconds); |
| 141 EXPECT_EQ(standard_name, daylight_name); |
| 142 } else { |
| 143 EXPECT_EQ(0, daylight_offset_seconds % (15 * 60)) |
| 144 << "daylight_offset_seconds " << daylight_offset_seconds; |
| 145 |
| 146 // In contemporary usage, dst_delta_seconds will almost always be one hour, |
| 147 // except for Lord Howe Island, Australia, which uses a 30-minute |
| 148 // delta. Throughout history, other variations existed. See |
| 149 // http://www.timeanddate.com/time/dst/#brief. |
| 150 int dst_delta_seconds = daylight_offset_seconds - standard_offset_seconds; |
| 151 if (dst_delta_seconds != 60 * 60 && dst_delta_seconds != 30 * 60) { |
| 152 FAIL() << "dst_delta_seconds " << dst_delta_seconds; |
| 153 } |
| 154 |
| 155 EXPECT_NE(standard_name, daylight_name); |
| 156 } |
| 157 } |
| 158 |
| 159 } // namespace |
| 160 } // namespace test |
| 161 } // namespace crashpad |
| OLD | NEW |