From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Dmitrii Dolgov <9erthalion6@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>, Yonghong Song <yhs@fb.com>,
Song Liu <songliubraving@fb.com>
Subject: Re: [RFC PATCH bpf-next 2/2] selftests/bpf: Add bpf link iter test
Date: Wed, 27 Apr 2022 12:03:40 -0700 [thread overview]
Message-ID: <CAEf4BzYSTOPiiEsksftkp1xkSw9JuCwtmiuZw4+nqREM_G=yMw@mail.gmail.com> (raw)
In-Reply-To: <20220422182254.13693-3-9erthalion6@gmail.com>
On Fri, Apr 22, 2022 at 11:23 AM Dmitrii Dolgov <9erthalion6@gmail.com> wrote:
>
> Add a simple test for bpf link iterator
>
> Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com>
> ---
> .../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
>
next prev parent reply other threads:[~2022-04-27 19:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-22 18:22 [RFC PATCH bpf-next 0/2] bpf: bpf link iterator Dmitrii Dolgov
2022-04-22 18:22 ` [RFC PATCH bpf-next 1/2] bpf: Add bpf_link iterator Dmitrii Dolgov
2022-04-27 19:03 ` Andrii Nakryiko
2022-04-28 16:14 ` Yonghong Song
[not found] ` <CA+q6zcXkSBrmnUt3jS+zggqJjUFJQ2J_qUmA4HXtcFmYzYppMg@mail.gmail.com>
2022-04-28 21:02 ` Yonghong Song
2022-04-22 18:22 ` [RFC PATCH bpf-next 2/2] selftests/bpf: Add bpf link iter test Dmitrii Dolgov
2022-04-27 19:03 ` Andrii Nakryiko [this message]
2022-04-28 16:42 ` Yonghong Song
2022-04-27 19:04 ` [RFC PATCH bpf-next 0/2] bpf: bpf link iterator Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAEf4BzYSTOPiiEsksftkp1xkSw9JuCwtmiuZw4+nqREM_G=yMw@mail.gmail.com' \
--to=andrii.nakryiko@gmail.com \
--cc=9erthalion6@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).