From e5bdcbbd1d975f088df3e5766f1ddda4a29c3cb1 Mon Sep 17 00:00:00 2001 From: Pavel Tikhomirov Date: Wed, 26 Jun 2019 15:47:39 +0300 Subject: zdtm/inotify: add a test that no unexpected events appear after c/r Just create two inotify watches on a testfile, and do nothing except c/r, it is expected that there is no events in queue after these. before "inotify: cleanup auxiliary events from queue": [root@snorch criu]# ./test/zdtm.py run -t zdtm/static/inotify04 === Run 1/1 ================ zdtm/static/inotify04 ======================== Run zdtm/static/inotify04 in h ======================== DEP inotify04.d CC inotify04.o LINK inotify04 Start test ./inotify04 --pidfile=inotify04.pid --outfile=inotify04.out --dirname=inotify04.test Run criu dump Run criu restore Send the 15 signal to 60 Wait for zdtm/static/inotify04(60) to die for 0.100000 =============== Test zdtm/static/inotify04 FAIL at result check ================ Test output: ================================ 18:37:14.279: 60: Event 0x10 18:37:14.280: 60: Event 0x20 18:37:14.280: 60: Event 0x10 18:37:14.280: 60: Read 3 events 18:37:14.280: 60: FAIL: inotify04.c:105: Found 3 unexpected inotify events (errno = 11 (Resource temporarily unavailable)) <<< ================================ v2: make two inotifies on the same file Signed-off-by: Pavel Tikhomirov zdtm: inotify04 add another inotify on the same file --- test/zdtm/static/Makefile | 1 + test/zdtm/static/inotify04.c | 124 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 test/zdtm/static/inotify04.c (limited to 'test') diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile index 52bd00602..d8279d6f8 100644 --- a/test/zdtm/static/Makefile +++ b/test/zdtm/static/Makefile @@ -311,6 +311,7 @@ TST_DIR = \ inotify00 \ inotify01 \ inotify02 \ + inotify04 \ cgroup00 \ rmdir_open \ cgroup01 \ diff --git a/test/zdtm/static/inotify04.c b/test/zdtm/static/inotify04.c new file mode 100644 index 000000000..fb9293024 --- /dev/null +++ b/test/zdtm/static/inotify04.c @@ -0,0 +1,124 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "Check inotify does not have trash in queue after c/r"; +const char *test_author = "Pavel Tikhomirov "; + +char *dirname; +TEST_OPTION(dirname, string, "directory name", 1); + +#define TEST_FILE "inotify-testfile" + +#define BUFF_SIZE ((sizeof(struct inotify_event) + PATH_MAX)) + +static int inotify_read_events(int inotify_fd, unsigned int *n) +{ + struct inotify_event *event; + char buf[BUFF_SIZE * 8]; + int ret, off; + + *n = 0; + + while (1) { + ret = read(inotify_fd, buf, sizeof(buf)); + if (ret < 0) { + if (errno != EAGAIN) { + pr_perror("Can't read inotify queue"); + return -1; + } else { + ret = 0; + break; + } + } else if (ret == 0) + break; + + for (off = 0; off < ret; (*n)++, off += sizeof(*event) + event->len) { + event = (void *)(buf + off); + test_msg("Event %#10x\n", event->mask); + } + } + + test_msg("Read %u events\n", *n); + return ret; +} + +int main (int argc, char *argv[]) +{ + unsigned int mask = IN_ALL_EVENTS; + char test_file_path[PATH_MAX]; + int fd, ifd, ifd2, ret; + unsigned int n; + + test_init(argc, argv); + + if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { + pr_perror("Can't create directory %s", dirname); + return 1; + } + + snprintf(test_file_path, sizeof(test_file_path), "%s/%s", dirname, TEST_FILE); + + fd = open(test_file_path, O_CREAT, 0644); + if (fd < 0) { + pr_perror("Failed to create %s", test_file_path); + return 1; + } + close(fd); + + ifd = inotify_init1(IN_NONBLOCK); + if (ifd < 0) { + pr_perror("Failed inotify_init"); + return 1; + } + + ifd2 = inotify_init1(IN_NONBLOCK); + if (ifd2 < 0) { + pr_perror("Failed inotify_init"); + return 1; + } + + if (inotify_add_watch(ifd, test_file_path, mask) < 0) { + pr_perror("Failed inotify_add_watch"); + return 1; + } + + if (inotify_add_watch(ifd2, test_file_path, mask) < 0) { + pr_perror("Failed inotify_add_watch"); + return 1; + } + + test_daemon(); + test_waitsig(); + + ret = inotify_read_events(ifd, &n); + if (ret < 0) { + fail("Failed to read inotify events"); + return 1; + } else if (n != 0) { + fail("Found %d unexpected inotify events", n); + return 1; + } + + ret = inotify_read_events(ifd, &n); + if (ret < 0) { + fail("Failed to read inotify events"); + return 1; + } else if (n != 0) { + fail("Found %d unexpected inotify events", n); + return 1; + } + + close(ifd); + close(ifd2); + unlink(test_file_path); + pass(); + + return 0; +} -- cgit v1.2.3