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'}