From: Richard Palethorpe <rpalethorpe@suse.de>
To: Marius Kittler <mkittler@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] Add regression test for hangup on pipe operations
Date: Mon, 27 Nov 2023 13:45:10 +0000 [thread overview]
Message-ID: <874jh78g1z.fsf@suse.de> (raw)
In-Reply-To: <20230925093005.24248-1-mkittler@suse.de>
Hello,
Pushed with some significant changes, please see commit for
details. Thanks!
Marius Kittler <mkittler@suse.de> writes:
> This tests the problem fixed by the patch
> https://www.spinics.net/lists/linux-api/msg49731.html.
>
> Signed-off-by: Marius Kittler <mkittler@suse.de>
> ---
> runtest/syscalls | 1 +
> testcases/kernel/syscalls/pipe/.gitignore | 1 +
> testcases/kernel/syscalls/pipe/pipe15.c | 96 +++++++++++++++++++++++
> 3 files changed, 98 insertions(+)
> create mode 100644 testcases/kernel/syscalls/pipe/pipe15.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 4f1ee1f34..6c125c2f5 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1004,6 +1004,7 @@ pipe11 pipe11
> pipe12 pipe12
> pipe13 pipe13
> pipe14 pipe14
> +pipe15 pipe15
>
> pipe2_01 pipe2_01
> pipe2_02 pipe2_02
> diff --git a/testcases/kernel/syscalls/pipe/.gitignore b/testcases/kernel/syscalls/pipe/.gitignore
> index 774d73205..581a68b78 100644
> --- a/testcases/kernel/syscalls/pipe/.gitignore
> +++ b/testcases/kernel/syscalls/pipe/.gitignore
> @@ -12,3 +12,4 @@
> /pipe12
> /pipe13
> /pipe14
> +/pipe15
> diff --git a/testcases/kernel/syscalls/pipe/pipe15.c b/testcases/kernel/syscalls/pipe/pipe15.c
> new file mode 100644
> index 000000000..7b55143c1
> --- /dev/null
> +++ b/testcases/kernel/syscalls/pipe/pipe15.c
> @@ -0,0 +1,96 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2023 SUSE LLC Marius Kittler <mkittler@suse.de>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This is a regression test for hangup on pipe operations. See
> + * https://www.spinics.net/lists/linux-api/msg49762.html for
> + * additional context. It tests that pipe operations do not block
> + * indefinitely when going to the soft limit on the total size of
> + * all pipes created by a single user.
> + */
> +
> +#define _GNU_SOURCE
> +#include <fcntl.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +#include "tst_test.h"
> +#include "tst_safe_stdio.h"
> +#include "tst_safe_macros.h"
> +
> +static int pipe_count;
> +static int *pipes;
> +static char *buffer;
> +static int buffer_size;
> +
> +static void run(void)
> +{
> + SAFE_WRITE(0, pipes[1], buffer, buffer_size);
> + SAFE_READ(0, pipes[0], buffer, buffer_size - 1);
> + SAFE_WRITE(0, pipes[1], buffer, 1);
> + tst_res(TPASS,
> + "Pipe operations do not block indefinitely when going to "
> + "the soft limit on the total size of all pipes created by "
> + "a single user");
> +}
> +
> +static void setup(void)
> +{
> + int pipe[2];
> + int page_size = getpagesize(), soft_limit;
> + struct rlimit nfd;
> +
> + /* determine the buffer size of a pipe, usually 65536 */
> + SAFE_PIPE(pipe);
> + buffer_size = fcntl(pipe[1], F_GETPIPE_SZ);
> + SAFE_CLOSE(pipe[0]);
> + SAFE_CLOSE(pipe[1]);
> +
> + /* determine the max number of pipes we can create within the
> + * soft limit, usually 1024
> + */
> + SAFE_FILE_SCANF("/proc/sys/fs/pipe-user-pages-soft", "%i", &soft_limit);
> + pipe_count = soft_limit * page_size / buffer_size;
> +
> + tst_res(TINFO, "Soft limit for pipes: %i pages", soft_limit);
> + tst_res(TINFO, "Buffer size: %d byte", buffer_size);
> + tst_res(TINFO, "Creating %i pipes", pipe_count);
> +
> + /* avoid running into "pipe() failed: EMFILE (24)" */
> + SAFE_GETRLIMIT(RLIMIT_NOFILE, &nfd);
> + if (nfd.rlim_max < (unsigned long)pipe_count)
> + tst_brk(TCONF, "NOFILE limit max too low: %lu < %i",
> + nfd.rlim_max, pipe_count);
> + if (nfd.rlim_cur < nfd.rlim_max) {
> + nfd.rlim_cur = nfd.rlim_max;
> + SAFE_SETRLIMIT(RLIMIT_NOFILE, &nfd);
> + }
> +
> + /* allocate memory for pipes and the buffer */
> + pipes = calloc(pipe_count * 2, sizeof(int));
> + memset(pipes, 0xFF, pipe_count * 2 * sizeof(int));
> + for (int i = 0; i < pipe_count; ++i)
> + SAFE_PIPE(pipes + i * 2);
> + buffer = calloc(buffer_size, 1);
> +}
> +
> +static void cleanup(void)
> +{
> + for (int i = 0; i < pipe_count * 2; i++)
> + if (pipes[i] > 0)
> + SAFE_CLOSE(pipes[i]);
> + if (pipes)
> + free(pipes);
> + if (buffer)
> + free(buffer);
> +}
> +
> +static struct tst_test test = {
> + .setup = setup,
> + .test_all = run,
> + .cleanup = cleanup
> +};
> --
> 2.42.0
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-11-27 13:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-25 9:30 [LTP] [PATCH v1] Add regression test for hangup on pipe operations Marius Kittler
2023-11-27 13:45 ` Richard Palethorpe [this message]
2023-11-27 14:34 ` Marius Kittler
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 \
--in-reply-to=874jh78g1z.fsf@suse.de \
--to=rpalethorpe@suse.de \
--cc=ltp@lists.linux.it \
--cc=mkittler@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.