2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2017 The Crashpad Authors
|
2017-08-08 15:04:00 -07: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.
|
|
|
|
|
|
|
|
#include "snapshot/linux/system_snapshot_linux.h"
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
2017-09-22 09:14:52 -07:00
|
|
|
#include <unistd.h>
|
2017-08-08 15:04:00 -07:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "build/build_config.h"
|
|
|
|
#include "gtest/gtest.h"
|
2018-02-22 12:12:26 -08:00
|
|
|
#include "snapshot/linux/process_reader_linux.h"
|
2017-08-08 15:04:00 -07:00
|
|
|
#include "test/errors.h"
|
2017-09-22 09:14:52 -07:00
|
|
|
#include "test/linux/fake_ptrace_connection.h"
|
2017-08-08 15:04:00 -07:00
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
TEST(SystemSnapshotLinux, Basic) {
|
2017-09-22 09:14:52 -07:00
|
|
|
FakePtraceConnection connection;
|
|
|
|
ASSERT_TRUE(connection.Initialize(getpid()));
|
|
|
|
|
2018-02-22 12:12:26 -08:00
|
|
|
ProcessReaderLinux process_reader;
|
2017-09-22 09:14:52 -07:00
|
|
|
ASSERT_TRUE(process_reader.Initialize(&connection));
|
2017-08-08 15:04:00 -07:00
|
|
|
|
|
|
|
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(¤t_hz, &max_hz);
|
2021-11-12 18:55:21 +01:00
|
|
|
// For short-term loads, modern CPUs can boost single-core frequency beyond
|
|
|
|
// the advertised base clock. Let's assume this is no more than a factor 2.
|
|
|
|
EXPECT_GE(max_hz * 2, current_hz);
|
2017-08-08 15:04:00 -07:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2017-08-08 15:04:00 -07:00
|
|
|
EXPECT_FALSE(system.MachineDescription().empty());
|
|
|
|
#else
|
|
|
|
system.MachineDescription();
|
2022-01-19 15:00:24 -05:00
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
2017-08-08 15:04:00 -07:00
|
|
|
|
|
|
|
#if defined(ARCH_CPU_X86_FAMILY)
|
|
|
|
system.CPUX86Signature();
|
|
|
|
system.CPUX86Features();
|
|
|
|
system.CPUX86ExtendedFeatures();
|
|
|
|
system.CPUX86Leaf7Features();
|
|
|
|
|
|
|
|
EXPECT_PRED1(
|
|
|
|
[](std::string vendor) {
|
2019-06-03 16:44:04 +08:00
|
|
|
return vendor == "GenuineIntel" || vendor == "AuthenticAMD" ||
|
|
|
|
vendor == "HygonGenuine";
|
2017-08-08 15:04:00 -07:00
|
|
|
},
|
|
|
|
system.CPUVendor());
|
|
|
|
|
|
|
|
EXPECT_TRUE(system.CPUX86SupportsDAZ());
|
|
|
|
#endif // ARCH_CPU_X86_FAMILY
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|