On Tue, Oct 11, 2022 at 12:27:12AM -0700, Song Liu wrote: > On Sun, Oct 9, 2022 at 3:01 PM Jiri Olsa <jolsa@xxxxxxxxxx> wrote: > > > > Adding kprobe_multi kmod link api tests that attach bpf_testmod > > functions via kprobe_multi link API. > > > > Running it as serial test, because we don't want other tests to > > reload bpf_testmod while it's running. > > > > Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx> > > --- > > .../prog_tests/kprobe_multi_testmod_test.c | 94 +++++++++++++++++++ > > .../selftests/bpf/progs/kprobe_multi.c | 51 ++++++++++ > > 2 files changed, 145 insertions(+) > > create mode 100644 tools/testing/selftests/bpf/prog_tests/kprobe_multi_testmod_test.c > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_testmod_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_testmod_test.c > > new file mode 100644 > > index 000000000000..5fe02572650a > > --- /dev/null > > +++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_testmod_test.c > > @@ -0,0 +1,94 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +#include <test_progs.h> > > +#include "kprobe_multi.skel.h" > > +#include "trace_helpers.h" > > +#include "bpf/libbpf_internal.h" > > + > > +static void kprobe_multi_testmod_check(struct kprobe_multi *skel) > > +{ > > + ASSERT_EQ(skel->bss->kprobe_testmod_test1_result, 1, "kprobe_test1_result"); > > + ASSERT_EQ(skel->bss->kprobe_testmod_test2_result, 1, "kprobe_test2_result"); > > + ASSERT_EQ(skel->bss->kprobe_testmod_test3_result, 1, "kprobe_test3_result"); > > + > > + ASSERT_EQ(skel->bss->kretprobe_testmod_test1_result, 1, "kretprobe_test1_result"); > > + ASSERT_EQ(skel->bss->kretprobe_testmod_test2_result, 1, "kretprobe_test2_result"); > > + ASSERT_EQ(skel->bss->kretprobe_testmod_test3_result, 1, "kretprobe_test3_result"); > > +} > > + > > +static void test_testmod_link_api(struct bpf_link_create_opts *opts) > > +{ > > + int prog_fd, link1_fd = -1, link2_fd = -1; > > + struct kprobe_multi *skel = NULL; > > + > > + skel = kprobe_multi__open_and_load(); > > + if (!ASSERT_OK_PTR(skel, "fentry_raw_skel_load")) > > + goto cleanup; > > nit: we can just return here. right, will change thanks, jirka > > Other than this: > > Acked-by: Song Liu <song@xxxxxxxxxx> > > > + > > + skel->bss->pid = getpid(); > > + prog_fd = bpf_program__fd(skel->progs.test_kprobe_testmod); > > + link1_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_KPROBE_MULTI, opts); > > + if (!ASSERT_GE(link1_fd, 0, "link_fd1")) > > + goto cleanup; > > + > > + opts->kprobe_multi.flags = BPF_F_KPROBE_MULTI_RETURN; > > + prog_fd = bpf_program__fd(skel->progs.test_kretprobe_testmod); > > + link2_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_KPROBE_MULTI, opts); > > + if (!ASSERT_GE(link2_fd, 0, "link_fd2")) > > + goto cleanup; > > + > > + ASSERT_OK(trigger_module_test_read(1), "trigger_read"); > > + kprobe_multi_testmod_check(skel); > > + > > +cleanup: > > + if (link1_fd != -1) > > + close(link1_fd); > > + if (link2_fd != -1) > > + close(link2_fd); > > + kprobe_multi__destroy(skel); > > +} > >