[CRIU] [PATCH] zdtm: Extend inotify00 test to test precise events

Cyrill Gorcunov gorcunov at openvz.org
Wed Nov 28 10:20:59 EST 2012


For root access use IN_OPEN and for deleted file
use IN_DELETE mask.

Strictly speaking we need to extend this test even
more to test all masks combinations.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm/live/static/Makefile    |    2 +-
 test/zdtm/live/static/inotify00.c |   25 +++++++++++++++++++++++--
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 3abe492..7393ab6 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -64,7 +64,6 @@ TST_NOFILE	=				\
 		file_fown			\
 		eventfs00			\
 		signalfd00			\
-		inotify00			\
 		uptime_grow			\
 		session00			\
 		pty00				\
@@ -108,6 +107,7 @@ TST_FILE	=				\
 		unlink_fifo_wronly		\
 		file_shared			\
 		cow01				\
+		inotify00			\
 
 TST_DIR		=				\
 		cwd00				\
diff --git a/test/zdtm/live/static/inotify00.c b/test/zdtm/live/static/inotify00.c
index 06780d6..565abba 100644
--- a/test/zdtm/live/static/inotify00.c
+++ b/test/zdtm/live/static/inotify00.c
@@ -20,10 +20,13 @@ const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
 
 #define BUFF_SIZE ((sizeof(struct inotify_event) + PATH_MAX))
 
+char *filename;
+TEST_OPTION(filename, string, "file name", 1);
+
 int main (int argc, char *argv[])
 {
 	char buf[BUFF_SIZE];
-	int fd, wd;
+	int fd, wd, delfd;
 
 	test_init(argc, argv);
 
@@ -33,8 +36,15 @@ int main (int argc, char *argv[])
 		exit(1);
 	}
 
+	delfd = open(filename, O_CREAT | O_TRUNC);
+	if (delfd < 0) {
+		fail("failed to create %s\n", filename);
+		exit(1);
+	}
+
 	wd  = 0;
-	wd |= inotify_add_watch(fd, "/", IN_ALL_EVENTS);
+	wd |= inotify_add_watch(fd, "/", IN_OPEN);
+	wd |= inotify_add_watch(fd, filename, IN_DELETE);
 	if (wd < 0) {
 		fail("inotify_add_watch failed");
 		exit(1);
@@ -50,6 +60,17 @@ int main (int argc, char *argv[])
 		fail("No events in queue");
 		exit(1);
 	}
+	close(wd);
+
+	close(delfd);
+	unlink(filename);
+
+	if (read(fd, buf, sizeof(buf)) > 0) {
+		pass();
+	} else {
+		fail("No events in queue");
+		exit(1);
+	}
 
 	return 0;
 }
-- 
1.7.7.6



More information about the CRIU mailing list