forked from bpftrace/bpftrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce unit tests for the new BpfBytecode class
For now, BpfBytecode only stores the sections, so move there the corresponding test from tests/codegen/general.cpp. The advantage is that now the test is executed for all LLVM versions instead of just LLVM 12.
- Loading branch information
1 parent
426c06f
commit 0f4ff11
Showing
3 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters