Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(733)

Unified Diff: snapshot/system_snapshot_mac_test.cc

Issue 626013002: Add SystemSnapshotMac and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« snapshot/system_snapshot_mac.cc ('K') | « snapshot/system_snapshot_mac.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: snapshot/system_snapshot_mac_test.cc
diff --git a/snapshot/system_snapshot_mac_test.cc b/snapshot/system_snapshot_mac_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fd041401086f6c840787916db94572c0b49e537f
--- /dev/null
+++ b/snapshot/system_snapshot_mac_test.cc
@@ -0,0 +1,175 @@
+// Copyright 2014 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/system_snapshot_mac.h"
+
+#include <sys/time.h>
+
+#include <string>
+
+#include "build/build_config.h"
+#include "gtest/gtest.h"
+#include "util/mac/mac_util.h"
+#include "util/mac/process_reader.h"
+#include "util/test/errors.h"
+
+namespace {
+
+using namespace crashpad;
+using namespace crashpad::test;
+
+// SystemSnapshotMac objects would be cumbersome to construct in each test
+// case that requires one, because of the repetitive and mechanical work
+// necessary to set up a ProcessReader and timeval. This class handles the
+// initialization work so that test cases need only instantiate and Initialize()
+// a single object.
+class TestSystemSnapshotMac {
Robert Sesek 2014/10/03 18:05:45 Why not do this in a testing::TestCase::SetUp() ?
+ public:
+ TestSystemSnapshotMac()
+ : process_reader_(),
+ snapshot_time_(),
+ system_snapshot_() {
+ }
+
+ void Initialize() {
+ ASSERT_TRUE(process_reader_.Initialize(mach_task_self()));
+ ASSERT_EQ(0, gettimeofday(&snapshot_time_, NULL))
+ << ErrnoMessage("gettimeofday");
+ system_snapshot_.Initialize(&process_reader_, &snapshot_time_);
+ }
+
+ const internal::SystemSnapshotMac* get() const { return &system_snapshot_; }
+
+ private:
+ ProcessReader process_reader_;
+ timeval snapshot_time_;
+ internal::SystemSnapshotMac system_snapshot_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestSystemSnapshotMac);
+};
+
+TEST(SystemSnapshotMac, GetCPUArchitecture) {
+ TestSystemSnapshotMac system_snapshot;
+ system_snapshot.Initialize();
+ if (Test::HasFatalFailure()) {
+ return;
+ }
+
+ CPUArchitecture cpu_architecture =
+ system_snapshot.get()->GetCPUArchitecture();
+
+#if defined(ARCH_CPU_X86)
+ EXPECT_EQ(kCPUArchitectureX86, cpu_architecture);
+#elif defined(ARCH_CPU_X86_64)
+ EXPECT_EQ(kCPUArchitectureX86_64, cpu_architecture);
+#endif
+}
+
+TEST(SystemSnapshotMac, CPUCount) {
+ TestSystemSnapshotMac system_snapshot;
+ system_snapshot.Initialize();
+ if (Test::HasFatalFailure()) {
+ return;
+ }
+
+ EXPECT_GE(system_snapshot.get()->CPUCount(), 1);
+}
+
+TEST(SystemSnapshotMac, CPUVendor) {
+ TestSystemSnapshotMac system_snapshot;
+ system_snapshot.Initialize();
+ if (Test::HasFatalFailure()) {
+ return;
+ }
+
+ std::string cpu_vendor = system_snapshot.get()->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") {
+ FAIL() << cpu_vendor;
+ }
+#endif
+}
+
+#if defined(ARCH_CPU_X86_FAMILY)
+
+TEST(SystemSnapshotMac, CPUX86SupportsDAZ) {
+ TestSystemSnapshotMac system_snapshot;
+ system_snapshot.Initialize();
+ if (Test::HasFatalFailure()) {
+ return;
+ }
+
+ // All x86-family CPUs that Apple is known to have shipped should support DAZ.
+ EXPECT_TRUE(system_snapshot.get()->CPUX86SupportsDAZ());
+}
+
+#endif
+
+TEST(SystemSnapshotMac, GetOperatingSystem) {
+ TestSystemSnapshotMac system_snapshot;
+ system_snapshot.Initialize();
+ if (Test::HasFatalFailure()) {
+ return;
+ }
+
+ EXPECT_EQ(SystemSnapshot::kOperatingSystemMacOSX,
+ system_snapshot.get()->GetOperatingSystem());
+}
+
+TEST(SystemSnapshotMac, OSVersion) {
+ TestSystemSnapshotMac system_snapshot;
+ system_snapshot.Initialize();
+ if (Test::HasFatalFailure()) {
+ return;
+ }
+
+ int major;
+ int minor;
+ int bugfix;
+ std::string build;
+ system_snapshot.get()->OSVersion(&major, &minor, &bugfix, &build);
+
+ EXPECT_EQ(10, major);
+ EXPECT_EQ(MacOSXMinorVersion(), minor);
+ EXPECT_FALSE(build.empty());
+}
+
+TEST(SystemSnapshotMac, OSVersionFull) {
+ TestSystemSnapshotMac system_snapshot;
+ system_snapshot.Initialize();
+ if (Test::HasFatalFailure()) {
+ return;
+ }
+
+ std::string os_version_full = system_snapshot.get()->OSVersionFull();
+
+ EXPECT_FALSE(os_version_full.empty());
+}
+
+TEST(SystemSnapshotMac, MachineDescription) {
+ TestSystemSnapshotMac system_snapshot;
+ system_snapshot.Initialize();
+ if (Test::HasFatalFailure()) {
+ return;
+ }
+
+ std::string machine_description = system_snapshot.get()->MachineDescription();
+
+ EXPECT_FALSE(machine_description.empty());
+}
+
+} // namespace
« snapshot/system_snapshot_mac.cc ('K') | « snapshot/system_snapshot_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698