public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: chrubis@suse.cz
To: Jan Kara <jack@suse.cz>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH 2/2] syscalls/fanotify: Test generation of overflow events
Date: Mon, 24 Feb 2014 13:10:04 +0100	[thread overview]
Message-ID: <20140224121004.GB23596@rei> (raw)
In-Reply-To: <1393233450-22698-2-git-send-email-jack@suse.cz>

Hi!
> Test whether overflow event is properly generated when we don't read
> fanotify descriptor and generate enough events.

Missing runtest and .gitignore changes as well.

>  testcases/kernel/syscalls/fanotify/fanotify05.c | 185 ++++++++++++++++++++++++
>  1 file changed, 185 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/fanotify/fanotify05.c
> 
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify05.c b/testcases/kernel/syscalls/fanotify/fanotify05.c
> new file mode 100644
> index 000000000000..a714d9e27a6f
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fanotify/fanotify05.c
> @@ -0,0 +1,185 @@
> +/*
> + * Copyright (c) 2014 SUSE Linux.  All Rights Reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * Further, this software is distributed without any warranty that it is
> + * free of the rightful claim of any third person regarding infringement
> + * or the like.  Any license provided herein, whether implied or
> + * otherwise, applies only to this software file.  Patent licenses, if
> + * any, provided herein do not apply to combinations of this program with
> + * other software, or any other product whatsoever.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + *
> + * Started by Jan Kara <jack@suse.cz>
> + *
> + * DESCRIPTION
> + *     Check that fanotify overflow event is properly generated
> + *
> + * ALGORITHM
> + *     Generate enough events without reading them and check that overflow
> + *     event is generated.
> + */
> +#include "config.h"
> +
> +#include <stdio.h>
> +#include <sys/stat.h>
> +#include <sys/types.h>
> +#include <sys/fcntl.h>
> +#include <errno.h>
> +#include <string.h>
> +#include <sys/syscall.h>
> +#include "test.h"
> +#include "usctest.h"
> +#include "linux_syscall_numbers.h"
> +#include "fanotify.h"
> +#include "safe_macros.h"
> +
> +char *TCID = "fanotify05";
> +int TST_TOTAL = 1;
> +
> +#if defined(HAVE_SYS_FANOTIFY_H)
> +#include <sys/fanotify.h>
> +
> +/* Currently this is fixed in kernel... */
> +#define MAX_EVENTS 16384
> +
> +static void setup(void);
> +static void cleanup(void);
> +
> +#define BUF_SIZE 256
> +static char fname[BUF_SIZE];
> +static int fd, fd_notify;
> +
> +struct fanotify_event_metadata event;
> +
> +int main(int ac, char **av)
> +{
> +	int lc, i;
> +	char *msg;
> +	int len;
> +
> +	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
> +		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		/*
> +		 * generate events
> +		 */
> +		for (i = 0; i < MAX_EVENTS + 1; i++) {
> +			sprintf(fname, "fname_%d", i);
> +			fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0644);
> +			SAFE_CLOSE(cleanup, fd);

SAFE_FILE_TOUCH(cleanup, fname, 0, NULL)

> +		}
> +
> +		while (1) {
> +			/*
> +			 * get list on events
> +			 */
> +			len = read(fd_notify, &event, sizeof(event));
> +			if (len < 0) {
> +				if (errno == -EAGAIN) {
> +					tst_resm(TFAIL, "Overflow event not "
> +						 "generated!\n");
> +					break;
> +				}
> +				tst_brkm(TBROK | TERRNO, cleanup,
> +				 	 "read of notification event failed");

Space befor tab.

> +				break;
> +			}
> +			if (event.fd != FAN_NOFD)
> +				close(event.fd);
> +
> +			/*
> +			 * check events
> +			 */
> +			if (event.mask != FAN_OPEN &&
> +			    event.mask != FAN_Q_OVERFLOW) {
> +				tst_resm(TFAIL,
> +					 "get event: mask=%llx (expected %llx)"
> +					 "pid=%u fd=%d",
> +					 (unsigned long long)event.mask,
> +					 (unsigned long long)FAN_OPEN,
> +					 (unsigned)event.pid, event.fd);
> +				break;
> +			}
> +			if (event.mask == FAN_Q_OVERFLOW) {
> +				if (event.fd != FAN_NOFD) {
> +					tst_resm(TFAIL,
> +					 	 "invalid overflow event: "

Here as well.

> +						 "mask=%llx pid=%u fd=%d",
> +						 (unsigned long long)event.mask,
> +						 (unsigned)event.pid,
> +						 event.fd);
> +					break;
> +				}
> +				tst_resm(TPASS,
> +					 "get event: mask=%llx pid=%u fd=%d",
> +					 (unsigned long long)event.mask,
> +					 (unsigned)event.pid, event.fd);
> +					break;
> +			}
> +		}
> +	}
> +
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static void setup(void)
> +{
> +	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +
> +	TEST_PAUSE;
> +
> +	tst_tmpdir();
> +
> +	if ((fd_notify = myfanotify_init(FAN_CLASS_NOTIF | FAN_NONBLOCK,
> +					 O_RDONLY)) < 0) {

I would move the assigment out of the if conditional here and then do
just if (fd_notify < 0) but that is just aesthetic change.

> +		if (errno == ENOSYS) {
> +			tst_brkm(TCONF, cleanup,
> +				 "fanotify is not configured in this kernel.");
> +		} else {
> +			tst_brkm(TBROK | TERRNO, cleanup,
> +				 "fanotify_init failed");
> +		}
> +	}
> +
> +	if (myfanotify_mark(fd_notify, FAN_MARK_MOUNT | FAN_MARK_ADD, FAN_OPEN,
> +			    AT_FDCWD, ".") < 0) {
> +		tst_brkm(TBROK | TERRNO, cleanup,
> +			 "fanotify_mark (%d, FAN_MARK_MOUNT | FAN_MARK_ADD, "
> +			 "FAN_OPEN, AT_FDCWD, \".\") failed",
> +			 fd_notify);
> +	}
> +}
> +
> +static void cleanup(void)
> +{
> +	if (close(fd_notify) == -1) {
> +		tst_resm(TWARN, "close(%d) failed", fd_notify);
> +	}

And I tend not to add curly brackets around one line statements...

> +	TEST_CLEANUP;
> +	tst_rmdir();
> +}
> +
> +#else
> +
> +int main(void)
> +{
> +	tst_brkm(TCONF, NULL, "system doesn't have required fanotify support");
> +}
> +
> +#endif
> -- 
> 1.8.1.4
> 

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  parent reply	other threads:[~2014-02-24 12:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1393233450-22698-1-git-send-email-jack@suse.cz>
2014-02-24 12:04 ` [LTP] [PATCH 1/2] syscalls/inotify: Test generation of overflow events chrubis
     [not found] ` <1393233450-22698-2-git-send-email-jack@suse.cz>
2014-02-24 12:10   ` chrubis [this message]
     [not found]     ` <20140224123723.GA26687@quack.suse.cz>
2014-02-24 13:25       ` [LTP] [PATCH 2/2] syscalls/fanotify: " chrubis
2014-02-24 12:14 ` [LTP] [PATCH 1/2] syscalls/inotify: " chrubis
     [not found]   ` <20140224123955.GB26687@quack.suse.cz>
2014-02-24 13:12     ` chrubis

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=20140224121004.GB23596@rei \
    --to=chrubis@suse.cz \
    --cc=jack@suse.cz \
    --cc=ltp-list@lists.sourceforge.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox