perf test: Enhance the LLVM tests: add kbuild test
authorWang Nan <wangnan0@huawei.com>
Fri, 6 Nov 2015 13:49:42 +0000 (13:49 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 6 Nov 2015 20:49:50 +0000 (17:49 -0300)
This patch adds a kbuild testcase to check whether kernel headers can be
correctly found.

For example:
  # mv /lib/modules/4.3.0-rc5{,.bak}
  # perf test LLVM

    38: Test LLVM searching and compiling                        : Skip

  # perf test -v LLVM
  ...
  <stdin>:11:10: fatal error: 'uapi/linux/fs.h' file not found
  #include <uapi/linux/fs.h>
          ^
  1 error generated.
  ERROR: unable to compile -
  Hint: Check error message shown above.
  Hint: You can also pre-compile it into .o using:
       clang -target bpf -O2 -c -
 with proper -I and -D options.
  Failed to compile test case: 'Test kbuild searching'
  test child finished with -2

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1446817783-86722-7-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/Build
tools/perf/tests/bpf-script-test-kbuild.c [new file with mode: 0644]
tools/perf/tests/llvm.c
tools/perf/tests/llvm.h

index 6c095b3d92a9bac4a3e4c5c0fa960e4d49278083..a47b21193fb2a057542410170c2d916d02ef74f0 100644 (file)
@@ -31,7 +31,7 @@ perf-y += sample-parsing.o
 perf-y += parse-no-sample-id-all.o
 perf-y += kmod-path.o
 perf-y += thread-map.o
-perf-y += llvm.o llvm-src-base.o
+perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o
 perf-y += topology.o
 
 $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c
@@ -41,6 +41,13 @@ $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c
        $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
        $(Q)echo ';' >> $@
 
+$(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c
+       $(call rule_mkdir)
+       $(Q)echo '#include <tests/llvm.h>' > $@
+       $(Q)echo 'const char test_llvm__bpf_test_kbuild_prog[] =' >> $@
+       $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
+       $(Q)echo ';' >> $@
+
 ifeq ($(ARCH),$(filter $(ARCH),x86 arm arm64))
 perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
 endif
diff --git a/tools/perf/tests/bpf-script-test-kbuild.c b/tools/perf/tests/bpf-script-test-kbuild.c
new file mode 100644 (file)
index 0000000..3626924
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * bpf-script-test-kbuild.c
+ * Test include from kernel header
+ */
+#ifndef LINUX_VERSION_CODE
+# error Need LINUX_VERSION_CODE
+# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
+#endif
+#define SEC(NAME) __attribute__((section(NAME), used))
+
+#include <uapi/linux/fs.h>
+#include <uapi/asm/ptrace.h>
+
+SEC("func=vfs_llseek")
+int bpf_func__vfs_llseek(void *ctx)
+{
+       return 0;
+}
+
+char _license[] SEC("license") = "GPL";
+int _version SEC("version") = LINUX_VERSION_CODE;
index 05683c5f183ee3846e5e433fac92644ec18129fe..bc4cf507cde50b7018bac107e152ba9f23ab007d 100644 (file)
@@ -40,6 +40,10 @@ static struct {
                .source = test_llvm__bpf_base_prog,
                .desc = "Basic BPF llvm compiling test",
        },
+       [LLVM_TESTCASE_KBUILD] = {
+               .source = test_llvm__bpf_test_kbuild_prog,
+               .desc = "Test kbuild searching",
+       },
 };
 
 
index bd63cee687b57fe8ea05b1c5f8f9e7deaec6e9e8..d91d8f44efeee2642a1dea7813b81a4299b7e067 100644 (file)
@@ -5,9 +5,11 @@
 #include <stdbool.h> /* for bool */
 
 extern const char test_llvm__bpf_base_prog[];
+extern const char test_llvm__bpf_test_kbuild_prog[];
 
 enum test_llvm__testcase {
        LLVM_TESTCASE_BASE,
+       LLVM_TESTCASE_KBUILD,
        __LLVM_TESTCASE_MAX,
 };