bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Hou Tao <houtao1@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>, Yonghong Song <yhs@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2 3/3] bpf/selftests: add test for writable bare tracepoint
Date: Tue, 21 Sep 2021 14:53:28 -0700	[thread overview]
Message-ID: <CAEf4BzbstXqV+oH8uBHDDSgSzOY722jv3SsYt+cZCW9Ebwk8+g@mail.gmail.com> (raw)
In-Reply-To: <20210918020958.1167652-4-houtao1@huawei.com>

On Fri, Sep 17, 2021 at 6:56 PM Hou Tao <houtao1@huawei.com> wrote:
>
> Add a writable bare tracepoint in bpf_testmod module, and
> trigger its calling when reading /sys/kernel/bpf_testmod
> with a specific buffer length. The reading will return
> the value in writable context if the early return flag
> is enabled in writable context.
>
> Signed-off-by: Hou Tao <houtao1@huawei.com>
> ---
>  .../bpf/bpf_testmod/bpf_testmod-events.h      | 15 ++++++++
>  .../selftests/bpf/bpf_testmod/bpf_testmod.c   | 10 ++++++
>  .../selftests/bpf/bpf_testmod/bpf_testmod.h   |  5 +++
>  .../selftests/bpf/prog_tests/module_attach.c  | 36 +++++++++++++++++++
>  .../selftests/bpf/progs/test_module_attach.c  | 14 ++++++++
>  5 files changed, 80 insertions(+)
>

[...]

> +static int trigger_module_test_writable(int *val)
> +{
> +       int fd, err;
> +       char buf[65];
> +       ssize_t rd;
> +
> +       fd = open("/sys/kernel/bpf_testmod", O_RDONLY);
> +       err = -errno;
> +       if (CHECK(fd < 0, "testmod_file_open", "failed: %d\n", err))
> +               return err;
> +
> +       rd = read(fd, buf, sizeof(buf) - 1);
> +       err = rd < 0 ? -errno : -ENODATA;
> +       if (CHECK(rd <= 0, "testmod_file_rd_val", "failed: rd %zd errno %d\n",
> +                 rd, errno)) {
> +               close(fd);
> +               return err;
> +       }
> +

please use ASSERT_xxx() consistently

> +       buf[rd] = '\0';
> +       *val = strtol(buf, NULL, 0);
> +       close(fd);
> +
> +       return 0;
> +}
> +

[...]

      reply	other threads:[~2021-09-21 21:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-18  2:09 [PATCH bpf-next v2 0/3] add support for writable bare tracepoint Hou Tao
2021-09-18  2:09 ` [PATCH bpf-next v2 1/3] bpf: support writable context for " Hou Tao
2021-09-18  2:09 ` [PATCH bpf-next v2 2/3] libbpf: support detecting and attaching of writable tracepoint program Hou Tao
2021-09-21 21:42   ` Andrii Nakryiko
2021-09-28 12:28     ` Hou Tao
2021-09-18  2:09 ` [PATCH bpf-next v2 3/3] bpf/selftests: add test for writable bare tracepoint Hou Tao
2021-09-21 21:53   ` Andrii Nakryiko [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=CAEf4BzbstXqV+oH8uBHDDSgSzOY722jv3SsYt+cZCW9Ebwk8+g@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=houtao1@huawei.com \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.org \
    --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).