]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
00b86691 WN |
2 | #include "clang.h" |
3 | #include "clang-c.h" | |
4 | #include "llvm/IR/Function.h" | |
5 | #include "llvm/IR/LLVMContext.h" | |
6 | ||
e67d52d4 WN |
7 | #include <util-cxx.h> |
8 | #include <tests/llvm.h> | |
9 | #include <string> | |
10 | ||
00b86691 WN |
11 | class perf_clang_scope { |
12 | public: | |
13 | explicit perf_clang_scope() {perf_clang__init();} | |
14 | ~perf_clang_scope() {perf_clang__cleanup();} | |
15 | }; | |
16 | ||
5e08a765 WN |
17 | static std::unique_ptr<llvm::Module> |
18 | __test__clang_to_IR(void) | |
00b86691 | 19 | { |
e67d52d4 WN |
20 | unsigned int kernel_version; |
21 | ||
22 | if (fetch_kernel_version(&kernel_version, NULL, 0)) | |
5e08a765 | 23 | return std::unique_ptr<llvm::Module>(nullptr); |
e67d52d4 WN |
24 | |
25 | std::string cflag_kver("-DLINUX_VERSION_CODE=" + | |
26 | std::to_string(kernel_version)); | |
00b86691 WN |
27 | |
28 | std::unique_ptr<llvm::Module> M = | |
e67d52d4 | 29 | perf::getModuleFromSource({cflag_kver.c_str()}, |
a9495fe9 | 30 | "perf-test.c", |
e67d52d4 | 31 | test_llvm__bpf_base_prog); |
5e08a765 WN |
32 | return M; |
33 | } | |
34 | ||
35 | extern "C" { | |
36 | int test__clang_to_IR(void) | |
37 | { | |
38 | perf_clang_scope _scope; | |
00b86691 | 39 | |
5e08a765 | 40 | auto M = __test__clang_to_IR(); |
00b86691 WN |
41 | if (!M) |
42 | return -1; | |
00b86691 | 43 | for (llvm::Function& F : *M) |
e67d52d4 | 44 | if (F.getName() == "bpf_func__SyS_epoll_wait") |
00b86691 WN |
45 | return 0; |
46 | return -1; | |
47 | } | |
48 | ||
5e08a765 WN |
49 | int test__clang_to_obj(void) |
50 | { | |
51 | perf_clang_scope _scope; | |
52 | ||
53 | auto M = __test__clang_to_IR(); | |
54 | if (!M) | |
55 | return -1; | |
56 | ||
57 | auto Buffer = perf::getBPFObjectFromModule(&*M); | |
58 | if (!Buffer) | |
59 | return -1; | |
60 | return 0; | |
61 | } | |
62 | ||
00b86691 | 63 | } |