public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Artem Savkov <asavkov@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, jbenc@redhat.com
Subject: Re: [PATCH bpf-next] selftests/bpf: make libbpf_probe_prog_types testcase aware of kernel configuration
Date: Fri, 30 Sep 2022 19:37:38 +0200	[thread overview]
Message-ID: <YzcpYjkv8RBaZQcM@krava> (raw)
In-Reply-To: <20220930110900.75492-1-asavkov@redhat.com>

On Fri, Sep 30, 2022 at 01:09:00PM +0200, Artem Savkov wrote:
> At the moment libbpf_probe_prog_types test iterates over all available
> BPF_PROG_TYPE regardless of kernel configuration which can exclude some
> of those. Unfortunately there is no direct way to tell which types are
> available, but we can look at struct bpf_ctx_onvert to tell which ones
> are available.
> 
> Signed-off-by: Artem Savkov <asavkov@redhat.com>
> ---
>  .../selftests/bpf/prog_tests/libbpf_probes.c  | 33 +++++++++++++++++--
>  1 file changed, 31 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> index 9f766ddd946ab..753ddf79cf5e0 100644
> --- a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> +++ b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> @@ -4,12 +4,29 @@
>  #include <test_progs.h>
>  #include <bpf/btf.h>
>  
> +static int find_type_in_ctx_convert(struct btf *btf,
> +				    const char *prog_type_name,
> +				    const struct btf_type *t)
> +{
> +	const struct btf_member *m;
> +	size_t cmplen = strlen(prog_type_name);
> +	int i, n;
> +
> +	for (m = btf_members(t), i = 0, n = btf_vlen(t); i < n; m++, i++) {
> +		const char *member_name = btf__str_by_offset(btf, m->name_off);
> +
> +		if (!strncmp(prog_type_name, member_name, cmplen))
> +			return 1;
> +	}
> +	return 0;
> +}
> +
>  void test_libbpf_probe_prog_types(void)
>  {
>  	struct btf *btf;
> -	const struct btf_type *t;
> +	const struct btf_type *t, *context_convert_t;
>  	const struct btf_enum *e;
> -	int i, n, id;
> +	int i, n, id, context_convert_id;
>  
>  	btf = btf__parse("/sys/kernel/btf/vmlinux", NULL);
>  	if (!ASSERT_OK_PTR(btf, "btf_parse"))
> @@ -23,6 +40,14 @@ void test_libbpf_probe_prog_types(void)
>  	if (!ASSERT_OK_PTR(t, "bpf_prog_type_enum"))
>  		goto cleanup;
>  
> +	context_convert_id = btf__find_by_name_kind(btf, "bpf_ctx_convert",
> +						    BTF_KIND_STRUCT);
> +	if (!ASSERT_GT(context_convert_id, 0, "bpf_ctx_convert_id"))
> +		goto cleanup;
> +	context_convert_t = btf__type_by_id(btf, context_convert_id);
> +	if (!ASSERT_OK_PTR(t, "bpf_ctx_convert_type"))

ASSERT_OK_PTR should check context_convert_t ?

I wonder if we could traverse bpf_ctx_convert members directly
instead of bpf_prog_type enum, but maybe there'd be other issues

jirka

> +		goto cleanup;
> +
>  	for (e = btf_enum(t), i = 0, n = btf_vlen(t); i < n; e++, i++) {
>  		const char *prog_type_name = btf__str_by_offset(btf, e->name_off);
>  		enum bpf_prog_type prog_type = (enum bpf_prog_type)e->val;
> @@ -31,6 +56,10 @@ void test_libbpf_probe_prog_types(void)
>  		if (prog_type == BPF_PROG_TYPE_UNSPEC)
>  			continue;
>  
> +		if (!find_type_in_ctx_convert(btf, prog_type_name,
> +					      context_convert_t))
> +			continue;
> +
>  		if (!test__start_subtest(prog_type_name))
>  			continue;
>  
> -- 
> 2.37.3
> 

  reply	other threads:[~2022-09-30 17:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30 11:09 [PATCH bpf-next] selftests/bpf: make libbpf_probe_prog_types testcase aware of kernel configuration Artem Savkov
2022-09-30 17:37 ` Jiri Olsa [this message]
2022-09-30 23:06 ` Andrii Nakryiko
2022-10-03  6:56   ` Artem Savkov
2022-10-04  0:03     ` Andrii Nakryiko
2022-10-06  7:27       ` Artem Savkov

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=YzcpYjkv8RBaZQcM@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=asavkov@redhat.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jbenc@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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