Message ID | 20240320095927.19973-2-chrubis@suse.cz |
---|---|
State | Accepted |
Headers | show |
Series | Add splice tests fro /dev/{zero,null,full} | expand |
On Wed, Mar 20, 2024 at 11:01 AM Cyril Hrubis <chrubis@suse.cz> wrote: > > Both of these devices produce zeroes when read. > > Signed-off-by: Cyril Hrubis <chrubis@suse.cz> > --- > 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 > > diff --git a/runtest/syscalls b/runtest/syscalls > index 4ed2b5602..0889f58a1 100644 > --- a/runtest/syscalls > +++ b/runtest/syscalls > @@ -1517,6 +1517,7 @@ splice04 splice04 > splice05 splice05 > splice06 splice06 > splice07 splice07 > +splice08 splice08 > > tee01 tee01 > tee02 tee02 > diff --git a/testcases/kernel/syscalls/splice/.gitignore b/testcases/kernel/syscalls/splice/.gitignore > index 88a8dff78..9453cf93a 100644 > --- a/testcases/kernel/syscalls/splice/.gitignore > +++ b/testcases/kernel/syscalls/splice/.gitignore > @@ -5,3 +5,4 @@ > /splice05 > /splice06 > /splice07 > +/splice08 > diff --git a/testcases/kernel/syscalls/splice/splice08.c b/testcases/kernel/syscalls/splice/splice08.c > new file mode 100644 > index 000000000..cdd51b66c > --- /dev/null > +++ b/testcases/kernel/syscalls/splice/splice08.c > @@ -0,0 +1,88 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (C) 2024 Cyril Hrubis <chrubis@suse.cz> > + */ > + > +/*\ > + * [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) > +{ > + 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. > + > + 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 >
Hi Cyril, > +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; > + > + 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. Reviewed-by: Petr Vorel <pvorel@suse.cz> > + 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
Hi! > > +{ > > + 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; > > + > > + 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. Will fix both. > Reviewed-by: Petr Vorel <pvorel@suse.cz> > > > + 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.
Hi! > Both look good to me, just curious if you meant to check TST_RET Is that Acked-by or Reviewed-by? > against sizeof(buf) here > as you did in splice09. Will fix.
On Thu, Apr 11, 2024 at 12:44 PM Cyril Hrubis <chrubis@suse.cz> wrote: > > Hi! > > Both look good to me, just curious if you meant to check TST_RET > > Is that Acked-by or Reviewed-by? > > > against sizeof(buf) here > > as you did in splice09. > > Will fix. Feel free to add to next version: Reviewed-by: Jan Stancek <jstancek@redhat.com> > > -- > Cyril Hrubis > chrubis@suse.cz >
Hi! > Feel free to add to next version: > Reviewed-by: Jan Stancek <jstancek@redhat.com> I've fixed all the problems pointed out by you and peter and pushed, thanks.
diff --git a/runtest/syscalls b/runtest/syscalls index 4ed2b5602..0889f58a1 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1517,6 +1517,7 @@ splice04 splice04 splice05 splice05 splice06 splice06 splice07 splice07 +splice08 splice08 tee01 tee01 tee02 tee02 diff --git a/testcases/kernel/syscalls/splice/.gitignore b/testcases/kernel/syscalls/splice/.gitignore index 88a8dff78..9453cf93a 100644 --- a/testcases/kernel/syscalls/splice/.gitignore +++ b/testcases/kernel/syscalls/splice/.gitignore @@ -5,3 +5,4 @@ /splice05 /splice06 /splice07 +/splice08 diff --git a/testcases/kernel/syscalls/splice/splice08.c b/testcases/kernel/syscalls/splice/splice08.c new file mode 100644 index 000000000..cdd51b66c --- /dev/null +++ b/testcases/kernel/syscalls/splice/splice08.c @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2024 Cyril Hrubis <chrubis@suse.cz> + */ + +/*\ + * [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) +{ + 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; + + 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", +};
Both of these devices produce zeroes when read. Signed-off-by: Cyril Hrubis <chrubis@suse.cz> --- 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