2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-10-03 14:55:54 -04:00
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
|
2014-10-17 13:41:45 -04:00
|
|
|
|
#include "snapshot/mac/system_snapshot_mac.h"
|
2014-10-03 14:55:54 -04:00
|
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "build/build_config.h"
|
2021-06-22 10:55:22 -04:00
|
|
|
|
#include "gmock/gmock.h"
|
2014-10-03 14:55:54 -04:00
|
|
|
|
#include "gtest/gtest.h"
|
2018-02-22 12:12:26 -08:00
|
|
|
|
#include "snapshot/mac/process_reader_mac.h"
|
test: Move util/test to its own top-level directory, test.
After 9e79ea1da719, it no longer makes sense for crashpad_util_test_lib
to “hide” in util/util_test.gyp. All of util/test is moved to its own
top-level directory, test, which all other test code is allowed to
depend on. test, too, is allowed to depend on all other non-test code.
In a future change, when crashpad_util_test_lib gains a dependency on
crashpad_client, it won’t look so weird for something in util (even
though it’s in util/test) to depend on something in client, because the
thing that needs to depend on client will live in test, not util.
BUG=crashpad:33
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/1051533002
2015-03-31 17:44:14 -04:00
|
|
|
|
#include "test/errors.h"
|
2014-10-03 14:55:54 -04:00
|
|
|
|
#include "util/mac/mac_util.h"
|
|
|
|
|
|
2014-10-07 17:28:50 -04:00
|
|
|
|
namespace crashpad {
|
|
|
|
|
namespace test {
|
2014-10-03 14:55:54 -04:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
// SystemSnapshotMac objects would be cumbersome to construct in each test that
|
|
|
|
|
// requires one, because of the repetitive and mechanical work necessary to set
|
2018-02-22 12:12:26 -08:00
|
|
|
|
// up a ProcessReaderMac and timeval, along with the checks to verify that these
|
2014-10-03 14:55:54 -04:00
|
|
|
|
// operations succeed. This test fixture class handles the initialization work
|
|
|
|
|
// so that individual tests don’t have to.
|
|
|
|
|
class SystemSnapshotMacTest : public testing::Test {
|
|
|
|
|
public:
|
|
|
|
|
SystemSnapshotMacTest()
|
|
|
|
|
: Test(),
|
|
|
|
|
process_reader_(),
|
|
|
|
|
snapshot_time_(),
|
|
|
|
|
system_snapshot_() {
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-20 12:55:12 -07:00
|
|
|
|
SystemSnapshotMacTest(const SystemSnapshotMacTest&) = delete;
|
|
|
|
|
SystemSnapshotMacTest& operator=(const SystemSnapshotMacTest&) = delete;
|
|
|
|
|
|
2014-10-03 14:55:54 -04:00
|
|
|
|
const internal::SystemSnapshotMac& system_snapshot() const {
|
|
|
|
|
return system_snapshot_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// testing::Test:
|
2014-10-14 11:11:57 -04:00
|
|
|
|
void SetUp() override {
|
2014-10-03 14:55:54 -04:00
|
|
|
|
ASSERT_TRUE(process_reader_.Initialize(mach_task_self()));
|
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
|
|
|
|
ASSERT_EQ(gettimeofday(&snapshot_time_, nullptr), 0)
|
2014-10-03 14:55:54 -04:00
|
|
|
|
<< ErrnoMessage("gettimeofday");
|
|
|
|
|
system_snapshot_.Initialize(&process_reader_, &snapshot_time_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2018-02-22 12:12:26 -08:00
|
|
|
|
ProcessReaderMac process_reader_;
|
2014-10-03 14:55:54 -04:00
|
|
|
|
timeval snapshot_time_;
|
|
|
|
|
internal::SystemSnapshotMac system_snapshot_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotMacTest, 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);
|
2014-10-03 14:55:54 -04: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);
|
2020-07-07 23:43:46 -04:00
|
|
|
|
#elif defined(ARCH_CPU_ARM64)
|
|
|
|
|
EXPECT_EQ(cpu_architecture, kCPUArchitectureARM64);
|
2014-10-03 14:55:54 -04:00
|
|
|
|
#else
|
|
|
|
|
#error port to your architecture
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotMacTest, CPUCount) {
|
|
|
|
|
EXPECT_GE(system_snapshot().CPUCount(), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotMacTest, CPUVendor) {
|
|
|
|
|
std::string cpu_vendor = system_snapshot().CPUVendor();
|
|
|
|
|
|
|
|
|
|
#if defined(ARCH_CPU_X86_FAMILY)
|
|
|
|
|
// Apple has only shipped Intel x86-family CPUs, but here’s a small nod to the
|
|
|
|
|
// “Hackintosh” crowd.
|
|
|
|
|
if (cpu_vendor != "GenuineIntel" && cpu_vendor != "AuthenticAMD") {
|
2014-10-03 18:40:09 -04:00
|
|
|
|
FAIL() << "cpu_vendor " << cpu_vendor;
|
2014-10-03 14:55:54 -04:00
|
|
|
|
}
|
2020-07-07 23:43:46 -04:00
|
|
|
|
#elif defined(ARCH_CPU_ARM64)
|
2021-06-22 10:55:22 -04:00
|
|
|
|
EXPECT_THAT(cpu_vendor, testing::StartsWith("Apple "));
|
2014-10-03 14:55:54 -04:00
|
|
|
|
#else
|
|
|
|
|
#error port to your architecture
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if defined(ARCH_CPU_X86_FAMILY)
|
|
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotMacTest, CPUX86SupportsDAZ) {
|
|
|
|
|
// All x86-family CPUs that Apple is known to have shipped should support DAZ.
|
|
|
|
|
EXPECT_TRUE(system_snapshot().CPUX86SupportsDAZ());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotMacTest, 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::kOperatingSystemMacOSX);
|
2014-10-03 14:55:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotMacTest, OSVersion) {
|
|
|
|
|
int major;
|
|
|
|
|
int minor;
|
|
|
|
|
int bugfix;
|
|
|
|
|
std::string build;
|
|
|
|
|
system_snapshot().OSVersion(&major, &minor, &bugfix, &build);
|
|
|
|
|
|
2020-09-01 17:09:37 -04:00
|
|
|
|
const int macos_version_number = MacOSVersionNumber();
|
|
|
|
|
EXPECT_EQ(major * 1'00'00 + minor * 1'00 +
|
2020-09-09 22:35:13 -04:00
|
|
|
|
(macos_version_number >= 10'13'04 ? bugfix : 0),
|
2020-09-01 17:09:37 -04:00
|
|
|
|
macos_version_number);
|
2014-10-03 14:55:54 -04:00
|
|
|
|
EXPECT_FALSE(build.empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotMacTest, OSVersionFull) {
|
|
|
|
|
EXPECT_FALSE(system_snapshot().OSVersionFull().empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SystemSnapshotMacTest, MachineDescription) {
|
|
|
|
|
EXPECT_FALSE(system_snapshot().MachineDescription().empty());
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 19:31:09 -04:00
|
|
|
|
TEST_F(SystemSnapshotMacTest, NXEnabled) {
|
|
|
|
|
// Assume NX will always be enabled, as it was always enabled by default on
|
|
|
|
|
// all supported versions of macOS.
|
|
|
|
|
EXPECT_TRUE(system_snapshot().NXEnabled());
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-03 14:55:54 -04:00
|
|
|
|
} // namespace
|
2014-10-07 17:28:50 -04:00
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace crashpad
|