brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.3 KiB · 534e3e1 Raw
145 lines · cpp
1//===-- ProcfsTests.cpp ---------------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "Procfs.h"10 11#include "lldb/Host/linux/Support.h"12#include "lldb/Host/posix/Support.h"13 14#include "gmock/gmock.h"15#include "gtest/gtest.h"16 17using namespace lldb_private;18using namespace process_linux;19using namespace llvm;20 21TEST(Perf, HardcodedLogicalCoreIDs) {22  Expected<std::vector<lldb::cpu_id_t>> cpu_ids =23      GetAvailableLogicalCoreIDs(R"(processor       : 1324vendor_id       : GenuineIntel25cpu family      : 626model           : 8527model name      : Intel(R) Xeon(R) Gold 6138 CPU @ 2.00GHz28stepping        : 429microcode       : 0x200006530cpu MHz         : 2886.37031cache size      : 28160 KB32physical id     : 133siblings        : 4034core id         : 1935cpu cores       : 2036apicid          : 10337initial apicid  : 10338fpu             : yes39fpu_exception   : yes40cpuid level     : 2241power management:42 43processor       : 2444vendor_id       : GenuineIntel45cpu family      : 646model           : 8547model name      : Intel(R) Xeon(R) Gold 6138 CPU @ 2.00GHz48stepping        : 449microcode       : 0x200006550cpu MHz         : 2768.49451cache size      : 28160 KB52physical id     : 153siblings        : 4054core id         : 2055cpu cores       : 2056apicid          : 10557power management:58 59processor       : 3560vendor_id       : GenuineIntel61cpu family      : 662model           : 8563model name      : Intel(R) Xeon(R) Gold 6138 CPU @ 2.00GHz64stepping        : 465microcode       : 0x200006566cpu MHz         : 2884.70367cache size      : 28160 KB68physical id     : 169siblings        : 4070core id         : 2471cpu cores       : 2072apicid          : 11373 74processor       : 7975vendor_id       : GenuineIntel76cpu family      : 677model           : 8578model name      : Intel(R) Xeon(R) Gold 6138 CPU @ 2.00GHz79stepping        : 480microcode       : 0x200006581cpu MHz         : 3073.95582cache size      : 28160 KB83physical id     : 184siblings        : 4085core id         : 2886cpu cores       : 2087apicid          : 12188power management:89)");90 91  ASSERT_TRUE((bool)cpu_ids);92  ASSERT_THAT(*cpu_ids, ::testing::ElementsAre(13, 24, 35, 79));93}94 95TEST(Perf, RealLogicalCoreIDs) {96  // We first check we can read /proc/cpuinfo97  auto buffer_or_error = errorOrToExpected(getProcFile("cpuinfo"));98  if (!buffer_or_error)99    GTEST_SKIP() << toString(buffer_or_error.takeError());100 101  // At this point we shouldn't fail parsing the core ids102  Expected<ArrayRef<lldb::cpu_id_t>> cpu_ids = GetAvailableLogicalCoreIDs();103  ASSERT_TRUE((bool)cpu_ids);104  ASSERT_GT((int)cpu_ids->size(), 0) << "We must see at least one core";105}106 107TEST(Perf, RealPtraceScopeWhenExist) {108  // We first check we can read /proc/sys/kernel/yama/ptrace_scope109  auto buffer_or_error =110      errorOrToExpected(getProcFile("sys/kernel/yama/ptrace_scope"));111  if (!buffer_or_error)112    GTEST_SKIP() << toString(buffer_or_error.takeError());113 114  // At this point we shouldn't fail parsing the ptrace_scope value.115  Expected<int> ptrace_scope = GetPtraceScope();116  ASSERT_TRUE((bool)ptrace_scope) << ptrace_scope.takeError();117  ASSERT_GE(*ptrace_scope, 0)118      << "Sensible values of ptrace_scope are between 0 and 3";119  ASSERT_LE(*ptrace_scope, 3)120      << "Sensible values of ptrace_scope are between 0 and 3";121}122 123TEST(Perf, RealPtraceScopeWhenNotExist) {124  // We first check we can NOT read /proc/sys/kernel/yama/ptrace_scope125  auto buffer_or_error =126      errorOrToExpected(getProcFile("sys/kernel/yama/ptrace_scope"));127  if (buffer_or_error)128    GTEST_SKIP() << "In order for this test to run, "129                    "/proc/sys/kernel/yama/ptrace_scope should not exist";130  consumeError(buffer_or_error.takeError());131 132  // At this point we should fail parsing the ptrace_scope value.133  Expected<int> ptrace_scope = GetPtraceScope();134  ASSERT_FALSE((bool)ptrace_scope);135  consumeError(ptrace_scope.takeError());136}137 138#ifdef LLVM_ENABLE_THREADING139TEST(Support, getProcFile_Tid) {140  auto BufferOrError = getProcFile(getpid(), llvm::get_threadid(), "comm");141  ASSERT_TRUE(BufferOrError);142  ASSERT_TRUE(*BufferOrError);143}144#endif /*ifdef LLVM_ENABLE_THREADING */145