From: Kumar Kartikeya Dwivedi <[email protected]>
To: [email protected]
Cc: Alexei Starovoitov <[email protected]>,
Daniel Borkmann <[email protected]>,
Andrii Nakryiko <[email protected]>,
Pavel Emelyanov <[email protected]>,
Alexander Mihalicyn <[email protected]>,
Andrei Vagin <[email protected]>,
[email protected], [email protected],
[email protected]
Subject: [PATCH bpf-next v1 7/8] selftests/bpf: Test partial reads for io_uring, epoll iterators
Date: Tue, 16 Nov 2021 11:12:36 +0530 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
Ensure that the output is consistent in face of partial reads that
return to userspace and then resume again later. To this end, we do
reads in 1-byte chunks, which is a bit stupid in real life, but works
well to simulate interrupted iteration. This also tests case where
seq_file buffer is consumed (after seq_printf) on interrupted read
before iterator invoked BPF prog again.
Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]>
---
.../selftests/bpf/prog_tests/bpf_iter.c | 33 ++++++++++++-------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
index 45e186385f9a..c27f3e10211c 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
@@ -72,13 +72,13 @@ static void do_dummy_read(struct bpf_program *prog)
bpf_link__destroy(link);
}
-static int read_fd_into_buffer(int fd, char *buf, int size)
+static int __read_fd_into_buffer(int fd, char *buf, int size, size_t chunks)
{
int bufleft = size;
int len;
do {
- len = read(fd, buf, bufleft);
+ len = read(fd, buf, chunks ?: bufleft);
if (len > 0) {
buf += len;
bufleft -= len;
@@ -88,6 +88,11 @@ static int read_fd_into_buffer(int fd, char *buf, int size)
return len < 0 ? len : size - bufleft;
}
+static int read_fd_into_buffer(int fd, char *buf, int size)
+{
+ return __read_fd_into_buffer(fd, buf, size, 0);
+}
+
static void test_ipv6_route(void)
{
struct bpf_iter_ipv6_route *skel;
@@ -1281,7 +1286,7 @@ static unsigned long long page_addr_to_pfn(unsigned long addr)
return pfn & 0x7fffffffffffff;
}
-void test_io_uring_buf(void)
+void test_io_uring_buf(bool partial)
{
DECLARE_LIBBPF_OPTS(bpf_iter_attach_opts, opts);
char rbuf[4096], buf[4096] = "B\n";
@@ -1352,7 +1357,7 @@ void test_io_uring_buf(void)
if (!ASSERT_GE(iter_fd, 0, "bpf_iter_create"))
goto end_close_fd;
- ret = read_fd_into_buffer(iter_fd, rbuf, sizeof(rbuf));
+ ret = __read_fd_into_buffer(iter_fd, rbuf, sizeof(rbuf), partial);
if (!ASSERT_GT(ret, 0, "read_fd_into_buffer"))
goto end_close_iter;
@@ -1374,7 +1379,7 @@ void test_io_uring_buf(void)
bpf_iter_io_uring__destroy(skel);
}
-void test_io_uring_file(void)
+void test_io_uring_file(bool partial)
{
int reg_files[] = { [0 ... 7] = -1 };
DECLARE_LIBBPF_OPTS(bpf_iter_attach_opts, opts);
@@ -1439,7 +1444,7 @@ void test_io_uring_file(void)
if (!ASSERT_OK(ret, "io_uring_register_files"))
goto end_iter_fd;
- ret = read_fd_into_buffer(iter_fd, rbuf, sizeof(rbuf));
+ ret = __read_fd_into_buffer(iter_fd, rbuf, sizeof(rbuf), partial);
if (!ASSERT_GT(ret, 0, "read_fd_into_buffer(iterator_fd, buf)"))
goto end_iter_fd;
@@ -1463,7 +1468,7 @@ void test_io_uring_file(void)
bpf_iter_io_uring__destroy(skel);
}
-void test_epoll(void)
+void test_epoll(bool partial)
{
const char *fmt = "B\npipe:%d\nsocket:%d\npipe:%d\nsocket:%d\nE\n";
DECLARE_LIBBPF_OPTS(bpf_iter_attach_opts, opts);
@@ -1529,7 +1534,7 @@ void test_epoll(void)
if (!ASSERT_GE(ret, 0, "snprintf") || !ASSERT_LT(ret, sizeof(buf), "snprintf"))
goto end_iter_fd;
- ret = read_fd_into_buffer(iter_fd, rbuf, sizeof(rbuf));
+ ret = __read_fd_into_buffer(iter_fd, rbuf, sizeof(rbuf), partial);
if (!ASSERT_GT(ret, 0, "read_fd_into_buffer"))
goto end_iter_fd;
@@ -1641,9 +1646,15 @@ void test_bpf_iter(void)
if (test__start_subtest("buf-neg-offset"))
test_buf_neg_offset();
if (test__start_subtest("io_uring_buf"))
- test_io_uring_buf();
+ test_io_uring_buf(false);
if (test__start_subtest("io_uring_file"))
- test_io_uring_file();
+ test_io_uring_file(false);
if (test__start_subtest("epoll"))
- test_epoll();
+ test_epoll(false);
+ if (test__start_subtest("io_uring_buf-partial"))
+ test_io_uring_buf(true);
+ if (test__start_subtest("io_uring_file-partial"))
+ test_io_uring_file(true);
+ if (test__start_subtest("epoll-partial"))
+ test_epoll(true);
}
--
2.33.1
next prev parent reply other threads:[~2021-11-16 5:59 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-16 5:42 [PATCH bpf-next v1 0/8] Introduce BPF iterators for io_uring and epoll Kumar Kartikeya Dwivedi
2021-11-16 5:42 ` [PATCH bpf-next v1 1/8] io_uring: Implement eBPF iterator for registered buffers Kumar Kartikeya Dwivedi
2021-11-18 17:21 ` Yonghong Song
2021-11-18 18:28 ` Kumar Kartikeya Dwivedi
2021-11-18 19:13 ` Yonghong Song
2021-11-18 22:02 ` Alexei Starovoitov
2021-11-19 4:15 ` Kumar Kartikeya Dwivedi
2021-11-19 4:44 ` Kumar Kartikeya Dwivedi
2021-11-19 4:56 ` Alexei Starovoitov
2021-11-19 5:16 ` Kumar Kartikeya Dwivedi
2021-11-19 5:24 ` Alexei Starovoitov
2021-11-19 6:12 ` Kumar Kartikeya Dwivedi
2021-12-03 15:52 ` Pavel Begunkov
2021-12-03 23:16 ` Kumar Kartikeya Dwivedi
2021-11-16 5:42 ` [PATCH bpf-next v1 2/8] bpf: Add bpf_page_to_pfn helper Kumar Kartikeya Dwivedi
2021-11-17 12:35 ` kernel test robot
2021-11-17 13:39 ` kernel test robot
2021-11-18 17:27 ` Yonghong Song
2021-11-18 18:30 ` Kumar Kartikeya Dwivedi
2021-11-18 19:18 ` Yonghong Song
2021-11-18 19:22 ` Kumar Kartikeya Dwivedi
2021-11-16 5:42 ` [PATCH bpf-next v1 3/8] io_uring: Implement eBPF iterator for registered files Kumar Kartikeya Dwivedi
2021-11-18 17:33 ` Yonghong Song
2021-11-16 5:42 ` [PATCH bpf-next v1 4/8] epoll: Implement eBPF iterator for registered items Kumar Kartikeya Dwivedi
2021-11-18 17:50 ` Yonghong Song
2021-11-16 5:42 ` [PATCH bpf-next v1 5/8] selftests/bpf: Add test for io_uring BPF iterators Kumar Kartikeya Dwivedi
2021-11-18 17:54 ` Yonghong Song
2021-11-18 18:33 ` Kumar Kartikeya Dwivedi
2021-11-18 19:21 ` Yonghong Song
2021-11-16 5:42 ` [PATCH bpf-next v1 6/8] selftests/bpf: Add test for epoll BPF iterator Kumar Kartikeya Dwivedi
2021-11-16 5:42 ` Kumar Kartikeya Dwivedi [this message]
2021-11-16 5:42 ` [PATCH bpf-next v1 8/8] selftests/bpf: Fix btf_dump test for bpf_iter_link_info Kumar Kartikeya Dwivedi
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 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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