aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/c++/clang-test.cpp
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-11-26 07:03:38 +0000
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-12-05 15:51:44 -0300
commit5e08a76525b8f5e9aeb8b27d0466614abec070a9 (patch)
tree9b63f3b0fb1c35248e51c4b4f2aadf3ab68db6aa /tools/perf/util/c++/clang-test.cpp
parentperf clang: Update test case to use real BPF script (diff)
downloadlinux-dev-5e08a76525b8f5e9aeb8b27d0466614abec070a9.tar.xz
linux-dev-5e08a76525b8f5e9aeb8b27d0466614abec070a9.zip
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.cpp31
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:
~perf_clang_scope() {perf_clang__cleanup();}
};
-extern "C" {
-
-int test__clang_to_IR(void)
+static std::unique_ptr<llvm::Module>
+__test__clang_to_IR(void)
{
- perf_clang_scope _scope;
unsigned int kernel_version;
if (fetch_kernel_version(&kernel_version, NULL, 0))
- return -1;
+ return std::unique_ptr<llvm::Module>(nullptr);
std::string cflag_kver("-DLINUX_VERSION_CODE=" +
std::to_string(kernel_version));
@@ -30,14 +28,35 @@ int test__clang_to_IR(void)
perf::getModuleFromSource({cflag_kver.c_str()},
"perf-test.c",
test_llvm__bpf_base_prog);
+ return M;
+}
+
+extern "C" {
+int test__clang_to_IR(void)
+{
+ perf_clang_scope _scope;
+ auto M = __test__clang_to_IR();
if (!M)
return -1;
-
for (llvm::Function& F : *M)
if (F.getName() == "bpf_func__SyS_epoll_wait")
return 0;
return -1;
}
+int test__clang_to_obj(void)
+{
+ perf_clang_scope _scope;
+
+ auto M = __test__clang_to_IR();
+ if (!M)
+ return -1;
+
+ auto Buffer = perf::getBPFObjectFromModule(&*M);
+ if (!Buffer)
+ return -1;
+ return 0;
+}
+
}