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
|
#include "common.h"
#include <iterator>
namespace bpftrace::test::codegen {
TEST(codegen, call_kstack)
{
const auto *result = NAME;
test("kprobe:f { @x = kstack(); @y = kstack(6); @z = kstack(perf) }", result);
}
TEST(codegen, call_kstack_mapids)
{
ast::ASTContext ast("stdin", R"(
kprobe:f {
@x = kstack(5);
@y = kstack(6);
@z = kstack(6)
})");
auto bpftrace = get_mock_bpftrace();
auto ok = ast::PassManager()
.put(ast)
.put<BPFtrace>(*bpftrace)
.add(ast::AllParsePasses())
.add(ast::CreateLLVMInitPass())
.add(ast::CreateClangBuildPass())
.add(ast::CreateTypeSystemPass())
.add(ast::CreateSemanticPass())
.add(ast::CreateResourcePass())
.add(ast::AllCompilePasses())
.run();
ASSERT_TRUE(ok && ast.diagnostics().ok());
bpftrace->bytecode_ = std::move(ok->get<BpfBytecode>());
ASSERT_EQ(bpftrace->bytecode_.maps().size(), 7);
ASSERT_EQ(bpftrace->bytecode_.countStackMaps(), 3U);
StackType stack_type;
stack_type.limit = 5;
ASSERT_TRUE(bpftrace->bytecode_.hasMap(stack_type));
stack_type.limit = 6;
ASSERT_TRUE(bpftrace->bytecode_.hasMap(stack_type));
}
TEST(codegen, call_kstack_modes_mapids)
{
ast::ASTContext ast("stdin", R"(
kprobe:f {
@w = kstack(raw);
@x = kstack(perf);
@y = kstack(bpftrace);
@z = kstack()
})");
auto bpftrace = get_mock_bpftrace();
auto ok = ast::PassManager()
.put(ast)
.put<BPFtrace>(*bpftrace)
.add(ast::AllParsePasses())
.add(ast::CreateLLVMInitPass())
.add(ast::CreateClangBuildPass())
.add(ast::CreateTypeSystemPass())
.add(ast::CreateSemanticPass())
.add(ast::CreateResourcePass())
.add(ast::AllCompilePasses())
.run();
ASSERT_TRUE(ast.diagnostics().ok());
bpftrace->bytecode_ = std::move(ok->get<BpfBytecode>());
ASSERT_EQ(bpftrace->bytecode_.maps().size(), 9);
ASSERT_EQ(bpftrace->bytecode_.countStackMaps(), 4U);
StackType stack_type;
stack_type.mode = StackMode::perf;
ASSERT_TRUE(bpftrace->bytecode_.hasMap(stack_type));
stack_type.mode = StackMode::bpftrace;
ASSERT_TRUE(bpftrace->bytecode_.hasMap(stack_type));
stack_type.mode = StackMode::raw;
ASSERT_TRUE(bpftrace->bytecode_.hasMap(stack_type));
}
} // namespace bpftrace::test::codegen
|