File: arch.cpp

package info (click to toggle)
bpftrace 0.24.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,496 kB
  • sloc: cpp: 60,982; ansic: 10,952; python: 953; yacc: 665; sh: 536; lex: 295; makefile: 22
file content (100 lines) | stat: -rw-r--r-- 2,823 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <gmock/gmock-matchers.h>
#include <gtest/gtest.h>
#include <sstream>

#include "arch/arch.h"

namespace bpftrace::test::arch {

using namespace bpftrace::arch;
using ::testing::AnyOf;
using ::testing::Eq;

template <typename T>
class ArchTest : public testing::Test {
  using Arch = T;
};

class ArchTestNameGenerator {
public:
  template <typename T>
  static std::string GetName([[maybe_unused]] int index)
  {
    std::stringstream ss;
    ss << T::Machine;
    return ss.str();
  }
};

using MachineTypes = ::testing::Types<Arch<Machine::X86_64>,
                                      Arch<Machine::ARM>,
                                      Arch<Machine::ARM64>,
                                      Arch<Machine::S390X>,
                                      Arch<Machine::PPC64>,
                                      Arch<Machine::MIPS64>,
                                      Arch<Machine::RISCV64>,
                                      Arch<Machine::LOONGARCH64>>;
TYPED_TEST_SUITE(ArchTest, MachineTypes, ArchTestNameGenerator);

TYPED_TEST(ArchTest, Sanity)
{
  EXPECT_GT(TypeParam::kernel_ptr_width(), 0);
  EXPECT_TRUE(!TypeParam::asm_arch().empty());
}

TYPED_TEST(ArchTest, CDefs)
{
  EXPECT_TRUE(!TypeParam::c_defs().empty());
}

TYPED_TEST(ArchTest, ValidArguments)
{
  for (const auto &reg : TypeParam::arguments()) {
    EXPECT_TRUE(TypeParam::register_to_pt_regs_expr(reg).has_value());
    EXPECT_TRUE(TypeParam::register_to_pt_regs_offset(reg).has_value());
  }
}

TYPED_TEST(ArchTest, InvalidRegister)
{
  EXPECT_FALSE(TypeParam::register_to_pt_regs_expr("invalid").has_value());
  EXPECT_FALSE(TypeParam::register_to_pt_regs_offset("invalid").has_value());
}

TYPED_TEST(ArchTest, ValidReturnValue)
{
  EXPECT_TRUE(!TypeParam::return_value().empty());
  EXPECT_TRUE(TypeParam::register_to_pt_regs_expr(TypeParam::return_value())
                  .has_value());
  EXPECT_TRUE(TypeParam::register_to_pt_regs_offset(TypeParam::return_value())
                  .has_value());
}

TYPED_TEST(ArchTest, ValidProgramCounter)
{
  EXPECT_TRUE(!TypeParam::pc_value().empty());
  EXPECT_TRUE(
      TypeParam::register_to_pt_regs_expr(TypeParam::pc_value()).has_value());
  EXPECT_TRUE(
      TypeParam::register_to_pt_regs_offset(TypeParam::pc_value()).has_value());
}

TYPED_TEST(ArchTest, ValidStackPointer)
{
  EXPECT_TRUE(!TypeParam::sp_value().empty());
  EXPECT_TRUE(
      TypeParam::register_to_pt_regs_expr(TypeParam::sp_value()).has_value());
  EXPECT_TRUE(
      TypeParam::register_to_pt_regs_offset(TypeParam::sp_value()).has_value());
}

TYPED_TEST(ArchTest, ValidWatchpointModes)
{
  for (const auto &mode : TypeParam::watchpoint_modes()) {
    for (const auto &c : mode) {
      EXPECT_THAT(c, AnyOf(Eq('r'), Eq('w'), Eq('x')));
    }
  }
}

} // namespace bpftrace::test::arch