From 2a250921522944debf4ed95a3a83c999bb31c91c Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Wed, 21 Oct 2015 10:28:00 +0300 Subject: [PATCH] test: Add inotify02 Its only purpose if to verify that we can show up a huge number of inotify in fdoutput (before the kernel v3.18-rc1-7-ga3816ab we can show only handles which fit page size in summary). In particular we revealed that hald daemon makes up to 35 notification marks which kernel can't show up in a one pass and dump fails. Signed-off-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov --- test/zdtm.sh | 1 + test/zdtm/live/static/inotify02.c | 101 +++++++++++++++++++++++++++ test/zdtm/live/static/inotify02.desc | 1 + 3 files changed, 103 insertions(+) create mode 100644 test/zdtm/live/static/inotify02.c create mode 100644 test/zdtm/live/static/inotify02.desc diff --git a/test/zdtm.sh b/test/zdtm.sh index 93f32ce4e..6966cecdc 100755 --- a/test/zdtm.sh +++ b/test/zdtm.sh @@ -100,6 +100,7 @@ generate_test_list() static/eventfs00 static/signalfd00 static/inotify00 + static/inotify02 static/inotify_irmap static/fanotify00 static/unbound_sock diff --git a/test/zdtm/live/static/inotify02.c b/test/zdtm/live/static/inotify02.c new file mode 100644 index 000000000..9e2c5f76c --- /dev/null +++ b/test/zdtm/live/static/inotify02.c @@ -0,0 +1,101 @@ +#define _GNU_SOURCE + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "Check for inotify file-handles storm"; +const char *test_author = "Cyrill Gorcunov "; + +char *dirname; +TEST_OPTION(dirname, string, "directory name", 1); + +static int num_of_handles(int fd) +{ + char path[64]; + char buf[512]; + int ret = 0; + FILE *f; + + snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd); + f = fopen(path, "r"); + if (!f) { + err("Can't open %s", path); + return -1; + } + + while (fgets(buf, sizeof(buf), f)) { + if (memcmp(buf, "inotify ", 8)) + continue; + ret++; + } + + fclose(f); + return ret; +} + +int main (int argc, char *argv[]) +{ + const unsigned int mask = IN_DELETE | IN_CLOSE_WRITE | IN_DELETE_SELF | IN_CREATE; + const int nr_dirs = 64; + char temp[nr_dirs][16]; + char path[PATH_MAX]; + int fd, i; + + test_init(argc, argv); + + if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { + err("Can't create directory %s", dirname); + exit(1); + } + + fd = inotify_init1(IN_NONBLOCK); + if (fd < 0) { + err("inotify_init failed"); + exit(1); + } + + for (i = 0; i < nr_dirs; i++) { + snprintf(temp[i], sizeof(temp[0]), "d.%03d", i); + snprintf(path, sizeof(path), "%s/%s", dirname, temp[i]); + if (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { + err("Can't create %s", path); + exit(1); + } + + if (inotify_add_watch(fd, path, mask) < 0) { + err("inotify_add_watch failed on %s", path); + exit(1); + } + } + + test_daemon(); + test_waitsig(); + + i = num_of_handles(fd); + close(fd); + + if (i < nr_dirs) + fail("Expected %d handles but got %d", nr_dirs, i); + else + pass(); + + return 0; +} diff --git a/test/zdtm/live/static/inotify02.desc b/test/zdtm/live/static/inotify02.desc new file mode 100644 index 000000000..95c58b401 --- /dev/null +++ b/test/zdtm/live/static/inotify02.desc @@ -0,0 +1 @@ +{'flags': 'noauto'}