Commit b7896486 authored by Jiri Olsa's avatar Jiri Olsa Committed by Alexei Starovoitov

selftests/bpf: Add fill_link_info test for perf event

Adding fill_link_info test for perf event and testing we
get its values back through the bpf_link_info interface.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Acked-by: default avatarSong Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20240119110505.400573-7-jolsa@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent d7417970
...@@ -109,6 +109,11 @@ static int verify_perf_link_info(int fd, enum bpf_perf_event_type type, long add ...@@ -109,6 +109,11 @@ static int verify_perf_link_info(int fd, enum bpf_perf_event_type type, long add
strlen(UPROBE_FILE)); strlen(UPROBE_FILE));
ASSERT_EQ(err, 0, "cmp_file_name"); ASSERT_EQ(err, 0, "cmp_file_name");
break; break;
case BPF_PERF_EVENT_EVENT:
ASSERT_EQ(info.perf_event.event.type, PERF_TYPE_SOFTWARE, "event_type");
ASSERT_EQ(info.perf_event.event.config, PERF_COUNT_SW_PAGE_FAULTS, "event_config");
ASSERT_EQ(info.perf_event.event.cookie, PERF_EVENT_COOKIE, "event_cookie");
break;
default: default:
err = -1; err = -1;
break; break;
...@@ -189,6 +194,39 @@ static void test_tp_fill_link_info(struct test_fill_link_info *skel) ...@@ -189,6 +194,39 @@ static void test_tp_fill_link_info(struct test_fill_link_info *skel)
bpf_link__destroy(link); bpf_link__destroy(link);
} }
static void test_event_fill_link_info(struct test_fill_link_info *skel)
{
DECLARE_LIBBPF_OPTS(bpf_perf_event_opts, opts,
.bpf_cookie = PERF_EVENT_COOKIE,
);
struct bpf_link *link;
int link_fd, err, pfd;
struct perf_event_attr attr = {
.type = PERF_TYPE_SOFTWARE,
.config = PERF_COUNT_SW_PAGE_FAULTS,
.freq = 1,
.sample_freq = 1,
.size = sizeof(struct perf_event_attr),
};
pfd = syscall(__NR_perf_event_open, &attr, -1 /* pid */, 0 /* cpu 0 */,
-1 /* group id */, 0 /* flags */);
if (!ASSERT_GE(pfd, 0, "perf_event_open"))
return;
link = bpf_program__attach_perf_event_opts(skel->progs.event_run, pfd, &opts);
if (!ASSERT_OK_PTR(link, "attach_event"))
goto error;
link_fd = bpf_link__fd(link);
err = verify_perf_link_info(link_fd, BPF_PERF_EVENT_EVENT, 0, 0, 0);
ASSERT_OK(err, "verify_perf_link_info");
bpf_link__destroy(link);
error:
close(pfd);
}
static void test_uprobe_fill_link_info(struct test_fill_link_info *skel, static void test_uprobe_fill_link_info(struct test_fill_link_info *skel,
enum bpf_perf_event_type type) enum bpf_perf_event_type type)
{ {
...@@ -549,6 +587,8 @@ void test_fill_link_info(void) ...@@ -549,6 +587,8 @@ void test_fill_link_info(void)
test_kprobe_fill_link_info(skel, BPF_PERF_EVENT_KPROBE, true); test_kprobe_fill_link_info(skel, BPF_PERF_EVENT_KPROBE, true);
if (test__start_subtest("tracepoint_link_info")) if (test__start_subtest("tracepoint_link_info"))
test_tp_fill_link_info(skel); test_tp_fill_link_info(skel);
if (test__start_subtest("event_link_info"))
test_event_fill_link_info(skel);
uprobe_offset = get_uprobe_offset(&uprobe_func); uprobe_offset = get_uprobe_offset(&uprobe_func);
if (test__start_subtest("uprobe_link_info")) if (test__start_subtest("uprobe_link_info"))
......
...@@ -33,6 +33,12 @@ int BPF_PROG(tp_run) ...@@ -33,6 +33,12 @@ int BPF_PROG(tp_run)
return 0; return 0;
} }
SEC("perf_event")
int event_run(void *ctx)
{
return 0;
}
SEC("kprobe.multi") SEC("kprobe.multi")
int BPF_PROG(kmulti_run) int BPF_PROG(kmulti_run)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment