From a4757fe31c20b01fabeb33e3d918653948912aeb Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 21 Apr 2022 21:08:34 -0700 Subject: [PATCH] ... --- test/unit/watch.tests.c | 64 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/test/unit/watch.tests.c b/test/unit/watch.tests.c index 804a44a..6a0b896 100644 --- a/test/unit/watch.tests.c +++ b/test/unit/watch.tests.c @@ -25,7 +25,67 @@ int main() { } static void watch_functionality_basic_test() { - assert(0); + /* see `man inotify` for explanation of alignment modifiers */ + char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event)))); + const struct inotify_event *event; + int fd, watch_fd; + ssize_t len; + char *p; + + fd = inotify_init(); + assert(fd>=0); + + watch_fd = inotify_add_watch(fd,TEST_DIRECTORY,WATCH_FLAGS); + assert(watch_fd>=0); + + system("echo hello > " TEST_DIRECTORY "/notarealfile.txt"); // IN_CREATE + IN_MODIFY + IN_CLOSE_WRITE + system("echo hello2 >> " TEST_DIRECTORY "/notarealfile.txt"); // IN_MODIFY + IN_CLOSE_WRITE + system("mv " TEST_DIRECTORY "/notarealfile.txt " TEST_DIRECTORY "/notarealfile2.txt"); // IN_MOVED_TO + system("rm " TEST_DIRECTORY "/notarealfile2.txt"); // IN_DELETE + + len = read(fd,buf,sizeof(buf)); + assert(len==336); + + p = buf; + event = (const struct inotify_event*) p; + assert(event->mask & IN_CREATE); + assert(strcmp(event->name,"notarealfile.txt")==0); + + p += (sizeof(struct inotify_event)+event->len); + event = (const struct inotify_event*) p; + assert(event->mask & IN_MODIFY); + assert(strcmp(event->name,"notarealfile.txt")==0); + + p += (sizeof(struct inotify_event)+event->len); + event = (const struct inotify_event*) p; + assert(event->mask & IN_CLOSE_WRITE); + assert(strcmp(event->name,"notarealfile.txt")==0); + + p += (sizeof(struct inotify_event)+event->len); + event = (const struct inotify_event*) p; + assert(event->mask & IN_MODIFY); + assert(strcmp(event->name,"notarealfile.txt")==0); + + p += (sizeof(struct inotify_event)+event->len); + event = (const struct inotify_event*) p; + assert(event->mask & IN_CLOSE_WRITE); + assert(strcmp(event->name,"notarealfile.txt")==0); + + p += (sizeof(struct inotify_event)+event->len); + event = (const struct inotify_event*) p; + assert(event->mask & IN_MOVED_TO); + assert(strcmp(event->name,"notarealfile2.txt")==0); + + p += (sizeof(struct inotify_event)+event->len); + event = (const struct inotify_event*) p; + assert(event->mask & IN_DELETE); + assert(strcmp(event->name,"notarealfile2.txt")==0); + + assert((p+(sizeof(struct inotify_event)+event->len)-buf)==336); + + close(fd); + + reset_env(); } static void watch_spawn_all_basic_test() { @@ -47,4 +107,6 @@ static void watch_spawn_all_basic_test() { close(fd); torrent_free(p); + + reset_env(); } -- 2.30.2