From: alex Date: Fri, 22 Apr 2022 04:08:34 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=a4757fe31c20b01fabeb33e3d918653948912aeb;p=seeder ... --- 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(); }