summaryrefslogtreecommitdiff
path: root/tools/perf/util/c++
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-11-26 10:03:37 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-12-05 21:51:44 +0300
commite67d52d411c3562263735479db2efd2ebd178db9 (patch)
treea88eae1461ecd9c0cfc84cb0f69faf9bbbfda859 /tools/perf/util/c++
parenta9495fe9dc63bee1166772b6f10e199ef1747892 (diff)
downloadlinux-e67d52d411c3562263735479db2efd2ebd178db9.tar.xz
perf clang: Update test case to use real BPF script
Allow C++ code to use util.h and tests/llvm.h. Let 'perf test' compile a real BPF script. 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-14-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/c++')
-rw-r--r--tools/perf/util/c++/clang-test.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/tools/perf/util/c++/clang-test.cpp b/tools/perf/util/c++/clang-test.cpp
index 0f484fbb2b58..d84e760d2aab 100644
--- a/tools/perf/util/c++/clang-test.cpp
+++ b/tools/perf/util/c++/clang-test.cpp
@@ -3,6 +3,10 @@
#include "llvm/IR/Function.h"
#include "llvm/IR/LLVMContext.h"
+#include <util-cxx.h>
+#include <tests/llvm.h>
+#include <string>
+
class perf_clang_scope {
public:
explicit perf_clang_scope() {perf_clang__init();}
@@ -14,17 +18,24 @@ extern "C" {
int test__clang_to_IR(void)
{
perf_clang_scope _scope;
+ unsigned int kernel_version;
+
+ if (fetch_kernel_version(&kernel_version, NULL, 0))
+ return -1;
+
+ std::string cflag_kver("-DLINUX_VERSION_CODE=" +
+ std::to_string(kernel_version));
std::unique_ptr<llvm::Module> M =
- perf::getModuleFromSource({"-DRESULT=1"},
+ perf::getModuleFromSource({cflag_kver.c_str()},
"perf-test.c",
- "int myfunc(void) {return RESULT;}");
+ test_llvm__bpf_base_prog);
if (!M)
return -1;
for (llvm::Function& F : *M)
- if (F.getName() == "myfunc")
+ if (F.getName() == "bpf_func__SyS_epoll_wait")
return 0;
return -1;
}