summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Cernekee <cernekee@gmail.com>2012-04-07 13:31:31 -0700
committerMike Frysinger <vapier@gentoo.org>2012-04-08 17:00:57 -0400
commit5707bfc85c4da593ae5df6fb243ddb5639957def (patch)
tree281878586103778bbe8fc6ec69936590dcf9073c
parentf6944967ac9ec5d1014a8e004e5d567f595668f4 (diff)
test/misc: Add tst-inotify
Signed-off-by: Kevin Cernekee <cernekee@gmail.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--test/.gitignore1
-rw-r--r--test/misc/tst-inotify.c66
2 files changed, 67 insertions, 0 deletions
diff --git a/test/.gitignore b/test/.gitignore
index 2b035431e..65490c237 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -151,6 +151,7 @@ misc/popen
misc/seek
misc/sem
misc/stdarg
+misc/tst-inotify
misc/tst-scandir
misc/tst-seekdir
misc/tst-utmp
diff --git a/test/misc/tst-inotify.c b/test/misc/tst-inotify.c
new file mode 100644
index 000000000..9d940f7fd
--- /dev/null
+++ b/test/misc/tst-inotify.c
@@ -0,0 +1,66 @@
+/* vi: set sw=4 ts=4 sts=4: */
+/*
+ * inotify test for uClibc
+ * Copyright (C) 2012 by Kevin Cernekee <cernekee@gmail.com>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <error.h>
+#include <inttypes.h>
+#include <sys/inotify.h>
+#include <sys/fcntl.h>
+
+static int
+do_test(void)
+{
+ int ifd, fd, ret, result = 0;
+ struct inotify_event e;
+ char tfile[] = "/tmp/inotify.XXXXXX";
+
+ fd = mkstemp(tfile);
+ close(fd);
+
+ ifd = inotify_init1(IN_NONBLOCK);
+ if (ifd < 0) {
+ perror("inotify_init1()");
+ result = 1;
+ }
+ if (inotify_add_watch(ifd, tfile, IN_DELETE_SELF) < 0) {
+ perror("inotify_add_watch()");
+ result = 1;
+ }
+
+ /* nonblocking inotify should return immediately with no events */
+ ret = read(ifd, &e, sizeof(e));
+ if (ret != -1 || errno != EAGAIN) {
+ error(0, 0, "first read() returned %d", ret);
+ result = 1;
+ }
+
+ /* generate an event */
+ unlink(tfile);
+
+ /* now check whether our event was seen */
+ ret = read(ifd, &e, sizeof(e));
+ if (ret != sizeof(e)) {
+ error(0, 0, "second read() returned %d", ret);
+ result = 1;
+ }
+
+ if (!(e.mask & IN_DELETE_SELF)) {
+ error(0, 0, "incorrect event mask: %" PRIx32, e.mask);
+ result = 1;
+ }
+
+ return result;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"