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
This commit is contained in:
Pavel Tikhomirov 2019-06-26 15:47:39 +03:00 committed by Andrei Vagin
parent 96992883ca
commit e5bdcbbd1d
2 changed files with 125 additions and 0 deletions

View file

@ -311,6 +311,7 @@ TST_DIR = \
inotify00 \
inotify01 \
inotify02 \
inotify04 \
cgroup00 \
rmdir_open \
cgroup01 \

View file

@ -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;
}