crashpad/snapshot/linux/system_snapshot_linux_test.cc
Joshua Peraza 59c5d848e5 linux: Refactor ptrace usage.
1) Add PtraceConnection which serves as the base class for specific
types of connections Crashpad uses to trace processes.
2) Add DirectPtraceConnection which is used when the handler process
has `ptrace` capabilities for the target process.
3) Move `ptrace` logic into Ptracer. This class isolates `ptrace` call
logic for use by various PtraceConnection implementations.

Bug: crashpad:30
Change-Id: I98083134a9f7d9f085e4cc816d2b85ffd6d73162
Reviewed-on: https://chromium-review.googlesource.com/671659
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Reviewed-by: Leonard Mosescu <mosescu@chromium.org>
2017-09-22 16:25:32 +00:00

91 lines
2.4 KiB
C++

// Copyright 2017 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/linux/system_snapshot_linux.h"
#include <sys/time.h>
#include <unistd.h>
#include <string>
#include "build/build_config.h"
#include "gtest/gtest.h"
#include "snapshot/linux/process_reader.h"
#include "test/errors.h"
#include "test/linux/fake_ptrace_connection.h"
namespace crashpad {
namespace test {
namespace {
TEST(SystemSnapshotLinux, Basic) {
FakePtraceConnection connection;
ASSERT_TRUE(connection.Initialize(getpid()));
ProcessReader process_reader;
ASSERT_TRUE(process_reader.Initialize(&connection));
timeval snapshot_time;
ASSERT_EQ(gettimeofday(&snapshot_time, nullptr), 0)
<< ErrnoMessage("gettimeofday");
internal::SystemSnapshotLinux system;
system.Initialize(&process_reader, &snapshot_time);
EXPECT_GT(system.CPUCount(), 0u);
uint64_t current_hz, max_hz;
system.CPUFrequency(&current_hz, &max_hz);
EXPECT_GE(max_hz, current_hz);
int major, minor, bugfix;
std::string build;
system.OSVersion(&major, &minor, &bugfix, &build);
EXPECT_GE(major, 3);
EXPECT_GE(minor, 0);
EXPECT_GE(bugfix, 0);
EXPECT_FALSE(build.empty());
EXPECT_FALSE(system.OSVersionFull().empty());
// No expectations; just make sure these can be called successfully.
system.CPURevision();
system.NXEnabled();
#if defined(OS_ANDROID)
EXPECT_FALSE(system.MachineDescription().empty());
#else
system.MachineDescription();
#endif // OS_ANDROID
#if defined(ARCH_CPU_X86_FAMILY)
system.CPUX86Signature();
system.CPUX86Features();
system.CPUX86ExtendedFeatures();
system.CPUX86Leaf7Features();
EXPECT_PRED1(
[](std::string vendor) {
return vendor == "GenuineIntel" || vendor == "AuthenticAMD";
},
system.CPUVendor());
EXPECT_TRUE(system.CPUX86SupportsDAZ());
#endif // ARCH_CPU_X86_FAMILY
}
} // namespace
} // namespace test
} // namespace crashpad