All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Dmitrii Dolgov <9erthalion6@gmail.com>,
	bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org, songliubraving@fb.com
Subject: Re: [RFC PATCH bpf-next 2/2] selftests/bpf: Add bpf link iter test
Date: Thu, 28 Apr 2022 09:42:07 -0700	[thread overview]
Message-ID: <088195e3-c94f-4f92-f627-f901c9a40eb0@fb.com> (raw)
In-Reply-To: <20220422182254.13693-3-9erthalion6@gmail.com>



On 4/22/22 11:22 AM, Dmitrii Dolgov 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)

This function is used. Please add a proper subtest for this
in function test_bpf_iter().

> +{
> +	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;

This is not correct. You should have CHECK(!skel, ...) to return
only if skel is NULL. The error message "skeleton open_and_load 
unexpected success\n" is not correct either. Probably a copy-paste
error.

Also, since you are working on this file, probably convert all
CHECK's in this file to ASSERT_*() macros as patch #2. Then
this patch itself can be patch #3 using ASSERT_*() as well.

> +
> +	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 */

copyright issue.

> +#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)

Please put bpf_iter__bpf_link definition in bpf_iter.h so
the test can work with an old version of vmlinux.h.

> +{
> +	struct seq_file *seq = ctx->meta->seq;
> +	struct bpf_link *link = ctx->link;
> +	int link_id;

The 'link' pointer could be NULL as in previous patch
we have:

+	.ctx_arg_info		= {
+		{ offsetof(struct bpf_iter__bpf_link, link),
+		  PTR_TO_BTF_ID_OR_NULL },
+	},

So you need to add a check below.

	if (!link)
		return 0;

> +
> +	link_id = link->id;
> +	bpf_seq_write(seq, &link_id, sizeof(link_id));
> +	return 0;
> +}

  parent reply	other threads:[~2022-04-28 16:42 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
2022-04-28 16:42   ` Yonghong Song [this message]
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=088195e3-c94f-4f92-f627-f901c9a40eb0@fb.com \
    --to=yhs@fb.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 \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.