On Thu, Jul 06, 2023 at 09:32:15PM -0700, Andrii Nakryiko wrote: > On Fri, Jun 30, 2023 at 1:37 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote: > > > > Adding uprobe_multi test for bpf_program__attach_uprobe_multi > > attach function. > > > > Testing attachment using glob patterns and via bpf_uprobe_multi_opts > > paths/syms fields. > > > > Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx> > > --- > > .../bpf/prog_tests/uprobe_multi_test.c | 71 +++++++++++++++++++ > > 1 file changed, 71 insertions(+) > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c > > index 5cd1116bbb62..f97a68871e73 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c > > +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c > > @@ -69,8 +69,79 @@ static void test_skel_api(void) > > uprobe_multi__destroy(skel); > > } > > > > +static void > > +test_attach_api(const char *binary, const char *pattern, struct bpf_uprobe_multi_opts *opts) > > +{ > > + struct bpf_link *link1 = NULL, *link2 = NULL; > > + struct bpf_link *link3 = NULL, *link4 = NULL; > > + struct uprobe_multi *skel = NULL; > > + > > + skel = uprobe_multi__open_and_load(); > > + if (!ASSERT_OK_PTR(skel, "uprobe_multi__open_and_load")) > > + goto cleanup; > > + > > + opts->retprobe = false; > > + link1 = bpf_program__attach_uprobe_multi(skel->progs.test_uprobe, -1, > > + binary, pattern, opts); > > + if (!ASSERT_OK_PTR(link1, "bpf_program__attach_uprobe_multi")) > > + goto cleanup; > > + > > + opts->retprobe = true; > > + link2 = bpf_program__attach_uprobe_multi(skel->progs.test_uretprobe, -1, > > + binary, pattern, opts); > > + if (!ASSERT_OK_PTR(link2, "bpf_program__attach_uprobe_multi_retprobe")) > > + goto cleanup; > > + > > + opts->retprobe = false; > > + link3 = bpf_program__attach_uprobe_multi(skel->progs.test_uprobe_sleep, -1, > > + binary, pattern, opts); > > + if (!ASSERT_OK_PTR(link1, "bpf_program__attach_uprobe_multi")) > > link3 > > > + goto cleanup; > > + > > + opts->retprobe = true; > > + link4 = bpf_program__attach_uprobe_multi(skel->progs.test_uretprobe_sleep, -1, > > + binary, pattern, opts); > > + if (!ASSERT_OK_PTR(link2, "bpf_program__attach_uprobe_multi_retprobe")) > > link4 > > > + goto cleanup; > > + > > + uprobe_multi_test_run(skel); > > + > > +cleanup: > > + bpf_link__destroy(link4); > > + bpf_link__destroy(link3); > > + bpf_link__destroy(link2); > > + bpf_link__destroy(link1); > > you could have used > skel->links.{test_uprobe,test_uretprobe,test_uprobe_sleep,test_uretprobe_sleep} > "containers" to not manage destruction of these links manually ah right, I keep forgetting we have those variables ready in there :-\ will change thanks, jirka > > > + uprobe_multi__destroy(skel); > > +} > > + > > +static void test_attach_api_pattern(void) > > +{ > > + LIBBPF_OPTS(bpf_uprobe_multi_opts, opts); > > + > > + test_attach_api("/proc/self/exe", "uprobe_multi_func_*", &opts); > > + test_attach_api("/proc/self/exe", "uprobe_multi_func_?", &opts); > > +} > > + > > [...]