All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Hao Luo <haoluo@google.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>,
	Stanislav Fomichev <sdf@google.com>
Subject: Re: [PATCHv4 bpf-next 4/4] selftests/bpf: Add bpf_vma_build_id_parse task vma iterator test
Date: Tue, 29 Nov 2022 09:29:31 +0100	[thread overview]
Message-ID: <Y4XC6wxSflQUz9/p@krava> (raw)
In-Reply-To: <CA+khW7h_4GGGsyszYVfSKtbv0nnUSKc-_oCqXgsj=JQ9RaVy7A@mail.gmail.com>

On Mon, Nov 28, 2022 at 11:21:30AM -0800, Hao Luo wrote:
> On Mon, Nov 28, 2022 at 5:30 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Adding tests for using new bpf_vma_build_id_parse kfunc in task_vma
> > iterator program.
> >
> > On bpf program side the iterator filters test proccess and proper
> > vma by provided function pointer and reads its build id with the
> > new kfunc.
> >
> > On user side the test uses readelf to get test_progs build id and
> > compares it with the one read from iterator.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  .../selftests/bpf/prog_tests/bpf_iter.c       | 44 +++++++++++++++++++
> >  .../selftests/bpf/progs/bpf_iter_build_id.c   | 41 +++++++++++++++++
> >  2 files changed, 85 insertions(+)
> >  create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_build_id.c
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > index 6f8ed61fc4b4..b2cad9f70b32 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > @@ -33,6 +33,9 @@
> <...>
> >
> > +static void test_task_vma_build_id(void)
> > +{
> > +       struct bpf_iter_build_id *skel;
> > +       char buf[BUILDID_STR_SIZE] = {};
> 
> Jiri, do you mean buf[BUILDID_STR_SIZE + 1]? I see you have
> buf[BUILDID_STR_SIZE] = 0; below.

ugh, that plus one ended up in the BUILDID_STR_SIZE define, will fix

> 
> > +       int iter_fd, len;
> > +       char *build_id;
> <...>
> > +
> > +       while ((len = read(iter_fd, buf, sizeof(buf))) > 0)
> > +               ;
> 
> I think you need to pass 'buf + len' to read(), otherwise the last
> iteration will overwrite the content read from the previous
> iterations.

ok

> 
> > +       buf[BUILDID_STR_SIZE] = 0;
> > +
> > +       /* Read build_id via readelf to compare with iterator buf. */
> > +       if (!ASSERT_OK(read_self_buildid(&build_id), "read_buildid"))
> > +               goto exit;
> 
> We need to close iter_fd before going to exit.

right, will fix

thanks,
jirka

> 
> > +
> > +       ASSERT_STREQ(buf, build_id, "build_id_match");
> > +       ASSERT_GT(skel->data->size, 0, "size");
> > +
> > +       free(build_id);
> > +       close(iter_fd);
> > +exit:
> > +       bpf_iter_build_id__destroy(skel);
> > +}
> > +
> <...>
> > --
> > 2.38.1
> >

      reply	other threads:[~2022-11-29  8:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28 13:29 [PATCHv4 bpf-next 0/4] bpf: Add bpf_vma_build_id_parse kfunc Jiri Olsa
2022-11-28 13:29 ` [PATCHv4 bpf-next 1/4] bpf: Mark vma objects as trusted for task_vma iter and find_vma callback Jiri Olsa
2022-11-28 18:43   ` Alexei Starovoitov
2022-11-28 19:04     ` Yonghong Song
2022-11-28 20:25       ` Alexei Starovoitov
2022-11-28 13:29 ` [PATCHv4 bpf-next 2/4] bpf: Add bpf_vma_build_id_parse function and kfunc Jiri Olsa
2022-11-28 21:36   ` Alexei Starovoitov
2022-11-29  8:45     ` Jiri Olsa
2022-11-29  1:15   ` Andrii Nakryiko
2022-11-29  6:20     ` Hao Luo
2022-11-30  0:35       ` Andrii Nakryiko
2022-11-30  1:27         ` Hao Luo
2022-12-01  1:11           ` Andrii Nakryiko
2022-11-29  8:52     ` Jiri Olsa
2022-11-28 13:29 ` [PATCHv4 bpf-next 3/4] selftests/bpf: Add bpf_vma_build_id_parse find_vma callback test Jiri Olsa
2022-11-28 19:25   ` Hao Luo
2022-11-29  8:32     ` Jiri Olsa
2022-11-28 13:29 ` [PATCHv4 bpf-next 4/4] selftests/bpf: Add bpf_vma_build_id_parse task vma iterator test Jiri Olsa
2022-11-28 19:21   ` Hao Luo
2022-11-29  8:29     ` Jiri Olsa [this message]

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=Y4XC6wxSflQUz9/p@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=sdf@google.com \
    --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 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.