[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzbstXqV+oH8uBHDDSgSzOY722jv3SsYt+cZCW9Ebwk8+g@mail.gmail.com>
Date: Tue, 21 Sep 2021 14:53:28 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Hou Tao <houtao1@...wei.com>
Cc: Alexei Starovoitov <ast@...nel.org>, Yonghong Song <yhs@...com>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>
Subject: Re: [PATCH bpf-next v2 3/3] bpf/selftests: add test for writable bare tracepoint
On Fri, Sep 17, 2021 at 6:56 PM Hou Tao <houtao1@...wei.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@...wei.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;
> +}
> +
[...]
Powered by blists - more mailing lists