diff options
author | Wang Nan <wangnan0@huawei.com> | 2016-11-26 02:03:38 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-12-05 13:51:44 -0500 |
commit | 5e08a76525b8f5e9aeb8b27d0466614abec070a9 (patch) | |
tree | 9b63f3b0fb1c35248e51c4b4f2aadf3ab68db6aa /tools/perf/util/c++/clang-test.cpp | |
parent | e67d52d411c3562263735479db2efd2ebd178db9 (diff) |
perf clang: Support compile IR to BPF object and add testcase
getBPFObjectFromModule() is introduced to compile LLVM IR(Module)
to BPF object. Add new testcase for it.
Test result:
$ ./buildperf/perf test -v clang
51: builtin clang support :
51.1: builtin clang compile C source to IR :
--- start ---
test child forked, pid 21822
test child finished with 0
---- end ----
builtin clang support subtest 0: Ok
51.2: builtin clang compile C source to ELF object :
--- start ---
test child forked, pid 21823
test child finished with 0
---- end ----
builtin clang support subtest 1: Ok
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Joe Stringer <joe@ovn.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/20161126070354.141764-15-wangnan0@huawei.com
[ Remove redundant "Test" from entry descriptions ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/c++/clang-test.cpp')
-rw-r--r-- | tools/perf/util/c++/clang-test.cpp | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/tools/perf/util/c++/clang-test.cpp b/tools/perf/util/c++/clang-test.cpp index d84e760d2aab..9b11e8c82798 100644 --- a/tools/perf/util/c++/clang-test.cpp +++ b/tools/perf/util/c++/clang-test.cpp | |||
@@ -13,15 +13,13 @@ public: | |||
13 | ~perf_clang_scope() {perf_clang__cleanup();} | 13 | ~perf_clang_scope() {perf_clang__cleanup();} |
14 | }; | 14 | }; |
15 | 15 | ||
16 | extern "C" { | 16 | static std::unique_ptr<llvm::Module> |
17 | 17 | __test__clang_to_IR(void) | |
18 | int test__clang_to_IR(void) | ||
19 | { | 18 | { |
20 | perf_clang_scope _scope; | ||
21 | unsigned int kernel_version; | 19 | unsigned int kernel_version; |
22 | 20 | ||
23 | if (fetch_kernel_version(&kernel_version, NULL, 0)) | 21 | if (fetch_kernel_version(&kernel_version, NULL, 0)) |
24 | return -1; | 22 | return std::unique_ptr<llvm::Module>(nullptr); |
25 | 23 | ||
26 | std::string cflag_kver("-DLINUX_VERSION_CODE=" + | 24 | std::string cflag_kver("-DLINUX_VERSION_CODE=" + |
27 | std::to_string(kernel_version)); | 25 | std::to_string(kernel_version)); |
@@ -30,14 +28,35 @@ int test__clang_to_IR(void) | |||
30 | perf::getModuleFromSource({cflag_kver.c_str()}, | 28 | perf::getModuleFromSource({cflag_kver.c_str()}, |
31 | "perf-test.c", | 29 | "perf-test.c", |
32 | test_llvm__bpf_base_prog); | 30 | test_llvm__bpf_base_prog); |
31 | return M; | ||
32 | } | ||
33 | |||
34 | extern "C" { | ||
35 | int test__clang_to_IR(void) | ||
36 | { | ||
37 | perf_clang_scope _scope; | ||
33 | 38 | ||
39 | auto M = __test__clang_to_IR(); | ||
34 | if (!M) | 40 | if (!M) |
35 | return -1; | 41 | return -1; |
36 | |||
37 | for (llvm::Function& F : *M) | 42 | for (llvm::Function& F : *M) |
38 | if (F.getName() == "bpf_func__SyS_epoll_wait") | 43 | if (F.getName() == "bpf_func__SyS_epoll_wait") |
39 | return 0; | 44 | return 0; |
40 | return -1; | 45 | return -1; |
41 | } | 46 | } |
42 | 47 | ||
48 | int test__clang_to_obj(void) | ||
49 | { | ||
50 | perf_clang_scope _scope; | ||
51 | |||
52 | auto M = __test__clang_to_IR(); | ||
53 | if (!M) | ||
54 | return -1; | ||
55 | |||
56 | auto Buffer = perf::getBPFObjectFromModule(&*M); | ||
57 | if (!Buffer) | ||
58 | return -1; | ||
59 | return 0; | ||
60 | } | ||
61 | |||
43 | } | 62 | } |