[LTP] [PATCH 1/2] syscalls: Add test for splicing from /dev/zero and /dev/full
Jan Stancek
jstancek@redhat.com
Wed Mar 20 14:26:15 CET 2024
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
>
More information about the ltp
mailing list