1 //===-- ProcfsTests.cpp ---------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 #include "lldb/Host/linux/Support.h"
13 #include "gmock/gmock.h"
14 #include "gtest/gtest.h"
16 using namespace lldb_private
;
17 using namespace process_linux
;
20 TEST(Perf
, HardcodedLogicalCoreIDs
) {
21 Expected
<std::vector
<lldb::cpu_id_t
>> cpu_ids
=
22 GetAvailableLogicalCoreIDs(R
"(processor : 13
23 vendor_id : GenuineIntel
26 model name : Intel(R) Xeon(R) Gold 6138 CPU @ 2.00GHz
43 vendor_id : GenuineIntel
46 model name : Intel(R) Xeon(R) Gold 6138 CPU @ 2.00GHz
59 vendor_id : GenuineIntel
62 model name : Intel(R) Xeon(R) Gold 6138 CPU @ 2.00GHz
74 vendor_id : GenuineIntel
77 model name : Intel(R) Xeon(R) Gold 6138 CPU @ 2.00GHz
90 ASSERT_TRUE((bool)cpu_ids
);
91 ASSERT_THAT(*cpu_ids
, ::testing::ElementsAre(13, 24, 35, 79));
94 TEST(Perf
, RealLogicalCoreIDs
) {
95 // We first check we can read /proc/cpuinfo
96 auto buffer_or_error
= errorOrToExpected(getProcFile("cpuinfo"));
98 GTEST_SKIP() << toString(buffer_or_error
.takeError());
100 // At this point we shouldn't fail parsing the core ids
101 Expected
<ArrayRef
<lldb::cpu_id_t
>> cpu_ids
= GetAvailableLogicalCoreIDs();
102 ASSERT_TRUE((bool)cpu_ids
);
103 ASSERT_GT((int)cpu_ids
->size(), 0) << "We must see at least one core";
106 TEST(Perf
, RealPtraceScope
) {
107 // We first check we can read /proc/sys/kernel/yama/ptrace_scope
108 auto buffer_or_error
=
109 errorOrToExpected(getProcFile("sys/kernel/yama/ptrace_scope"));
110 if (!buffer_or_error
)
111 GTEST_SKIP() << toString(buffer_or_error
.takeError());
113 // At this point we shouldn't fail parsing the ptrace_scope value.
114 Expected
<int> ptrace_scope
= GetPtraceScope();
115 ASSERT_TRUE((bool)ptrace_scope
) << ptrace_scope
.takeError();
116 ASSERT_GE(*ptrace_scope
, 0)
117 << "Sensible values of ptrace_scope are between 0 and 3";
118 ASSERT_LE(*ptrace_scope
, 3)
119 << "Sensible values of ptrace_scope are between 0 and 3";