All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: Murphy Zhou <jencce.kernel@gmail.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4] kernel/fs/fsnotify-stress: fsnotify stress test
Date: Mon, 17 Oct 2022 10:40:38 +0100	[thread overview]
Message-ID: <87pmeqohsh.fsf@suse.de> (raw)
In-Reply-To: <20220902081711.1776943-1-jencce.kernel@gmail.com>

Hello,

Murphy Zhou <jencce.kernel@gmail.com> writes:

> This is a stress test that exercises fanotify and inotify interfaces
> while IO going on. It intentionally ignores failures or return values
> of some syscalls to let the stress go on. If the kernel does not panic
> or hang after a certain period of time of testing, test pass.
>
> Signed-off-by: Murphy Zhou <jencce.kernel@gmail.com>
> ---
> v3 -> v4:
> 	Convert comment to docparse part.
>
>  runtest/fs                                    |   2 +
>  testcases/kernel/fs/fsnotify-stress/Makefile  |   9 +
>  .../fs/fsnotify-stress/fsnotify-stress.c      | 476 ++++++++++++++++++
>  3 files changed, 487 insertions(+)
>  create mode 100644 testcases/kernel/fs/fsnotify-stress/Makefile
>  create mode 100644 testcases/kernel/fs/fsnotify-stress/fsnotify-stress.c
>
> diff --git a/runtest/fs b/runtest/fs
> index 1d753e0dd..beb43aae4 100644
> --- a/runtest/fs
> +++ b/runtest/fs
> @@ -87,3 +87,5 @@ binfmt_misc01 binfmt_misc01.sh
>  binfmt_misc02 binfmt_misc02.sh
>  
>  squashfs01 squashfs01
> +
> +fsnotify-stress fsnotify-stress
> diff --git a/testcases/kernel/fs/fsnotify-stress/Makefile b/testcases/kernel/fs/fsnotify-stress/Makefile
> new file mode 100644
> index 000000000..451f791f1
> --- /dev/null
> +++ b/testcases/kernel/fs/fsnotify-stress/Makefile
> @@ -0,0 +1,9 @@
> +#
> +#    kernel/fs/fs-notify testcases Makefile.
> +#
> +
> +top_srcdir	?= ../../../..
> +
> +include $(top_srcdir)/include/mk/testcases.mk
> +
> +include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/fs/fsnotify-stress/fsnotify-stress.c b/testcases/kernel/fs/fsnotify-stress/fsnotify-stress.c
> new file mode 100644
> index 000000000..8130f7f12
> --- /dev/null
> +++ b/testcases/kernel/fs/fsnotify-stress/fsnotify-stress.c
> @@ -0,0 +1,476 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2022 Red Hat, Inc.  All Rights Reserved.
> + * Author: Murphy Zhou <jencce.kernel@gmail.com>
> + * Copyright (c) Linux Test Project, 2001-2022
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This is an irregular stress test for Linux kernel fanotify/inotify
> + * interfaces. It calls thoese interfaces with possible best coverage
> + * arguments, in a loop. It ignores some return values in the loop to
> + * let the stress going on. At the same time, it initiates IO traffics
> + * by calling IO syscalls.
> + *
> + * If kernel does no panic or hang after the test, test pass.
> + *
> + * It detected a leak in fsnotify code which was fixed by Amir through
> + * this Linux commit:
> + *     4396a731 fsnotify: fix sb_connectors leak

The problem with stress tests is that they are expensive to run. If they
do fail then it's often difficult to reproduce the errors. Eventually
they just get added to a skip list.

Why not make a reproducer for this bug which executes in the minimum
time necessary?

As well as saving CPU time and avoiding random timeouts this helps
create a better understanding of what really matters in the test.

> + *
> + */
> +
> +#define _GNU_SOURCE     /* Needed to get O_LARGEFILE definition */
> +
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <limits.h>
> +#include <poll.h>
> +#include <sys/fanotify.h>
> +#include <sys/inotify.h>
> +#include <sys/time.h>
> +#include <unistd.h>
> +#include <string.h>
> +
> +#include "tst_test.h"
> +#include "../../syscalls/fanotify/fanotify.h"
> +#include "../../syscalls/inotify/inotify.h"
> +
> +static int fd0;
> +
> +#define TESTDIR "testdir"
> +#define TESTFILE "testdir/file"
> +
> +static void cleanup(void)
> +{
> +	if (fd0 > 0) {
> +		SAFE_CLOSE(fd0);
> +	}
> +}
> +
> +static void setup(void)
> +{
> +	SAFE_MKDIR(TESTDIR, 0777);
> +	fd0 = SAFE_OPEN(TESTFILE, O_CREAT|O_RDWR, 0666);
> +}
> +
> +static void fanotify_flushes(char *fn)
> +{
> +	int fd;
> +
> +	fd = SAFE_FANOTIFY_INIT(FAN_CLOEXEC | FAN_CLASS_CONTENT | FAN_NONBLOCK,
> +					   O_RDONLY | O_LARGEFILE);
> +
> +	while (tst_remaining_runtime() > 10) {
> +		/* As a stress test, we ignore the return values here to
> +		 * proceed with the stress.
> +		 */

The LTP style guide forbids inline comments unless they are explaining
something that would be very difficult to understand without them. There
are lots of comments like this in the test.

> +		fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT,
> +			  FAN_ACCESS | FAN_MODIFY | FAN_OPEN_PERM | FAN_CLOSE |
> +			  FAN_OPEN | FAN_ACCESS_PERM | FAN_ONDIR |
> +			  FAN_EVENT_ON_CHILD, -1, fn);
> +

...

> +static void readfiles(char *fn)
> +{
> +	int fd;
> +	char buf[BUFSIZ];
> +
> +	memset(buf, 1, BUFSIZ);
> +	while (tst_remaining_runtime() > 10) {
> +		fd = open(fn, O_RDONLY);

If this fails then what are we stressing? We could just be testing
spinning in a loop.

> +		if (fd == -1)
> +			continue;
> +		read(fd, buf, BUFSIZ);

Also ignoring the result of read results in compiler warnings.

> +
> +static struct tst_test test = {
> +	.tcnt = 1,
> +	.max_runtime = 60,

Does it need 60 seconds to reproduce the bug?
Why does it need this long to achieve the desired coverage?

Without further evidence I'd assume that full coverage (ignoring setup)
is approached after <1 second on a reasonable system.

Also we should limit the number of iterations.

-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      reply	other threads:[~2022-10-17 10:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-25  2:47 [LTP] [PATCH 1/2] kernel/fs/fs-notify: fsnotify stress tests Murphy Zhou
2022-01-25  7:29 ` Amir Goldstein
2022-01-25  8:30   ` Murphy Zhou
2022-01-25 10:28     ` Petr Vorel
2022-01-25 10:56     ` Cyril Hrubis
2022-01-25 11:04 ` Cyril Hrubis
2022-01-27  4:42   ` Murphy Zhou
2022-02-28  6:29   ` Murphy Zhou
2022-02-28  6:42     ` Petr Vorel
2022-03-03  3:06       ` [LTP] [PATCH v2] kernel/fs/fsnotify-stress: fsnotify stress test Murphy Zhou
2022-03-03 15:22         ` Petr Vorel
2022-03-04  3:28           ` Murphy Zhou
2022-03-08  1:38           ` [LTP] [PATCH v3] " Murphy Zhou
2022-03-09 10:38             ` Cyril Hrubis
2022-03-10 20:48               ` Petr Vorel
2022-09-02  7:58                 ` Murphy Zhou
2022-09-02  8:17                 ` [LTP] [PATCH v4] " Murphy Zhou
2022-10-17  9:40                   ` Richard Palethorpe [this message]

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=87pmeqohsh.fsf@suse.de \
    --to=rpalethorpe@suse.de \
    --cc=jencce.kernel@gmail.com \
    --cc=ltp@lists.linux.it \
    /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.