All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Dave Marchevsky <davemarchevsky@fb.com>
Cc: Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 2/3] selftests/bpf: add libbpf feature-probing API selftests
Date: Thu, 16 Dec 2021 16:42:08 -0800	[thread overview]
Message-ID: <CAEf4BzZydhBisHacU9Rjf1ZWik1_aUeiy6ANRfaUkebo7cYq5Q@mail.gmail.com> (raw)
In-Reply-To: <b183b2b8-3bff-f647-678f-40b479c9c5c5@fb.com>

On Thu, Dec 16, 2021 at 4:21 PM Dave Marchevsky <davemarchevsky@fb.com> wrote:
>
> On 12/16/21 2:04 AM, Andrii Nakryiko wrote:
> > Add selftests for prog/map/prog+helper feature probing APIs. Prog and
> > map selftests are designed in such a way that they will always test all
> > the possible prog/map types, based on running kernel's vmlinux BTF enum
> > definition. This way we'll always be sure that when adding new BPF
> > program types or map types, libbpf will be always updated accordingly to
> > be able to feature-detect them.
> >
> > BPF prog_helper selftest will have to be manually extended with
> > interesting and important prog+helper combinations, it's easy, but can't
> > be completely automated.
> >
> > Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> > ---
>
> [...]
>
> > +     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;
> > +             int res;
> > +
> > +             if (prog_type == BPF_PROG_TYPE_UNSPEC)
> > +                     continue;
> > +
> > +             if (!test__start_subtest(prog_type_name))
> > +                     continue;
> > +
> > +             res = libbpf_probe_bpf_prog_type(prog_type, NULL);
> > +             ASSERT_EQ(res, 1, prog_type_name);
> > +     }
>
> I like how easy BTF makes this.
> Maybe worth trying to probe one-past-the-end of enum to confirm it fails as
> expected?
>

Yeah, sure, not a bad idea, I'll add in v2.

> Regardless,
>
> Acked-by: Dave Marchevsky <davemarchevsky@fb.com>
>
> > +cleanup:
> > +     btf__free(btf);
> > +}
>
> [...]

  reply	other threads:[~2021-12-17  0:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16  7:04 [PATCH bpf-next 0/3] Revamp and fix libbpf's feature-probing APIs Andrii Nakryiko
2021-12-16  7:04 ` [PATCH bpf-next 1/3] libbpf: rework " Andrii Nakryiko
2021-12-17  0:10   ` Dave Marchevsky
2021-12-17  0:41     ` Andrii Nakryiko
2021-12-17  7:07       ` Dave Marchevsky
2021-12-16  7:04 ` [PATCH bpf-next 2/3] selftests/bpf: add libbpf feature-probing API selftests Andrii Nakryiko
2021-12-17  0:21   ` Dave Marchevsky
2021-12-17  0:42     ` Andrii Nakryiko [this message]
2021-12-17 17:09       ` Andrii Nakryiko
2021-12-16  7:04 ` [PATCH bpf-next 3/3] bpftool: reimplement large insn size limit feature probing Andrii Nakryiko
2021-12-17  0:36   ` Dave Marchevsky

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=CAEf4BzZydhBisHacU9Rjf1ZWik1_aUeiy6ANRfaUkebo7cYq5Q@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davemarchevsky@fb.com \
    --cc=kernel-team@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.