Add splice tests fro /dev/{zero,null,full}
cover Add splice tests fro /dev/{zero,null,full}
We came around this when we were doing pre-release testing for the splice07 test, the support for splicing to/from some dev files was likely unintentionaly removed and added back later on. This patchset implements first two basic splice tests for these device files.
Cyril Hrubis (2):
syscalls: Add test for splicing from /dev/zero and /dev/full
syscalls: Add test for splicing to /dev/zero and /dev/null
runtest/syscalls | 2 + testcases/kernel/syscalls/splice/.gitignore | 2 + testcases/kernel/syscalls/splice/splice08.c | 88 +++++++++++++++++++++ testcases/kernel/syscalls/splice/splice09.c | 55 +++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 testcases/kernel/syscalls/splice/splice08.c create mode 100644 testcases/kernel/syscalls/splice/splice09.c
Signature · 5 lines
2.43.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/2 syscalls: Add test for splicing from /dev/zero and /dev/full
Both of these devices produce zeroes when read.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/splice/.gitignore | 1 + testcases/kernel/syscalls/splice/splice08.c | 88 +++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 testcases/kernel/syscalls/splice/splice08.c
runtest/syscalls +1 -0
@@ -1517,6 +1517,7 @@ splice04 splice04 splice05 splice05 splice06 splice06 splice07 splice07 +splice08 splice08 tee01 tee01 tee02 tee02
testcases/kernel/syscalls/splice/.gitignore +1 -0
@@ -5,3 +5,4 @@ /splice05 /splice06 /splice07 +/splice08
testcases/kernel/syscalls/splice/splice08.c new file +88 -0
88 lines not on this page · raw message
Signature · 5 lines
2.43.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/2] syscalls: Add test for splicing from /dev/zero and /dev/full
Quoted 63 lines · Cyril Hrubis
Both of these devices produce zeroes when read.
Signed-off-by Cyril Hrubis <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/splice/.gitignore | 1 + testcases/kernel/syscalls/splice/splice08.c | 88 +++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 testcases/kernel/syscalls/splice/splice08.cruntest/syscalls +1
-0@@ -1517,6 +1517,7 @@ splice04 splice04 splice05 splice05 splice06 splice06 splice07 splice07 +splice08 splice08 tee01 tee01 tee02 tee02testcases/kernel/syscalls/splice/.gitignore +1
-0@@ -5,3 +5,4 @@ /splice05 /splice06 /splice07 +/splice08testcases/kernel/syscalls/splice/splice08.c new file +25
-0@@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 Cyril Hrubis <[email protected]> +*/ + +/*\ +* [Description] +* +* Test for splicing from /dev/zero and /dev/full. +* +* The support for splicing from /dev/zero and /dev/full was removed in: +* c6585011bc1d ("splice: Remove generic_file_splice_read()") +* +* And added back in: +* 1b057bd800c3 ("drivers/char/mem: implement splice() for /dev/zero, /dev/full") +*/ + +#define _GNU_SOURCE +#include "tst_test.h" + +static int fd_zero; +static int fd_full; + +static void test_splice (unsigned int bytes,int dev_fd) +{
testcases/kernel/syscalls/splice/splice08.c line 35
Quoted 10 lines
testcases/kernel/syscalls/splice/splice08.c new file +10
-0+int pipefd[2 ]; +char buf[bytes]; +size_t i; +int fail =0 ; + +memset (buf,0xff ,sizeof (buf)); + +SAFE_PIPE (pipefd); + +TST_EXP_POSITIVE (splice (dev_fd,NULL , pipefd[1 ],NULL ,sizeof (buf),0 ));
Both look good to me, just curious if you meant to check TST_RET against sizeof(buf) here
as you did in splice09.
Quoted 60 lines
testcases/kernel/syscalls/splice/splice08.c new file +53
-1+ +if (!TST_PASS ) + goto ret; + +SAFE_READ (1 , pipefd[0 ], buf,sizeof (buf)); + +for (i =0 ; i <sizeof (buf); i++) { +if (buf[i]) + fail++; + } + +if (fail) +tst_res (TFAIL ,"Non-zero bytes spliced from /dev/zero" ); +else +tst_res (TPASS ,"All bytes spliced from /dev/zero are zeroed" ); + +ret: +SAFE_CLOSE (pipefd[0 ]); +SAFE_CLOSE (pipefd[1 ]); +} + +static void verify_splice (unsigned int n) +{ +unsigned int bytes =1009 * n; + +tst_res (TINFO ,"Splicing %u bytes from /dev/zero" , bytes); +test_splice (bytes, fd_zero); +tst_res (TINFO ,"Splicing %u bytes from /dev/full" , bytes); +test_splice (bytes, fd_full); +} + +static void setup (void ) +{ + fd_zero =SAFE_OPEN ("/dev/zero" ,O_RDONLY ); + fd_full =SAFE_OPEN ("/dev/full" ,O_RDONLY ); +} + +static void cleanup (void ) +{ +if (fd_zero >0 ) +SAFE_CLOSE (fd_zero); + +if (fd_full >0 ) +SAFE_CLOSE (fd_full); +} + +static struct tst_test test = { + .test = verify_splice, + .tcnt =9 , + .setup = setup, + .cleanup = cleanup, + .min_kver ="6.7" , +}; --2.43.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/2] syscalls: Add test for splicing from /dev/zero and /dev/full
Hi!
Quoted 1 line
Both look good to me, just curious if you meant to check
TST_RET
Is that Acked-by or Reviewed-by?
Quoted 2 lines
against sizeof(buf) here
as you did in splice09.
Will fix.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Jan Stancek
Reviewed-byRe: [LTP] [PATCH 1/2] syscalls: Add test for splicing from /dev/zero and /dev/full
Quoted 10 lines · Cyril Hrubis
Hi!
Quoted 1 line
Both look good to me, just curious if you meant to check
TST_RETIs that Acked-by or Reviewed-by?
Quoted 2 lines
against sizeof(buf) here
as you did in splice09.Will fix.
Feel free to add to next version:
Quoted 5 lines
--
Cyril Hrubis
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/2] syscalls: Add test for splicing from /dev/zero and /dev/full
Hi!
Quoted 2 lines
Feel free to add to next version:
Reviewed-by Jan Stancek <[email protected]>
I've fixed all the problems pointed out by you and peter and pushed, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/2] syscalls: Add test for splicing from /dev/zero and /dev/full
In reply to Cyril HrubisHi Cyril,
Quoted 15 lines
testcases/kernel/syscalls/splice/splice08.c new file +15
-0+static void test_splice (unsigned int bytes,int dev_fd) +{ +int pipefd[2 ]; +char buf[bytes]; +size_t i; +int fail =0 ; + +memset (buf,0xff ,sizeof (buf)); + +SAFE_PIPE (pipefd); + +TST_EXP_POSITIVE (splice (dev_fd,NULL , pipefd[1 ],NULL ,sizeof (buf),0 )); + +if (!TST_PASS ) + goto ret;
testcases/kernel/syscalls/splice/splice08.c line 48
Quoted 10 lines
testcases/kernel/syscalls/splice/splice08.c new file +10
-0+ +SAFE_READ (1 , pipefd[0 ], buf,sizeof (buf)); + +for (i =0 ; i <sizeof (buf); i++) { +if (buf[i]) + fail++; + } + +if (fail) +tst_res (TFAIL ,"Non-zero bytes spliced from /dev/zero" );
Maybe write how many fail we have?
I also agree with Jan's comment about missing TST_RET, which is in splice09.
testcases/kernel/syscalls/splice/splice08.c line 59
Quoted 11 lines
testcases/kernel/syscalls/splice/splice08.c new file +11
-0+else +tst_res (TPASS ,"All bytes spliced from /dev/zero are zeroed" ); + +ret: +SAFE_CLOSE (pipefd[0 ]); +SAFE_CLOSE (pipefd[1 ]); +} + +static void verify_splice (unsigned int n) +{ +unsigned int bytes =1009 * n;
Out of curiosity, why 1009 and not 1000?
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/2] syscalls: Add test for splicing from /dev/zero and /dev/full
Hi!
Quoted 26 lines
Quoted 14 lines
testcases/kernel/syscalls/splice/splice08.c new file +14
-0+{ +int pipefd[2 ]; +char buf[bytes]; +size_t i; +int fail =0 ; + +memset (buf,0xff ,sizeof (buf)); + +SAFE_PIPE (pipefd); + +TST_EXP_POSITIVE (splice (dev_fd,NULL , pipefd[1 ],NULL ,sizeof (buf),0 )); + +if (!TST_PASS ) + goto ret;testcases/kernel/syscalls/splice/splice08.c line 48
Quoted 10 lines
testcases/kernel/syscalls/splice/splice08.c new file +10
-0+ +SAFE_READ (1 , pipefd[0 ], buf,sizeof (buf)); + +for (i =0 ; i <sizeof (buf); i++) { +if (buf[i]) + fail++; + } + +if (fail) +tst_res (TFAIL ,"Non-zero bytes spliced from /dev/zero" );Maybe write how many fail we have?
Quoted 1 line
I also agree with Jan's comment about missing
TST_RET, which is in splice09.
Will fix both.
Quoted 15 lines
Reviewed-by Petr Vorel <[email protected]>testcases/kernel/syscalls/splice/splice08.c line 59
Quoted 11 lines
testcases/kernel/syscalls/splice/splice08.c new file +11
-0+else +tst_res (TPASS ,"All bytes spliced from /dev/zero are zeroed" ); + +ret: +SAFE_CLOSE (pipefd[0 ]); +SAFE_CLOSE (pipefd[1 ]); +} + +static void verify_splice (unsigned int n) +{ +unsigned int bytes =1009 * n;Out of curiosity, why 1009 and not 1000?
Because people tend to use buffers that are either power of two or multiples of 100 or 1000. The 1009 is a prime number which means that multiples of it will have "unexpected" sizes.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/2 syscalls: Add test for splicing to /dev/zero and /dev/null
In reply to Cyril HrubisBoth of these devices discard written data.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/splice/.gitignore | 1 + testcases/kernel/syscalls/splice/splice09.c | 55 +++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 testcases/kernel/syscalls/splice/splice09.c
runtest/syscalls +1 -0
@@ -1518,6 +1518,7 @@ splice05 splice05 splice06 splice06 splice07 splice07 splice08 splice08 +splice09 splice09 tee01 tee01 tee02 tee02
testcases/kernel/syscalls/splice/.gitignore +1 -0
@@ -6,3 +6,4 @@ /splice06 /splice07 /splice08 +/splice09
testcases/kernel/syscalls/splice/splice09.c new file +55 -0
55 lines not on this page · raw message
Signature · 5 lines
2.43.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/2] syscalls: Add test for splicing to /dev/zero and /dev/null
Hi Cyril,
...
testcases/kernel/syscalls/splice/splice09.c line 19
Quoted 4 lines
testcases/kernel/syscalls/splice/splice09.c new file +4
-0+#define _GNU_SOURCE +#include "tst_test.h" + +static const char *test_devices[] = {
checkpatch.pl suggests:
static const char * const test_devices[] = {
Quoted 8 lines
testcases/kernel/syscalls/splice/splice09.c new file +8
-0+"/dev/null" , + "/dev/zero", +}; + +static void verify_splice (unsigned int n) +{ +char buf[1024 ]; +char dev_fd;
testcases/kernel/syscalls/splice/splice09.c line 37
Quoted 10 lines
testcases/kernel/syscalls/splice/splice09.c new file +10
-0+int pipefd[2 ]; + +memset (buf,0xff ,sizeof (buf)); + +tst_res (TINFO ,"Testing %s" , test_devices[n]); + + dev_fd =SAFE_OPEN (test_devices[n],O_WRONLY ); + +SAFE_PIPE (pipefd); +SAFE_WRITE (1 , pipefd[1 ], buf,sizeof (buf));
I wonder if write() fails, we don't get SAFE_CLOSE() calls, right?
Otherwise LGTM.
Kind regards,
Petr
Quoted 18 lines
testcases/kernel/syscalls/splice/splice09.c new file +18
-0+ +TST_EXP_POSITIVE (splice (pipefd[0 ],NULL , dev_fd,NULL ,sizeof (buf),0 )); + +if (TST_PASS &&TST_RET !=sizeof (buf)) +tst_res (TFAIL ,"Wrote only part of the pipe buffer" ); +else +tst_res (TPASS ,"Wrote whole pipe buffer" ); + +SAFE_CLOSE (pipefd[0 ]); +SAFE_CLOSE (pipefd[1 ]); +SAFE_CLOSE (dev_fd); +} + +static struct tst_test test = { + .test = verify_splice, + .tcnt =ARRAY_SIZE (test_devices), + .min_kver ="6.7" , +};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/2] syscalls: Add test for splicing to /dev/zero and /dev/null
Hi!
Quoted 6 lines
testcases/kernel/syscalls/splice/splice09.c line 19
Quoted 4 lines
testcases/kernel/syscalls/splice/splice09.c new file +4
-0+#define _GNU_SOURCE +#include "tst_test.h" + +static const char *test_devices[] = {checkpatch.pl suggests:
static const char * const test_devices[] = {
Will fix and push.
Quoted 11 lines
Quoted 11 lines
testcases/kernel/syscalls/splice/splice09.c new file +11
-0+"/dev/null" , + "/dev/zero", +}; + +static void verify_splice (unsigned int n) +{ +char buf[1024 ]; +char dev_fd; +int pipefd[2 ]; + +memset (buf,0xff ,sizeof (buf));
Quoted 8 lines
testcases/kernel/syscalls/splice/splice09.c line 37
Quoted 7 lines
testcases/kernel/syscalls/splice/splice09.c new file +7
-0+ +tst_res (TINFO ,"Testing %s" , test_devices[n]); + + dev_fd =SAFE_OPEN (test_devices[n],O_WRONLY ); + +SAFE_PIPE (pipefd); +SAFE_WRITE (1 , pipefd[1 ], buf,sizeof (buf));I wonder if
write()fails, we don't getSAFE_CLOSE()calls, right?
We do not care here since these are just pipes, the test will fail with TBROK and kernel will destroy the pipes once the process exits.
We have to close real files in test temporary directory, because if we do not do so, tst_rmdir() may fail on nfs. E.g. if you create a file on nfs, open it and unlink it, the directory is not empty as one would expect and cannot be removed.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp