aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/c++/clang-test.cpp
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-11-26 02:03:34 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-12-05 13:51:43 -0500
commit00b86691c77c6576861b82a3cfe4d609800758fe (patch)
tree50161d349254c75fb8707c370c96cd8a205f3e9c /tools/perf/util/c++/clang-test.cpp
parentd58ac0bf8d1e6ffbfcb0a77e459cf4737b131b75 (diff)
perf clang: Add builtin clang support ant test case
Add basic clang support in clang.cpp and test__clang() testcase. The first testcase checks if builtin clang is able to generate LLVM IR. tests/clang.c is a proxy. Real testcase resides in utils/c++/clang-test.cpp in c++ and exports C interface to perf test subsystem. Test result: $ perf test -v clang 51: builtin clang support : 51.1: Test builtin clang compile C source to IR : --- start --- test child forked, pid 13215 test child finished with 0 ---- end ---- Test builtin clang support subtest 0: Ok Committer note: Make sure you've enabled CLANG and LLVM builtin support by setting the LIBCLANGLLVM variable on the make command line, e.g.: make LIBCLANGLLVM=1 O=/tmp/build/perf -C tools/perf install-bin Otherwise you'll get this when trying to do the 'perf test' call above: # perf test clang 51: builtin clang support : Skip (not compiled in) # Signed-off-by: Wang Nan <wangnan0@huawei.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.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-11-wangnan0@huawei.com [ Removed "Test" from descriptions, redundant and already removed from all the other entries ] 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, 31 insertions, 0 deletions
diff --git a/tools/perf/util/c++/clang-test.cpp b/tools/perf/util/c++/clang-test.cpp
new file mode 100644
index 000000000000..3da6bfa4bc54
--- /dev/null
+++ b/tools/perf/util/c++/clang-test.cpp
@@ -0,0 +1,31 @@
1#include "clang.h"
2#include "clang-c.h"
3#include "llvm/IR/Function.h"
4#include "llvm/IR/LLVMContext.h"
5
6class perf_clang_scope {
7public:
8 explicit perf_clang_scope() {perf_clang__init();}
9 ~perf_clang_scope() {perf_clang__cleanup();}
10};
11
12extern "C" {
13
14int test__clang_to_IR(void)
15{
16 perf_clang_scope _scope;
17
18 std::unique_ptr<llvm::Module> M =
19 perf::getModuleFromSource("perf-test.c",
20 "int myfunc(void) {return 1;}");
21
22 if (!M)
23 return -1;
24
25 for (llvm::Function& F : *M)
26 if (F.getName() == "myfunc")
27 return 0;
28 return -1;
29}
30
31}