On Fri, Apr 22, 2022 at 11:23 AM Dmitrii Dolgov <9erthalion6@xxxxxxxxx> wrote: > > Add a simple test for bpf link iterator > > Signed-off-by: Dmitrii Dolgov <9erthalion6@xxxxxxxxx> > --- > .../selftests/bpf/prog_tests/bpf_iter.c | 15 +++++++++++++++ > .../selftests/bpf/progs/bpf_iter_bpf_link.c | 18 ++++++++++++++++++ > 2 files changed, 33 insertions(+) > create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_bpf_link.c > > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c > index 2c403ddc8076..e14a7a6d925c 100644 > --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c > @@ -26,6 +26,7 @@ > #include "bpf_iter_bpf_sk_storage_map.skel.h" > #include "bpf_iter_test_kern5.skel.h" > #include "bpf_iter_test_kern6.skel.h" > +#include "bpf_iter_bpf_link.skel.h" > > static int duration; > > @@ -1172,6 +1173,20 @@ static void test_buf_neg_offset(void) > bpf_iter_test_kern6__destroy(skel); > } > > +static void test_link_iter(void) > +{ > + struct bpf_iter_bpf_link *skel; > + > + skel = bpf_iter_bpf_link__open_and_load(); > + if (CHECK(skel, "bpf_iter_bpf_link__open_and_load", > + "skeleton open_and_load unexpected success\n")) > + return; > + please don't use CHECK() for new tests, you need ASSERT_OK_PTR() here > + do_dummy_read(skel->progs.dump_bpf_link); > + > + bpf_iter_bpf_link__destroy(skel); > +} > + > #define CMP_BUFFER_SIZE 1024 > static char task_vma_output[CMP_BUFFER_SIZE]; > static char proc_maps_output[CMP_BUFFER_SIZE]; > diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_bpf_link.c b/tools/testing/selftests/bpf/progs/bpf_iter_bpf_link.c > new file mode 100644 > index 000000000000..a5041fa1cda9 > --- /dev/null > +++ b/tools/testing/selftests/bpf/progs/bpf_iter_bpf_link.c > @@ -0,0 +1,18 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* Copyright (c) 2020 Facebook */ > +#include "bpf_iter.h" > +#include <bpf/bpf_helpers.h> > + > +char _license[] SEC("license") = "GPL"; > + > +SEC("iter/bpf_link") > +int dump_bpf_link(struct bpf_iter__bpf_link *ctx) see progs/bpf_iter.h, let's add bpf_iter__bpf_link there as well > +{ > + struct seq_file *seq = ctx->meta->seq; > + struct bpf_link *link = ctx->link; > + int link_id; > + > + link_id = link->id; > + bpf_seq_write(seq, &link_id, sizeof(link_id)); > + return 0; > +} > -- > 2.32.0 >