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 | |
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>
-rw-r--r-- | tools/perf/Makefile.config | 27 | ||||
-rw-r--r-- | tools/perf/tests/llvm.h | 7 | ||||
-rw-r--r-- | tools/perf/util/c++/clang-test.cpp | 17 | ||||
-rw-r--r-- | tools/perf/util/util-cxx.h | 26 |
4 files changed, 62 insertions, 15 deletions
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index b7c9c8051a33..09c2a9874f2f 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config | |||
@@ -212,24 +212,27 @@ ifeq ($(DEBUG),0) | |||
212 | endif | 212 | endif |
213 | endif | 213 | endif |
214 | 214 | ||
215 | CFLAGS += -I$(src-perf)/util/include | 215 | INC_FLAGS += -I$(src-perf)/util/include |
216 | CFLAGS += -I$(src-perf)/arch/$(ARCH)/include | 216 | INC_FLAGS += -I$(src-perf)/arch/$(ARCH)/include |
217 | CFLAGS += -I$(srctree)/tools/include/uapi | 217 | INC_FLAGS += -I$(srctree)/tools/include/uapi |
218 | CFLAGS += -I$(srctree)/tools/include/ | 218 | INC_FLAGS += -I$(srctree)/tools/include/ |
219 | CFLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/uapi | 219 | INC_FLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/uapi |
220 | CFLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/ | 220 | INC_FLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/ |
221 | CFLAGS += -I$(srctree)/tools/arch/$(ARCH)/ | 221 | INC_FLAGS += -I$(srctree)/tools/arch/$(ARCH)/ |
222 | 222 | ||
223 | # $(obj-perf) for generated common-cmds.h | 223 | # $(obj-perf) for generated common-cmds.h |
224 | # $(obj-perf)/util for generated bison/flex headers | 224 | # $(obj-perf)/util for generated bison/flex headers |
225 | ifneq ($(OUTPUT),) | 225 | ifneq ($(OUTPUT),) |
226 | CFLAGS += -I$(obj-perf)/util | 226 | INC_FLAGS += -I$(obj-perf)/util |
227 | CFLAGS += -I$(obj-perf) | 227 | INC_FLAGS += -I$(obj-perf) |
228 | endif | 228 | endif |
229 | 229 | ||
230 | CFLAGS += -I$(src-perf)/util | 230 | INC_FLAGS += -I$(src-perf)/util |
231 | CFLAGS += -I$(src-perf) | 231 | INC_FLAGS += -I$(src-perf) |
232 | CFLAGS += -I$(srctree)/tools/lib/ | 232 | INC_FLAGS += -I$(srctree)/tools/lib/ |
233 | |||
234 | CFLAGS += $(INC_FLAGS) | ||
235 | CXXFLAGS += $(INC_FLAGS) | ||
233 | 236 | ||
234 | CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE | 237 | CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE |
235 | 238 | ||
diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h index 0eaa604be99d..b83571758d83 100644 --- a/tools/perf/tests/llvm.h +++ b/tools/perf/tests/llvm.h | |||
@@ -1,6 +1,10 @@ | |||
1 | #ifndef PERF_TEST_LLVM_H | 1 | #ifndef PERF_TEST_LLVM_H |
2 | #define PERF_TEST_LLVM_H | 2 | #define PERF_TEST_LLVM_H |
3 | 3 | ||
4 | #ifdef __cplusplus | ||
5 | extern "C" { | ||
6 | #endif | ||
7 | |||
4 | #include <stddef.h> /* for size_t */ | 8 | #include <stddef.h> /* for size_t */ |
5 | #include <stdbool.h> /* for bool */ | 9 | #include <stdbool.h> /* for bool */ |
6 | 10 | ||
@@ -20,4 +24,7 @@ enum test_llvm__testcase { | |||
20 | int test_llvm__fetch_bpf_obj(void **p_obj_buf, size_t *p_obj_buf_sz, | 24 | int test_llvm__fetch_bpf_obj(void **p_obj_buf, size_t *p_obj_buf_sz, |
21 | enum test_llvm__testcase index, bool force, | 25 | enum test_llvm__testcase index, bool force, |
22 | bool *should_load_fail); | 26 | bool *should_load_fail); |
27 | #ifdef __cplusplus | ||
28 | } | ||
29 | #endif | ||
23 | #endif | 30 | #endif |
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 | } |
diff --git a/tools/perf/util/util-cxx.h b/tools/perf/util/util-cxx.h new file mode 100644 index 000000000000..0e0e019c9f34 --- /dev/null +++ b/tools/perf/util/util-cxx.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /* | ||
2 | * Support C++ source use utilities defined in util.h | ||
3 | */ | ||
4 | |||
5 | #ifndef PERF_UTIL_UTIL_CXX_H | ||
6 | #define PERF_UTIL_UTIL_CXX_H | ||
7 | |||
8 | #ifdef __cplusplus | ||
9 | extern "C" { | ||
10 | #endif | ||
11 | |||
12 | /* | ||
13 | * Now 'new' is the only C++ keyword found in util.h: | ||
14 | * in tools/include/linux/rbtree.h | ||
15 | * | ||
16 | * Other keywords, like class and delete, should be | ||
17 | * redefined if necessary. | ||
18 | */ | ||
19 | #define new _new | ||
20 | #include "util.h" | ||
21 | #undef new | ||
22 | |||
23 | #ifdef __cplusplus | ||
24 | } | ||
25 | #endif | ||
26 | #endif | ||