2015-03-02 13:06:34 -08:00
|
|
|
// Copyright 2015 The Crashpad Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "snapshot/win/system_snapshot_win.h"
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "build/build_config.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "snapshot/win/process_reader_win.h"
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class SystemSnapshotWinTest : public testing::Test {
|
|
|
|
public:
|
|
|
|
SystemSnapshotWinTest()
|
|
|
|
: Test(),
|
|
|
|
process_reader_(),
|
|
|
|
system_snapshot_() {
|
|
|
|
}
|
|
|
|
|
|
|
|
const internal::SystemSnapshotWin& system_snapshot() const {
|
|
|
|
return system_snapshot_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// testing::Test:
|
|
|
|
void SetUp() override {
|
2015-09-09 12:29:29 -07:00
|
|
|
ASSERT_TRUE(process_reader_.Initialize(GetCurrentProcess(),
|
|
|
|
ProcessSuspensionState::kRunning));
|
2015-03-02 13:06:34 -08:00
|
|
|
system_snapshot_.Initialize(&process_reader_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcessReaderWin process_reader_;
|
|
|
|
internal::SystemSnapshotWin system_snapshot_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(SystemSnapshotWinTest);
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotWinTest, GetCPUArchitecture) {
|
|
|
|
CPUArchitecture cpu_architecture = system_snapshot().GetCPUArchitecture();
|
|
|
|
|
|
|
|
#if defined(ARCH_CPU_X86)
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(cpu_architecture, kCPUArchitectureX86);
|
2015-03-02 13:06:34 -08:00
|
|
|
#elif defined(ARCH_CPU_X86_64)
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(cpu_architecture, kCPUArchitectureX86_64);
|
2018-12-12 12:58:24 -08:00
|
|
|
#elif defined(ARCH_CPU_ARM64)
|
|
|
|
EXPECT_EQ(cpu_architecture, kCPUArchitectureARM64);
|
|
|
|
#else
|
|
|
|
#error Unsupported Windows Arch
|
2015-03-02 13:06:34 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotWinTest, CPUCount) {
|
|
|
|
EXPECT_GE(system_snapshot().CPUCount(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotWinTest, CPUVendor) {
|
|
|
|
std::string cpu_vendor = system_snapshot().CPUVendor();
|
2019-07-24 15:19:03 +02:00
|
|
|
#if defined(ARCH_CPU_X86_FAMILY)
|
2015-03-02 13:06:34 -08:00
|
|
|
EXPECT_TRUE(cpu_vendor == "GenuineIntel" || cpu_vendor == "AuthenticAMD");
|
2019-07-24 15:19:03 +02:00
|
|
|
#elif defined(ARCH_CPU_ARM64)
|
2019-08-15 09:37:31 -07:00
|
|
|
EXPECT_FALSE(cpu_vendor.empty());
|
2019-07-24 15:19:03 +02:00
|
|
|
#else
|
|
|
|
#error Unsupported Windows Arch
|
|
|
|
#endif
|
2015-03-02 13:06:34 -08:00
|
|
|
}
|
|
|
|
|
2019-06-03 10:47:48 +02:00
|
|
|
#if defined(ARCH_CPU_X86_FAMILY)
|
2015-03-02 13:06:34 -08:00
|
|
|
TEST_F(SystemSnapshotWinTest, CPUX86SupportsDAZ) {
|
|
|
|
// Most SSE2+ machines support Denormals-Are-Zero. This may fail if run on
|
|
|
|
// older machines.
|
|
|
|
EXPECT_TRUE(system_snapshot().CPUX86SupportsDAZ());
|
|
|
|
}
|
2019-06-03 10:47:48 +02:00
|
|
|
#endif
|
2015-03-02 13:06:34 -08:00
|
|
|
|
|
|
|
TEST_F(SystemSnapshotWinTest, GetOperatingSystem) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(system_snapshot().GetOperatingSystem(),
|
|
|
|
SystemSnapshot::kOperatingSystemWindows);
|
2015-03-02 13:06:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotWinTest, OSVersion) {
|
|
|
|
int major;
|
|
|
|
int minor;
|
|
|
|
int bugfix;
|
|
|
|
std::string build;
|
|
|
|
system_snapshot().OSVersion(&major, &minor, &bugfix, &build);
|
|
|
|
|
|
|
|
EXPECT_GE(major, 5);
|
|
|
|
if (major == 5)
|
|
|
|
EXPECT_GE(minor, 1);
|
|
|
|
if (major == 6)
|
|
|
|
EXPECT_TRUE(minor >= 0 && minor <= 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotWinTest, OSVersionFull) {
|
|
|
|
EXPECT_FALSE(system_snapshot().OSVersionFull().empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotWinTest, MachineDescription) {
|
|
|
|
EXPECT_TRUE(system_snapshot().MachineDescription().empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotWinTest, TimeZone) {
|
|
|
|
SystemSnapshot::DaylightSavingTimeStatus dst_status;
|
|
|
|
int standard_offset_seconds;
|
|
|
|
int daylight_offset_seconds;
|
|
|
|
std::string standard_name;
|
|
|
|
std::string daylight_name;
|
|
|
|
|
|
|
|
system_snapshot().TimeZone(&dst_status,
|
|
|
|
&standard_offset_seconds,
|
|
|
|
&daylight_offset_seconds,
|
|
|
|
&standard_name,
|
|
|
|
&daylight_name);
|
|
|
|
|
|
|
|
// |standard_offset_seconds| gives seconds east of UTC, and |timezone| gives
|
|
|
|
// seconds west of UTC.
|
2015-09-21 10:51:15 -07:00
|
|
|
long timezone = 0;
|
|
|
|
_get_timezone(&timezone);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(standard_offset_seconds, -timezone);
|
2015-03-02 13:06:34 -08:00
|
|
|
|
|
|
|
// In contemporary usage, most time zones have an integer hour offset from
|
|
|
|
// UTC, although several are at a half-hour offset, and two are at 15-minute
|
|
|
|
// offsets. Throughout history, other variations existed. See
|
2017-11-20 16:57:43 -05:00
|
|
|
// https://www.timeanddate.com/time/time-zones-interesting.html.
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(standard_offset_seconds % (15 * 60), 0)
|
2015-03-02 13:06:34 -08:00
|
|
|
<< "standard_offset_seconds " << standard_offset_seconds;
|
|
|
|
|
2018-02-06 11:34:20 -08:00
|
|
|
// dst_status of kDoesNotObserveDaylightSavingTime can mean only that the
|
|
|
|
// adjustment is not automatic, as opposed to daylight/standard differences
|
|
|
|
// not existing at all. So it cannot be asserted that the two offsets are the
|
|
|
|
// same in that case.
|
|
|
|
|
|
|
|
EXPECT_EQ(daylight_offset_seconds % (15 * 60), 0)
|
|
|
|
<< "daylight_offset_seconds " << daylight_offset_seconds;
|
|
|
|
|
|
|
|
// In contemporary usage, dst_delta_seconds will almost always be one hour,
|
|
|
|
// except for Lord Howe Island, Australia, which uses a 30-minute delta.
|
|
|
|
// Throughout history, other variations existed. See
|
|
|
|
// https://www.timeanddate.com/time/dst/.
|
|
|
|
int dst_delta_seconds = daylight_offset_seconds - standard_offset_seconds;
|
|
|
|
if (dst_delta_seconds != 60 * 60 && dst_delta_seconds != 30 * 60) {
|
|
|
|
FAIL() << "dst_delta_seconds " << dst_delta_seconds;
|
|
|
|
}
|
2015-03-02 13:06:34 -08:00
|
|
|
|
2018-02-06 11:34:20 -08:00
|
|
|
if (dst_status != SystemSnapshot::kDoesNotObserveDaylightSavingTime) {
|
2015-03-02 13:06:34 -08:00
|
|
|
EXPECT_NE(standard_name, daylight_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|