diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bf331a5bd6eb..bd2fafba6580 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,6 +19,7 @@ endif() add_executable(bpftrace_test ast.cpp + bpfbytecode.cpp bpftrace.cpp child.cpp clang_parser.cpp diff --git a/tests/bpfbytecode.cpp b/tests/bpfbytecode.cpp new file mode 100644 index 000000000000..938e75c951e1 --- /dev/null +++ b/tests/bpfbytecode.cpp @@ -0,0 +1,37 @@ +#include "bpfbytecode.h" +#include "driver.h" +#include "mocks.h" +#include "passes/codegen_llvm.h" +#include "passes/semantic_analyser.h" + +#include "gtest/gtest.h" + +namespace bpftrace { +namespace test { +namespace bpfbytecode { + +BpfBytecode codegen(const std::string &input) +{ + auto bpftrace = get_mock_bpftrace(); + + Driver driver(*bpftrace); + EXPECT_EQ(driver.parse_str(input), 0); + + ast::SemanticAnalyser semantics(driver.root.get(), *bpftrace); + EXPECT_EQ(semantics.analyse(), 0); + + ast::CodegenLLVM codegen(driver.root.get(), *bpftrace); + return codegen.compile(); +} + +TEST(bpfbytecode, populate_sections) +{ + auto bytecode = codegen("kprobe:foo { 1 } kprobe:bar { 1 }"); + + EXPECT_TRUE(bytecode.hasSection("s_kprobe:foo_1")); + EXPECT_TRUE(bytecode.hasSection("s_kprobe:bar_2")); +} + +} // namespace bpfbytecode +} // namespace test +} // namespace bpftrace diff --git a/tests/codegen/general.cpp b/tests/codegen/general.cpp index b9e828e1cf50..1f1466e7826a 100644 --- a/tests/codegen/general.cpp +++ b/tests/codegen/general.cpp @@ -47,23 +47,6 @@ class MockBPFtrace : public BPFtrace } }; -TEST(codegen, populate_sections) -{ - auto bpftrace = get_mock_bpftrace(); - Driver driver(*bpftrace); - - ASSERT_EQ(driver.parse_str("kprobe:foo { 1 } kprobe:bar { 1 }"), 0); - // Override to mockbpffeature. - bpftrace->feature_ = std::make_unique(true); - ast::SemanticAnalyser semantics(driver.root.get(), *bpftrace); - ASSERT_EQ(semantics.analyse(), 0); - ast::CodegenLLVM codegen(driver.root.get(), *bpftrace); - auto bytecode = codegen.compile(); - - EXPECT_TRUE(bytecode.hasSection("s_kprobe:foo_1")); - EXPECT_TRUE(bytecode.hasSection("s_kprobe:bar_2")); -} - TEST(codegen, printf_offsets) { auto bpftrace = get_mock_bpftrace();