selftests/bpf: Add extra link to uprobe_multi tests
authorJiri Olsa <jolsa@kernel.org>
Wed, 9 Aug 2023 08:34:40 +0000 (10:34 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 21 Aug 2023 22:51:27 +0000 (15:51 -0700)
Attaching extra program to same functions system wide for api
and link tests.

This way we can test the pid filter works properly when there's
extra system wide consumer on the same uprobe that will trigger
the original uprobe handler.

We expect to have the same counts as before.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20230809083440.3209381-29-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
tools/testing/selftests/bpf/progs/uprobe_multi.c

index bc07921a5a77a56929eaf384c0c8f1240cba898c..cd051d3901a99d1ac026f692d78b0b6661cb234e 100644 (file)
@@ -184,6 +184,12 @@ __test_attach_api(const char *binary, const char *pattern, struct bpf_uprobe_mul
        if (!ASSERT_OK_PTR(skel->links.uretprobe_sleep, "bpf_program__attach_uprobe_multi"))
                goto cleanup;
 
+       opts->retprobe = false;
+       skel->links.uprobe_extra = bpf_program__attach_uprobe_multi(skel->progs.uprobe_extra, -1,
+                                                                   binary, pattern, opts);
+       if (!ASSERT_OK_PTR(skel->links.uprobe_extra, "bpf_program__attach_uprobe_multi"))
+               goto cleanup;
+
        uprobe_multi_test_run(skel, child);
 
 cleanup:
@@ -240,6 +246,7 @@ static void __test_link_api(struct child *child)
                "uprobe_multi_func_2",
                "uprobe_multi_func_3",
        };
+       int link_extra_fd = -1;
        int err;
 
        err = elf_resolve_syms_offsets(path, 3, syms, (unsigned long **) &offsets);
@@ -279,6 +286,13 @@ static void __test_link_api(struct child *child)
        if (!ASSERT_GE(link4_fd, 0, "link4_fd"))
                goto cleanup;
 
+       opts.kprobe_multi.flags = 0;
+       opts.uprobe_multi.pid = 0;
+       prog_fd = bpf_program__fd(skel->progs.uprobe_extra);
+       link_extra_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_UPROBE_MULTI, &opts);
+       if (!ASSERT_GE(link_extra_fd, 0, "link_extra_fd"))
+               goto cleanup;
+
        uprobe_multi_test_run(skel, child);
 
 cleanup:
@@ -290,6 +304,8 @@ cleanup:
                close(link3_fd);
        if (link4_fd >= 0)
                close(link4_fd);
+       if (link_extra_fd >= 0)
+               close(link_extra_fd);
 
        uprobe_multi__destroy(skel);
        free(offsets);
index ec648a6699e63917cd33f61a7831c0f67305e6d2..419d9aa28fce5cdf94e9976e6f8501a3551b4133 100644 (file)
@@ -93,3 +93,9 @@ int uretprobe_sleep(struct pt_regs *ctx)
        uprobe_multi_check(ctx, true, true);
        return 0;
 }
+
+SEC("uprobe.multi//proc/self/exe:uprobe_multi_func_*")
+int uprobe_extra(struct pt_regs *ctx)
+{
+       return 0;
+}