diff options
| author | Wang Nan <wangnan0@huawei.com> | 2016-11-26 02:03:37 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-12-05 13:51:44 -0500 |
| commit | e67d52d411c3562263735479db2efd2ebd178db9 (patch) | |
| tree | a88eae1461ecd9c0cfc84cb0f69faf9bbbfda859 /tools/perf/util/c++ | |
| parent | a9495fe9dc63bee1166772b6f10e199ef1747892 (diff) | |
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.cpp | 17 |
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 @@ | |||
| 3 | #include "llvm/IR/Function.h" | 3 | #include "llvm/IR/Function.h" |
| 4 | #include "llvm/IR/LLVMContext.h" | 4 | #include "llvm/IR/LLVMContext.h" |
| 5 | 5 | ||
| 6 | #include <util-cxx.h> | ||
| 7 | #include <tests/llvm.h> | ||
| 8 | #include <string> | ||
| 9 | |||
| 6 | class perf_clang_scope { | 10 | class perf_clang_scope { |
| 7 | public: | 11 | public: |
| 8 | explicit perf_clang_scope() {perf_clang__init();} | 12 | explicit perf_clang_scope() {perf_clang__init();} |
| @@ -14,17 +18,24 @@ extern "C" { | |||
| 14 | int test__clang_to_IR(void) | 18 | int test__clang_to_IR(void) |
| 15 | { | 19 | { |
| 16 | perf_clang_scope _scope; | 20 | perf_clang_scope _scope; |
| 21 | unsigned int kernel_version; | ||
| 22 | |||
| 23 | if (fetch_kernel_version(&kernel_version, NULL, 0)) | ||
| 24 | return -1; | ||
| 25 | |||
| 26 | std::string cflag_kver("-DLINUX_VERSION_CODE=" + | ||
| 27 | std::to_string(kernel_version)); | ||
| 17 | 28 | ||
| 18 | std::unique_ptr<llvm::Module> M = | 29 | std::unique_ptr<llvm::Module> M = |
| 19 | perf::getModuleFromSource({"-DRESULT=1"}, | 30 | perf::getModuleFromSource({cflag_kver.c_str()}, |
| 20 | "perf-test.c", | 31 | "perf-test.c", |
| 21 | "int myfunc(void) {return RESULT;}"); | 32 | test_llvm__bpf_base_prog); |
| 22 | 33 | ||
| 23 | if (!M) | 34 | if (!M) |
| 24 | return -1; | 35 | return -1; |
| 25 | 36 | ||
| 26 | for (llvm::Function& F : *M) | 37 | for (llvm::Function& F : *M) |
| 27 | if (F.getName() == "myfunc") | 38 | if (F.getName() == "bpf_func__SyS_epoll_wait") |
| 28 | return 0; | 39 | return 0; |
| 29 | return -1; | 40 | return -1; |
| 30 | } | 41 | } |
