[LTP] [PATCH v2 2/2] pipe2_04: Don't assume the minimum pipe size is getpagesize()
Wake Liu
wakel@google.com
Mon Nov 16 15:22:40 CET 2026
F_SETPIPE_SZ rounds the requested size up to the minimum pipe capacity,
which is a single pipe buffer of one kernel page. The test expects that
to be equal to the page size reported to userspace.
That is not the case when the page size reported to userspace differs
from the one the kernel uses internally. With the 16K page size
emulation that Android uses on x86_64 the test fails with:
TFAIL: Pipe size (4096) must be page size (16384)
Conversely, with 16K kernel pages and a 4K page size reported to
userspace, the minimum pipe size is 16384 instead of the expected 4096.
As the minimum pipe size can't be derived from getpagesize(), only
check that F_GETPIPE_SZ on the other end of the pipe returns the size
set by F_SETPIPE_SZ, which is what the test is about. The rest of the
test already uses the actual pipe size.
Suggested-by: Kalesh Singh <kaleshsingh@google.com>
Signed-off-by: Wake Liu <wakel@google.com>
---
Notes:
Changes in v2:
- Drop the check that the minimum pipe size doesn't exceed
getpagesize(), which fails when the kernel uses larger pages than
reported to userspace (Kalesh)
testcases/kernel/syscalls/pipe2/pipe2_04.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/testcases/kernel/syscalls/pipe2/pipe2_04.c b/testcases/kernel/syscalls/pipe2/pipe2_04.c
index 3911f95b4..91aacab79 100644
--- a/testcases/kernel/syscalls/pipe2/pipe2_04.c
+++ b/testcases/kernel/syscalls/pipe2/pipe2_04.c
@@ -57,11 +57,10 @@ static void test_pipe2(void)
static void setup(void)
{
- int page_size, pipe_size;
+ int pipe_size, set_size;
char *write_buffer;
SAFE_PIPE2(fds, O_NONBLOCK);
- page_size = SAFE_SYSCONF(_SC_PAGESIZE);
flags = SAFE_FCNTL(fds[1], F_GETFL);
if (!(flags & O_NONBLOCK))
@@ -70,17 +69,21 @@ static void setup(void)
* A pipe has two file descriptors.
* But in the kernel these two file descriptors point to the same pipe.
* So setting size from first file handle set size for the pipe.
+ *
+ * The size is rounded up to the minimum pipe capacity, i.e. a single
+ * pipe buffer of one kernel page, which can be smaller or larger than
+ * the page size reported to userspace.
*/
- SAFE_FCNTL(fds[0], F_SETPIPE_SZ, 0);
+ set_size = SAFE_FCNTL(fds[0], F_SETPIPE_SZ, 0);
/*
* So getting size from the second file descriptor return the size of
* the pipe which was changed before with first file descriptor.
*/
pipe_size = SAFE_FCNTL(fds[1], F_GETPIPE_SZ);
- if (pipe_size != page_size)
- tst_res(TFAIL, "Pipe size (%d) must be page size (%d)",
- pipe_size, page_size);
+ if (pipe_size != set_size)
+ tst_res(TFAIL, "Pipe size (%d) must be the size set (%d)",
+ pipe_size, set_size);
write_buffer = SAFE_MALLOC(pipe_size);
memset(write_buffer, 'x', pipe_size);
--
2.56.0.611.g1030f0b940-goog
More information about the ltp
mailing list