2 #include <bpf/libbpf.h>
3 #include <util/llvm-utils.h>
4 #include <util/cache.h>
8 static int perf_config_cb(const char *var, const char *val,
9 void *arg __maybe_unused)
11 return perf_default_config(var, val, arg);
15 * Randomly give it a "version" section since we don't really load it
18 static const char test_bpf_prog[] =
19 "__attribute__((section(\"do_fork\"), used)) "
20 "int fork(void *ctx) {return 0;} "
21 "char _license[] __attribute__((section(\"license\"), used)) = \"GPL\";"
22 "int _version __attribute__((section(\"version\"), used)) = 0x40100;";
24 #ifdef HAVE_LIBBPF_SUPPORT
25 static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz)
27 struct bpf_object *obj;
29 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL);
32 bpf_object__close(obj);
36 static int test__bpf_parsing(void *obj_buf __maybe_unused,
37 size_t obj_buf_sz __maybe_unused)
39 fprintf(stderr, " (skip bpf parsing)");
46 char *tmpl_new, *clang_opt_new;
51 perf_config(perf_config_cb, NULL);
54 * Skip this test if user's .perfconfig doesn't set [llvm] section
55 * and clang is not found in $PATH, and this is not perf test -v
57 if (verbose == 0 && !llvm_param.user_set_param && llvm__search_clang()) {
58 fprintf(stderr, " (no clang, try 'perf test -v LLVM')");
62 old_verbose = verbose;
64 * llvm is verbosity when error. Suppress all error output if
70 if (!llvm_param.clang_bpf_cmd_template)
73 if (!llvm_param.clang_opt)
74 llvm_param.clang_opt = strdup("");
76 err = asprintf(&tmpl_new, "echo '%s' | %s", test_bpf_prog,
77 llvm_param.clang_bpf_cmd_template);
80 err = asprintf(&clang_opt_new, "-xc %s", llvm_param.clang_opt);
84 llvm_param.clang_bpf_cmd_template = tmpl_new;
85 llvm_param.clang_opt = clang_opt_new;
86 err = llvm__compile_bpf("-", &obj_buf, &obj_buf_sz);
88 verbose = old_verbose;
91 fprintf(stderr, " (use -v to see error message)");
95 err = test__bpf_parsing(obj_buf, obj_buf_sz);