Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/checkpoint-restore/criu.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPavel Tikhomirov <ptikhomirov@virtuozzo.com>2019-06-26 15:47:39 +0300
committerAndrei Vagin <avagin@gmail.com>2019-09-07 15:59:56 +0300
commite5bdcbbd1d975f088df3e5766f1ddda4a29c3cb1 (patch)
tree31c679260981764d6231865678012a2e5f716c03 /test
parent96992883ca7550387b347fbbcfde1266f078c55a (diff)
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 <ptikhomirov@virtuozzo.com> zdtm: inotify04 add another inotify on the same file
Diffstat (limited to 'test')
-rw-r--r--test/zdtm/static/Makefile1
-rw-r--r--test/zdtm/static/inotify04.c124
2 files changed, 125 insertions, 0 deletions
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 <unistd.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/inotify.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc = "Check inotify does not have trash in queue after c/r";
+const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>";
+
+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;
+}