]> git.saurik.com Git - apple/xnu.git/blame - tools/tests/kqueue_tests/kqueue_file_tests.c
xnu-3789.60.24.tar.gz
[apple/xnu.git] / tools / tests / kqueue_tests / kqueue_file_tests.c
CommitLineData
b0d623f7
A
1#include <string.h>
2#include <errno.h>
3#include <pwd.h>
4#include <stdarg.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <unistd.h>
8#include <fcntl.h>
9#include <pthread.h>
10#include <poll.h>
11#include <sys/types.h>
12#include <sys/event.h>
13#include <sys/time.h>
14#include <sys/stat.h>
15#include <sys/mman.h>
39236c6e 16#include <sys/xattr.h>
39037602 17#include <sys/file.h>
b0d623f7 18
39037602 19#define DIR1 "/tmp/dir1"
b0d623f7 20#define DOTDOT ".."
39037602
A
21#define DIR2 "/tmp/dir2"
22#define FILE1 "/tmp/file1"
23#define FILE2 "/tmp/file2"
b0d623f7
A
24
25#define KEY "somekey"
26#define VAL "someval"
27
28#define NOSLEEP 0
29#define SLEEP 1
30#define NO_EVENT 0
31#define YES_EVENT 1
32
33
39037602 34#define OUTPUT_LEVEL 0
b0d623f7
A
35#define RESULT_LEVEL 3
36
37#define TEST_STRING "Some text!!! Yes indeed, some of that very structure which has passed on man's knowledge for generations."
38#define HELLO_WORLD "Hello, World!"
39#define SLEEP_TIME 2
40#define WAIT_TIME (4l)
41#define LENGTHEN_SIZE 500
42#define FIFO_SPACE 8192 /* FIFOS have 8K of buffer space */
43
39037602
A
44/*
45 * These two variables are the non local memory for holding the return
46 * values from functions with which pthread_create is called.
47 */
48int thread_status;
49int fifo_read_fd;
50
b0d623f7
A
51/*
52 * Types of actions for setup, cleanup, and execution of tests
53 */
54typedef enum {CREAT, MKDIR, READ, WRITE, WRITEFD, FILLFD, UNLINK, LSKEE, RMDIR, MKFIFO, LENGTHEN, TRUNC,
55 SYMLINK, CHMOD, CHOWN, EXCHANGEDATA, RENAME, LSEEK, OPEN, MMAP, NOTHING,
39037602 56 SETXATTR, UTIMES, STAT, HARDLINK, REVOKE, FUNLOCK} action_id_t;
b0d623f7
A
57
58/*
59 * Directs an action as mentioned above
60 */
61typedef struct _action {
62 int act_dosleep;
63 action_id_t act_id;
64 void *act_args[5];
65 int act_fd;
66} action_t;
67
68/*
69 * A test case. Specifies setup, an event to look for, an action to take to
70 * cause (or not cause) that event, and cleanup.
71 */
72typedef struct _test {
73 char *t_testname;
6d2010ae 74
b0d623f7
A
75 /* Test kevent() or poll() */
76 int t_is_poll_test;
6d2010ae 77
b0d623f7
A
78 /* Actions for setting up test */
79 int t_n_prep_actions;
80 action_t t_prep_actions[5];
6d2010ae 81
b0d623f7
A
82 /* Actions for cleaning up test */
83 int t_n_cleanup_actions;
84 action_t t_cleanup_actions[5];
85
86 /* Action for thred to take while we wait */
87 action_t t_helpthreadact;
6d2010ae 88
b0d623f7
A
89 /* File to look for event on */
90 char *t_watchfile; /* set event ident IN TEST (can't know fd beforehand)*/
91 int t_file_is_fifo;/* FIFOs are handled in a special manner */
6d2010ae 92
b0d623f7
A
93 /* Different parameters for poll() vs kevent() */
94 union {
95 struct kevent tu_kev;
96 short tu_pollevents;
97 } t_union;
6d2010ae 98
b0d623f7
A
99 /* Do we expect results? */
100 int t_want_event;
6d2010ae 101
b0d623f7
A
102 /* Not always used--how much data should we find (EVFILT_{READ,WRITE}) */
103 int t_nbytes;
6d2010ae 104
b0d623f7
A
105 /* Hacks for FILT_READ and pipes */
106 int t_read_to_end_first; /* Consume all data in file before waiting for event */
107 int t_write_some_data; /* Write some data to file before waiting for event (FIFO hack) */
108 int t_extra_sleep_hack; /* Sleep before waiting, to let a fifo fill up with data */
109} test_t;
110
111/*
112 * Extra logging infrastructure so we can filter some out
113 */
114void LOG(int level, FILE *f, const char *fmt, ...) {
115 va_list ap;
116 va_start(ap, fmt);
117 if (level >= OUTPUT_LEVEL) {
118 /* Indent for ease of reading */
119 if (level < RESULT_LEVEL) {
39037602
A
120 for (int i = RESULT_LEVEL - level; i>0; i--) {
121 fprintf(f, "\t");
122 }
b0d623f7
A
123 }
124 vfprintf(f, fmt, ap);
125 }
6d2010ae 126
b0d623f7
A
127 va_end(ap);
128}
129
39037602
A
130char *
131get_action_name(action_id_t a)
132{
133 switch (a) {
134 case CREAT:
135 return "CREAT";
136 case MKDIR:
137 return "MKDIR";
138 case READ:
139 return "READ";
140 case WRITE:
141 return "WRITE";
142 case WRITEFD:
143 return "WRITEFD";
144 case FILLFD:
145 return "FILLFD";
146 case UNLINK:
147 return "UNLINK";
148 case LSKEE:
149 return "LSKEE";
150 case RMDIR:
151 return "RMDIR";
152 case MKFIFO:
153 return "MKFIFO";
154 case LENGTHEN:
155 return "LENGTHEN";
156 case TRUNC:
157 return "TRUNC";
158 case SYMLINK:
159 return "SYMLINK";
160 case CHMOD:
161 return "CHMOD";
162 case CHOWN:
163 return "CHOWN";
164 case EXCHANGEDATA:
165 return "EXCHANGEDATA";
166 case RENAME:
167 return "RENAME";
168 case LSEEK:
169 return "LSEEK";
170 case OPEN:
171 return "OPEN";
172 case MMAP:
173 return "MMAP";
174 case NOTHING:
175 return "NOTHING";
176 case SETXATTR:
177 return "SETXATTR";
178 case UTIMES:
179 return "UTIMES";
180 case STAT:
181 return "STAT";
182 case HARDLINK:
183 return "HARDLINK";
184 case REVOKE:
185 return "REVOKE";
186 case FUNLOCK:
187 return "FUNLOCK";
188 }
189 return "Unknown";
190}
b0d623f7
A
191/*
192 * Initialize an action struct. Whether to sleep, what action to take,
193 * and arguments for that action.
194 */
6d2010ae 195void
b0d623f7
A
196init_action(action_t *act, int sleep, action_id_t call, int nargs, ...)
197{
198 int i;
199 va_list ap;
200 va_start(ap, nargs);
201 act->act_dosleep = sleep;
202 act->act_id = call;
6d2010ae 203
b0d623f7
A
204 for (i = 0; i < nargs; i++)
205 {
206 act->act_args[i] = va_arg(ap, void*);
207 }
6d2010ae 208
b0d623f7 209 va_end(ap);
6d2010ae 210
b0d623f7
A
211}
212
213/*
214 * Opening a fifo is complicated: need to open both sides at once
215 */
39037602 216void *
b0d623f7
A
217open_fifo_readside(void *arg)
218{
39037602
A
219 fifo_read_fd = open((char*)arg, O_RDONLY);
220 return (&fifo_read_fd);
b0d623f7
A
221}
222
223/*
224 * Open a fifo, setting read and write descriptors. Return 0 for success, -1 for failure.
225 * Only set FD args upon success; they will be unmodified on failure.
226 */
227int
228open_fifo(const char *path, int *readfd, int *writefd)
229{
230 pthread_t thread;
231 int waitres;
232 int res;
39037602 233 int *tmpreadfd, tmpwritefd;
6d2010ae 234
39037602 235 fifo_read_fd = -1;
b0d623f7
A
236 res = pthread_create(&thread, 0, open_fifo_readside, (void*)path);
237 if (res == 0) {
238 tmpwritefd = open(path, O_WRONLY);
239 waitres = pthread_join(thread, (void**) &tmpreadfd);
6d2010ae 240
b0d623f7 241 fcntl(tmpwritefd, F_SETFL, O_WRONLY | O_NONBLOCK);
6d2010ae 242
39037602
A
243 if ((waitres == 0) && (tmpwritefd >= 0) && (*tmpreadfd >= 0)) {
244 *readfd = *tmpreadfd;
b0d623f7
A
245 *writefd = tmpwritefd;
246 } else {
247 res = -1;
248 }
249 }
250
251 return res;
252}
253
254/*
255 * Just concatenate a directory and a filename, sticking a "/" betwixt them
256 */
257void
258makepath(char *buf, const char *dir, const char *file)
259{
260 strcpy(buf, dir);
261 strcat(buf, "/");
262 strcat(buf, file);
263}
264
265
266/* Execute a prep, cleanup, or test action; specific tricky notes below.
267 *
268 * CREAT: comes to life and given length 1
269 * READ: try to read one char
270 * WRITE: try to write TEST_STRING to file
271 * LENGTHEN: make longer by LENGTHEN_SIZE
272 * MMAP: mmap first 20 bytes of file, write HELLO_WORLD in
273 * SETXATTR: set the KEY attribute to value VAL
274 * WRITEFD: instead of opening fresh, take an FD in the action struct (FIFOs)
275 * FILLFD: write a file until you can no longer. for filling FIFOS.
276 *
277 * * Several of these have hard-coded sizes.
278 */
279void*
280execute_action(void *actionptr)
281{
282 action_t *act = (action_t*)actionptr;
283 void **args = act->act_args;
284 char c;
285 int res = -1, tmpfd, tmpfd2;
286 static int lastfd;
287 void *addr;
288 struct timeval tv;
289 struct stat sstat;
6d2010ae 290
39037602 291 LOG(1, stderr, "Beginning action of type %d: %s\n", act->act_id, get_action_name(act->act_id));
6d2010ae 292
b0d623f7
A
293 /* Let other thread get into kevent() sleep */
294 if(SLEEP == act->act_dosleep) {
295 sleep(SLEEP_TIME);
296 }
297 switch(act->act_id) {
298 case NOTHING:
299 res = 0;
300 break;
301 case CREAT:
302 tmpfd = creat((char*)args[0], 0755);
303 ftruncate(tmpfd, 1); /* So that mmap() doesn't fool us */
304 if (tmpfd >= 0) {
305 close(tmpfd);
306 res = 0;
307 }
308 break;
309 case MKDIR:
310 res = mkdir((char*)args[0], 0755);
311 break;
312 case READ:
313 tmpfd = open((char*)args[0], O_RDONLY);
314 if (tmpfd >= 0) {
315 res = read(tmpfd, &c, 1);
316 res = (res == 1 ? 0 : -1);
317 }
318 close(tmpfd);
319 break;
320 case WRITE:
321 tmpfd = open((char*)args[0], O_RDWR);
322 if (tmpfd >= 0) {
323 res = write(tmpfd, TEST_STRING, strlen(TEST_STRING));
324 if (res == strlen(TEST_STRING)) {
325 res = 0;
326 } else {
327 res = -1;
328 }
6d2010ae 329
b0d623f7
A
330 close(tmpfd);
331 }
332 break;
333 case WRITEFD:
334 res = write((int)act->act_fd, TEST_STRING, strlen(TEST_STRING));
335 if (res == strlen(TEST_STRING)) {
336 res = 0;
337 } else {
338 res = -1;
339 }
340 break;
341 case FILLFD:
342 while (write((int)act->act_fd, "a", 1) > 0);
343 res = 0;
344 break;
345 case UNLINK:
346 res = unlink((char*)args[0]);
347 break;
348 case LSEEK:
349 res = lseek((int)act->act_fd, (int)args[0], SEEK_SET);
350 res = (res == (int)args[0] ? 0 : -1);
351 break;
352 case RMDIR:
353 res = rmdir((char*)args[0]);
354 break;
355 case MKFIFO:
356 res = mkfifo((char*)args[0], 0755);
357 break;
358 case LENGTHEN:
359 res = truncate((char*)args[0], LENGTHEN_SIZE);
360 break;
361 case TRUNC:
362 res = truncate((char*)args[0], 0);
363 break;
364 case SYMLINK:
365 res = symlink((char*)args[0], (char*)args[1]);
366 break;
367 case CHMOD:
368 res = chmod((char*)args[0], (int)args[1]);
369 break;
370 case CHOWN:
371 /* path, uid, gid */
372 res = chown((char*)args[0], (int) args[1], (int) args[2]);
373 break;
374 case EXCHANGEDATA:
375 res = exchangedata((char*)args[0], (char*)args[1], 0);
376 break;
377 case RENAME:
378 res = rename((char*)args[0], (char*)args[1]);
379 break;
380 case OPEN:
381 tmpfd = open((char*)args[0], O_RDONLY | O_CREAT);
382 res = close(tmpfd);
383 break;
384 case MMAP:
385 /* It had best already exist with nonzero size */
386 tmpfd = open((char*)args[0], O_RDWR);
387 addr = mmap(0, 20, PROT_WRITE | PROT_READ, MAP_FILE | MAP_SHARED, tmpfd, 0);
388 if (addr != ((void*)-1)) {
389 res = 0;
390 if ((int)args[1]) {
391 strcpy((char*)addr, HELLO_WORLD);
392 msync(addr, 20, MS_SYNC);
393 }
394 }
395 close(tmpfd);
396 munmap(addr, 20);
397 break;
398 case SETXATTR:
399 res = setxattr((char*)args[0], KEY, (void*)VAL, strlen(VAL),
6d2010ae 400 0, 0);
b0d623f7
A
401 break;
402 case UTIMES:
403 tv.tv_sec = time(NULL);
404 tv.tv_usec = 0;
405 res = utimes((char*)args[0], &tv);
406 break;
407 case STAT:
408 res = lstat((char*)args[0], &sstat);
409 break;
410 case HARDLINK:
411 res = link((char*)args[0], (char*)args[1]);
412 break;
413 case REVOKE:
414 tmpfd = open((char*)args[0], O_RDONLY);
415 res = revoke((char*)args[0]);
416 close(tmpfd);
417 break;
39037602
A
418 case FUNLOCK:
419 tmpfd = open((char*)args[0], O_RDONLY);
420 if (tmpfd != -1) {
421 res = flock(tmpfd, LOCK_EX);
422 if (res != -1)
423 res = flock(tmpfd, LOCK_UN);
424 (void)close(tmpfd);
425 }
426 break;
b0d623f7
A
427 default:
428 res = -1;
429 break;
430 }
39037602
A
431
432 thread_status = res;
433 return (&thread_status);
b0d623f7
A
434}
435
436/*
437 * Read until the end of a file, for EVFILT_READ purposes (considers file position)
438 */
439void
440read_to_end(int fd)
441{
442 char buf[50];
443 while (read(fd, buf, sizeof(buf)) > 0);
444}
445
446/*
447 * Helper for setup and cleanup; just execute every action in an array
448 * of actions. "failout" parameter indicates whether to stop if one fails.
449 */
450int
451execute_action_list(action_t *actions, int nactions, int failout)
452{
453 int i, res;
454 for (i = 0, res = 0; (0 == res || (!failout)) && (i < nactions); i++) {
455 LOG(1, stderr, "Starting prep action %d\n", i);
39037602 456 res = *((int *) execute_action(&(actions[i])));
b0d623f7 457 if(res != 0) {
39037602 458 LOG(2, stderr, "Action list failed on step %d. res = %d\n", i, res);
b0d623f7
A
459 } else {
460 LOG(1, stderr, "Action list work succeeded on step %d.\n", i);
461 }
462 }
6d2010ae 463
b0d623f7
A
464 return res;
465}
466
467/*
468 * Execute a full test, return success value.
469 */
470int
471execute_test(test_t *test)
472{
39037602 473 int i, kqfd, filefd = -1, res2, res, cnt, writefd = -1;
b0d623f7
A
474 int retval = -1;
475 pthread_t thr;
476 struct kevent evlist;
477 struct timespec ts = {WAIT_TIME, 0l};
39037602
A
478 int *status;
479
b0d623f7 480 memset(&evlist, 0, sizeof(evlist));
6d2010ae 481
b0d623f7
A
482 LOG(1, stderr, "Test %s starting.\n", test->t_testname);
483 LOG(1, stderr, test->t_want_event ? "Expecting an event.\n" : "Not expecting events.\n");
6d2010ae 484
b0d623f7 485 res = execute_action_list(test->t_prep_actions, test->t_n_prep_actions, 1);
6d2010ae 486
b0d623f7
A
487 /* If prep succeeded */
488 if (0 == res) {
489 /* Create kqueue for kqueue tests*/
490 if (!test->t_is_poll_test) {
491 kqfd = kqueue();
492 }
6d2010ae 493
b0d623f7
A
494 if ((test->t_is_poll_test) || kqfd >= 0) {
495 LOG(1, stderr, "Opened kqueue.\n");
6d2010ae 496
b0d623f7
A
497 /* Open the file we're to monitor. Fifos get special handling */
498 if (test->t_file_is_fifo) {
499 filefd = -1;
500 open_fifo(test->t_watchfile, &filefd, &writefd);
501 } else {
502 filefd = open(test->t_watchfile, O_RDONLY | O_SYMLINK);
503 }
6d2010ae 504
b0d623f7
A
505 if (filefd >= 0) {
506 LOG(1, stderr, "Opened file to monitor.\n");
6d2010ae 507
b0d623f7
A
508 /*
509 * Fill in the fd to monitor once you know it
510 * If it's a fifo test, then the helper is definitely going to want the write end.
511 */
512 test->t_helpthreadact.act_fd = (writefd >= 0 ? writefd : filefd);
6d2010ae 513
b0d623f7
A
514 if (test->t_read_to_end_first) {
515 read_to_end(filefd);
516 } else if (test->t_write_some_data) {
517 action_t dowr;
518 init_action(&dowr, NOSLEEP, WRITEFD, 0);
519 dowr.act_fd = writefd;
39037602 520 (void)execute_action(&dowr);
b0d623f7 521 }
6d2010ae 522
b0d623f7 523 /* Helper modifies the file that we're listening on (sleeps first, in general) */
39037602 524 thread_status = 0;
b0d623f7
A
525 res = pthread_create(&thr, NULL, execute_action, (void*) &test->t_helpthreadact);
526 if (0 == res) {
527 LOG(1, stderr, "Created helper thread.\n");
6d2010ae 528
b0d623f7
A
529 /* This is ugly business to hack on filling up a FIFO */
530 if (test->t_extra_sleep_hack) {
531 sleep(5);
532 }
6d2010ae 533
b0d623f7
A
534 if (test->t_is_poll_test) {
535 struct pollfd pl;
536 pl.fd = filefd;
537 pl.events = test->t_union.tu_pollevents;
538 cnt = poll(&pl, 1, WAIT_TIME);
539 LOG(1, stderr, "Finished poll() call.\n");
6d2010ae 540
b0d623f7
A
541 if ((cnt < 0)) {
542 LOG(2, stderr, "error is in errno, %s\n", strerror(errno));
543 res = cnt;
544 }
545 } else {
546 test->t_union.tu_kev.ident = filefd;
547 cnt = kevent(kqfd, &test->t_union.tu_kev, 1, &evlist, 1, &ts);
548 LOG(1, stderr, "Finished kevent() call.\n");
6d2010ae 549
b0d623f7
A
550 if ((cnt < 0) || (evlist.flags & EV_ERROR)) {
551 LOG(2, stderr, "kevent() call failed.\n");
552 if (cnt < 0) {
553 LOG(2, stderr, "error is in errno, %s\n", strerror(errno));
554 } else {
555 LOG(2, stderr, "error is in data, %s\n", strerror(evlist.data));
556 }
557 res = cnt;
558 }
559 }
6d2010ae 560
b0d623f7 561 /* Success only if you've succeeded to this point AND joined AND other thread is happy*/
39037602
A
562 status = NULL;
563 res2 = pthread_join(thr, (void **)&status);
b0d623f7
A
564 if (res2 < 0) {
565 LOG(2, stderr, "Couldn't join helper thread.\n");
39037602
A
566 } else if (*status) {
567 LOG(2, stderr, "Helper action had result %d\n", *status);
b0d623f7 568 }
39037602 569 res = ((res == 0) && (res2 == 0) && (*status == 0)) ? 0 : -1;
b0d623f7
A
570 } else {
571 LOG(2, stderr, "Couldn't start thread.\n");
572 }
6d2010ae 573
b0d623f7
A
574 close(filefd);
575 if (test->t_file_is_fifo) {
576 close(writefd);
577 }
578 } else {
579 LOG(2, stderr, "Couldn't open test file %s to monitor.\n", test->t_watchfile);
580 res = -1;
581 }
582 close(kqfd);
583 } else {
584 LOG(2, stderr, "Couldn't open kqueue.\n");
585 res = -1;
586 }
587 }
6d2010ae 588
b0d623f7
A
589 /* Cleanup work */
590 execute_action_list(test->t_cleanup_actions, test->t_n_cleanup_actions, 0);
6d2010ae 591
b0d623f7
A
592 /* Success if nothing failed and we either received or did not receive event,
593 * as expected
594 */
595 if (0 == res) {
596 LOG(1, stderr, cnt > 0 ? "Got an event.\n" : "Did not get an event.\n");
597 if (((cnt > 0) && (test->t_want_event)) || ((cnt == 0) && (!test->t_want_event))) {
598 if ((!test->t_is_poll_test) && (test->t_union.tu_kev.filter == EVFILT_READ || test->t_union.tu_kev.filter == EVFILT_WRITE)
599 && (test->t_nbytes) && (test->t_nbytes != evlist.data)) {
600 LOG(2, stderr, "Read wrong number of bytes available. Wanted %d, got %d\n", test->t_nbytes, evlist.data);
601 retval = -1;
602 } else {
603 retval = 0;
604 }
6d2010ae 605
b0d623f7
A
606 } else {
607 LOG(2, stderr, "Got unexpected event or lack thereof.\n");
608 retval = -1;
609 }
610 } else {
39037602 611 LOG(2, stderr, "Failed to execute test. res = %d\n", res);
b0d623f7
A
612 retval = -1;
613 }
6d2010ae 614
b0d623f7 615 LOG(3, stdout, "Test %s done with result %d.\n", test->t_testname, retval);
39037602 616 return (retval);
b0d623f7
A
617}
618
619void
620init_test_common(test_t *tst, char *testname, char *watchfile, int nprep, int nclean, int event, int want, int ispoll)
621{
622 memset(tst, 0, sizeof(test_t));
623 tst->t_testname = testname;
624 tst->t_watchfile = watchfile;
625 tst->t_n_prep_actions = nprep;
626 tst->t_n_cleanup_actions = nclean;
627 tst->t_want_event = (want > 0);
6d2010ae 628
b0d623f7
A
629 if (ispoll) {
630 tst->t_is_poll_test = 1;
631 tst->t_union.tu_pollevents = (short)event;
632 } else {
633 /* Can do this because filter is negative, notes are positive */
634 if (event == EVFILT_READ || event == EVFILT_WRITE) {
635 EV_SET(&tst->t_union.tu_kev, 0, event, EV_ADD | EV_ENABLE, 0, 0, NULL);
636 tst->t_nbytes = want;
637 } else {
638 EV_SET(&tst->t_union.tu_kev, 0, EVFILT_VNODE, EV_ADD | EV_ENABLE, event, 0, NULL);
639 }
640 }
641}
642
643/*
644 * Initialize a test case, not including its actions. Meaning: a name for it, what filename to watch,
645 * counts of prep and cleanup actions, what event to watch for, and whether you want an event/how many bytes read.
646 *
647 * "want" does double duty as whether you want an event and how many bytes you might want to read
648 * "event" is either an event flag (e.g. NOTE_WRITE) or EVFILT_READ
649 */
650void
651init_test(test_t *tst, char *testname, char *watchfile, int nprep, int nclean, int event, int want)
652{
653 init_test_common(tst, testname, watchfile, nprep, nclean, event, want, 0);
654}
655
656/*
657 * Same as above, but for a poll() test
658 */
659void
660init_poll_test(test_t *tst, char *testname, char *watchfile, int nprep, int nclean, int event, int want)
661{
662 init_test_common(tst, testname, watchfile, nprep, nclean, event, want, 1);
663}
664
665void
666run_note_delete_tests()
667{
668 test_t test;
6d2010ae 669
b0d623f7
A
670 init_test(&test, "1.1.2: unlink a file", FILE1, 1, 0, NOTE_DELETE, YES_EVENT);
671 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
672 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 2, (void*)FILE1, NULL);
673 execute_test(&test);
6d2010ae 674
b0d623f7
A
675 init_test(&test, "1.1.3: rmdir a dir", DIR1, 1, 0, NOTE_DELETE, YES_EVENT);
676 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
677 init_action(&test.t_helpthreadact, SLEEP, RMDIR, 2, (void*)DIR1, NULL);
678 execute_test(&test);
6d2010ae 679
b0d623f7
A
680 init_test(&test, "1.1.4: rename one file over another", FILE2, 2, 1, NOTE_DELETE, YES_EVENT);
681 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
682 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)FILE2, (void*)NULL);
683 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)FILE2);
684 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE2, NULL);
685 execute_test(&test);
6d2010ae 686
b0d623f7
A
687 init_test(&test, "1.1.5: rename one dir over another", DIR2, 2, 1, NOTE_DELETE, YES_EVENT);
688 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
689 init_action(&(test.t_prep_actions[1]), NOSLEEP, MKDIR, 2, (void*)DIR2, (void*)NULL);
690 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)DIR1, (void*)DIR2);
691 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR2, NULL);
692 execute_test(&test);
6d2010ae 693
b0d623f7
A
694 /* Do FIFO stuff here */
695 init_test(&test, "1.1.6: make a fifo, unlink it", FILE1, 1, 0, NOTE_DELETE, YES_EVENT);
696 test.t_file_is_fifo = 1;
697 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 2, (void*)FILE1, (void*)NULL);
698 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 1, (void*)FILE1);
699 execute_test(&test);
6d2010ae 700
b0d623f7
A
701 init_test(&test, "1.1.7: rename a file over a fifo", FILE1, 2, 1, NOTE_DELETE, YES_EVENT);
702 test.t_file_is_fifo = 1;
703 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 2, (void*)FILE1, (void*)NULL);
704 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)FILE2, (void*)NULL);
705 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE2, (void*)FILE1);
706 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
707 execute_test(&test);
6d2010ae 708
b0d623f7
A
709 init_test(&test, "1.1.8: unlink a symlink to a file", FILE2, 2, 1, NOTE_DELETE, YES_EVENT);
710 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
711 init_action(&(test.t_prep_actions[1]), NOSLEEP, SYMLINK, 2, (void*)FILE1, (void*)FILE2);
712 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 2, (void*)FILE2, NULL);
713 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
714 execute_test(&test);
6d2010ae 715
b0d623f7 716 /* ================= */
6d2010ae 717
b0d623f7
A
718 init_test(&test, "1.2.1: Straight-up rename file", FILE1, 1, 1, NOTE_DELETE, NO_EVENT);
719 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
720 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)FILE2);
721 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE2, (void*)NULL);
722 execute_test(&test);
6d2010ae 723
b0d623f7
A
724 init_test(&test, "1.2.2: Straight-up rename dir", DIR1, 1, 1, NOTE_DELETE, NO_EVENT);
725 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
726 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)DIR1, (void*)DIR2);
727 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR2, (void*)NULL);
728 execute_test(&test);
6d2010ae 729
b0d623f7
A
730 init_test(&test, "1.2.3: Null action on file", FILE1, 1, 1, NOTE_DELETE, NO_EVENT);
731 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
732 init_action(&test.t_helpthreadact, SLEEP, NOTHING, 2, NULL, NULL); /* The null action */
733 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
734 execute_test(&test);
6d2010ae 735
b0d623f7
A
736 init_test(&test, "1.2.4: Rename one file over another: watch the file that lives", FILE1, 2, 1, NOTE_DELETE, NO_EVENT);
737 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
738 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)FILE2, (void*)NULL);
739 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)FILE2);
740 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE2, NULL);
741 execute_test(&test);
6d2010ae 742
b0d623f7
A
743 init_test(&test, "1.2.5: Rename one dir over another, watch the dir that lives", DIR1, 2, 1, NOTE_DELETE, NO_EVENT);
744 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
745 init_action(&(test.t_prep_actions[1]), NOSLEEP, MKDIR, 2, (void*)DIR2, (void*)NULL);
746 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)DIR1, (void*)DIR2);
747 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR2, NULL);
748}
749
750void
751run_note_write_tests()
752{
753 char pathbuf[50];
754 char otherpathbuf[50];
6d2010ae 755
b0d623f7 756 test_t test;
6d2010ae 757
b0d623f7
A
758 init_test(&test, "2.1.1: Straight-up write to a file", FILE1, 1, 1, NOTE_WRITE, YES_EVENT);
759 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
760 init_action(&test.t_helpthreadact, SLEEP, WRITE, 2, (void*)FILE1, NULL);
761 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
762 execute_test(&test);
6d2010ae
A
763
764
b0d623f7
A
765 makepath(pathbuf, DIR1, FILE1);
766 init_test(&test, "2.1.2: creat() file inside a dir", DIR1, 1, 2, NOTE_WRITE, YES_EVENT);
767 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
768 init_action(&test.t_helpthreadact, SLEEP, CREAT, 2, (void*)pathbuf, NULL);
769 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
770 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
771 execute_test(&test);
6d2010ae 772
b0d623f7
A
773 makepath(pathbuf, DIR1, FILE1);
774 init_test(&test, "2.1.3: open() file inside a dir", DIR1, 1, 2, NOTE_WRITE, YES_EVENT);
775 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
776 init_action(&test.t_helpthreadact, SLEEP, OPEN, 2, (void*)pathbuf, NULL);
777 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
778 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
779 execute_test(&test);
6d2010ae 780
b0d623f7
A
781 makepath(pathbuf, DIR1, FILE1);
782 init_test(&test, "2.1.3: unlink a file from a dir", DIR1, 2, 1, NOTE_WRITE, YES_EVENT);
783 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
784 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)pathbuf, (void*)NULL);
785 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 2, (void*)pathbuf, NULL);
786 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
787 execute_test(&test);
6d2010ae 788
b0d623f7
A
789 makepath(pathbuf, DIR1, FILE1);
790 makepath(otherpathbuf, DIR1, FILE2);
791 init_test(&test, "2.1.5: rename a file in a dir", DIR1, 2, 2, NOTE_WRITE, YES_EVENT);
792 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
793 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)pathbuf, (void*)NULL);
794 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)pathbuf, (void*)otherpathbuf);
795 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)otherpathbuf, (void*)NULL);
796 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
797 execute_test(&test);
6d2010ae 798
b0d623f7
A
799 makepath(pathbuf, DIR1, FILE1);
800 init_test(&test, "2.1.6: rename a file to outside of a dir", DIR1, 2, 2, NOTE_WRITE, YES_EVENT);
801 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
802 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)pathbuf, (void*)NULL);
803 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)pathbuf, (void*)FILE1);
804 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
805 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
806 execute_test(&test);
6d2010ae 807
b0d623f7
A
808 makepath(pathbuf, DIR1, FILE1);
809 init_test(&test, "2.1.7: rename a file into a dir", DIR1, 2, 2, NOTE_WRITE, YES_EVENT);
810 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
811 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
812 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)pathbuf);
813 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
814 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
815 execute_test(&test);
6d2010ae 816
b0d623f7
A
817 makepath(pathbuf, DIR1, FILE1);
818 init_test(&test, "2.1.9: unlink a fifo from a dir", DIR1, 2, 1, NOTE_WRITE, YES_EVENT);
819 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
820 init_action(&(test.t_prep_actions[1]), NOSLEEP, MKFIFO, 2, (void*)pathbuf, (void*)NULL);
821 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 2, (void*)pathbuf, NULL);
822 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
823 execute_test(&test);
6d2010ae 824
b0d623f7
A
825 makepath(pathbuf, DIR1, FILE1);
826 init_test(&test, "2.1.10: make symlink in a dir", DIR1, 1, 2, NOTE_WRITE, YES_EVENT);
827 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
828 init_action(&test.t_helpthreadact, SLEEP, SYMLINK, 2, (void*)DOTDOT, (void*)pathbuf);
829 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
830 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
831 execute_test(&test);
832
833 init_test(&test, "2.1.12: write to a FIFO", FILE1, 1, 1, NOTE_WRITE, YES_EVENT);
834 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 2, (void*)FILE1, (void*)NULL);
835 test.t_file_is_fifo = 1;
836 init_action(&test.t_helpthreadact, SLEEP, WRITEFD, 0);
837 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
838 execute_test(&test);
6d2010ae
A
839
840
b0d623f7
A
841 makepath(pathbuf, DIR1, FILE1);
842 init_test(&test, "2.1.13: delete a symlink in a dir", DIR1, 2, 1, NOTE_WRITE, YES_EVENT);
843 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
844 init_action(&(test.t_prep_actions[1]), NOSLEEP, SYMLINK, 2, (void*)DOTDOT, (void*)pathbuf);
845 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 2, (void*)pathbuf, (void*)FILE1);
846 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
847 execute_test(&test);
6d2010ae 848
b0d623f7
A
849 /* This actually should not generate an event, though it's in this section */
850 makepath(pathbuf, DIR1, FILE1);
851 makepath(otherpathbuf, DIR1, FILE2);
852 init_test(&test, "2.1.14: exchangedata two files in a dir", DIR1, 3, 3, NOTE_WRITE, NO_EVENT);
853 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
854 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)pathbuf, (void*)NULL);
855 init_action(&(test.t_prep_actions[2]), NOSLEEP, CREAT, 2, (void*)otherpathbuf, (void*)NULL);
856 init_action(&test.t_helpthreadact, SLEEP, EXCHANGEDATA, 2, (void*)pathbuf, (void*)otherpathbuf);
857 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
858 init_action(&test.t_cleanup_actions[1], NOSLEEP, UNLINK, 2, (void*)otherpathbuf, (void*)NULL);
859 init_action(&test.t_cleanup_actions[2], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
860 execute_test(&test);
6d2010ae 861
b0d623f7
A
862 LOG(1, stderr, "MMAP test should fail on HFS.\n");
863 init_test(&test, "2.1.15: Change a file with mmap()", FILE1, 1, 1, NOTE_WRITE, YES_EVENT);
864 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
865 init_action(&test.t_helpthreadact, SLEEP, MMAP, 2, (void*)FILE1, (void*)1); /* 1 -> "modify it"*/
866 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
867 execute_test(&test);
6d2010ae 868
b0d623f7
A
869 /*================= no-event tests ==================*/
870 init_test(&test, "2.2.1: just open and close existing file", FILE1, 1, 1, NOTE_WRITE, NO_EVENT);
871 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
872 init_action(&test.t_helpthreadact, SLEEP, OPEN, 2, (void*)FILE1, NULL);
873 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
874 execute_test(&test);
6d2010ae 875
b0d623f7
A
876 init_test(&test, "2.2.2: read from existing file", FILE1, 1, 1, NOTE_WRITE, NO_EVENT);
877 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
878 init_action(&test.t_helpthreadact, SLEEP, READ, 2, (void*)FILE1, NULL);
879 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
880 execute_test(&test);
6d2010ae 881
b0d623f7
A
882 init_test(&test, "2.2.3: rename existing file", FILE1, 1, 1, NOTE_WRITE, NO_EVENT);
883 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
884 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)FILE2);
885 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE2, (void*)NULL);
886 execute_test(&test);
6d2010ae 887
b0d623f7
A
888 init_test(&test, "2.2.4: just open and close dir", DIR1, 1, 1, NOTE_WRITE, NO_EVENT);
889 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
890 init_action(&test.t_helpthreadact, SLEEP, OPEN, 2, (void*)DIR1, (void*)NULL);
891 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
892 execute_test(&test);
6d2010ae 893
b0d623f7 894 /* There are no tests 2.2.5 or 2.2.6 */
6d2010ae 895
b0d623f7
A
896 init_test(&test, "2.2.7: rename a dir", DIR1, 1, 1, NOTE_WRITE, NO_EVENT);
897 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
898 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)DIR1, (void*)DIR2);
899 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR2, (void*)NULL);
900 execute_test(&test);
6d2010ae 901
b0d623f7
A
902 init_test(&test, "2.2.8: rename a fifo", FILE1, 1, 1, NOTE_WRITE, NO_EVENT);
903 test.t_file_is_fifo = 1;
904 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 2, (void*)FILE1, (void*)NULL);
905 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)FILE2);
906 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE2, (void*)NULL);
907 execute_test(&test);
908
909 init_test(&test, "2.2.9: unlink a fifo", FILE1, 1, 0, NOTE_WRITE, NO_EVENT);
910 test.t_file_is_fifo = 1;
911 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 2, (void*)FILE1, (void*)NULL);
912 init_action(&test.t_helpthreadact, SLEEP, UNLINK,1, (void*)FILE1);
913 execute_test(&test);
6d2010ae 914
b0d623f7
A
915 init_test(&test, "2.2.10: chmod a file", FILE1, 1, 1, NOTE_WRITE, NO_EVENT);
916 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
917 init_action(&test.t_helpthreadact, SLEEP, CHMOD, 2, (void*)FILE1, (void*)0700);
918 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
919 execute_test(&test);
6d2010ae 920
b0d623f7
A
921 struct passwd *pwd = getpwnam("local");
922 int uid = pwd->pw_uid;
923 int gid = pwd->pw_gid;
6d2010ae 924
b0d623f7
A
925 init_test(&test, "2.2.11: chown a file", FILE1, 2, 1, NOTE_WRITE, NO_EVENT);
926 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
927 init_action(&test.t_prep_actions[1], NOSLEEP, CHOWN, 3, (void*)FILE1, (void*)uid, (void*)gid);
928 init_action(&test.t_helpthreadact, SLEEP, CHOWN, 3, (void*)FILE1, (void*)getuid(), (void*)getgid());
929 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
930 execute_test(&test);
6d2010ae
A
931
932
b0d623f7
A
933 init_test(&test, "2.2.12: chmod a dir", DIR1, 1, 1, NOTE_WRITE, NO_EVENT);
934 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
935 init_action(&test.t_helpthreadact, SLEEP, CHMOD, 2, (void*)DIR1, (void*)0700);
936 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
937 execute_test(&test);
6d2010ae 938
b0d623f7
A
939 init_test(&test, "2.2.13: chown a dir", DIR1, 2, 1, NOTE_WRITE, NO_EVENT);
940 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
941 init_action(&test.t_prep_actions[1], NOSLEEP, CHOWN, 3, (void*)DIR1, (void*)uid, (void*)gid);
942 init_action(&test.t_helpthreadact, SLEEP, CHOWN, 3, (void*)DIR1, (void*)getuid(), (void*)getgid());
943 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
944 execute_test(&test);
6d2010ae
A
945
946
947
b0d623f7
A
948 LOG(1, stderr, "MMAP will never give a notification on HFS.\n");
949 init_test(&test, "2.1.14: mmap() a file but do not change it", FILE1, 1, 1, NOTE_WRITE, NO_EVENT);
950 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
951 init_action(&test.t_helpthreadact, SLEEP, MMAP, 2, (void*)FILE1, (void*)0);
952 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
953 execute_test(&test);
954}
955
956void
957run_note_extend_tests()
958{
959 test_t test;
960 char pathbuf[50];
6d2010ae 961
b0d623f7 962 LOG(1, stderr, "THESE TESTS WILL FAIL ON HFS!\n");
6d2010ae 963
b0d623f7
A
964 init_test(&test, "3.1.1: write beyond the end of a file", FILE1, 1, 1, NOTE_EXTEND, YES_EVENT);
965 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
966 init_action(&test.t_helpthreadact, SLEEP, WRITE, 2, (void*)FILE1, (void*)NULL);
967 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
968 execute_test(&test);
6d2010ae 969
b0d623f7
A
970 /*
971 * We won't concern ourselves with lengthening directories: commenting these out
972 *
6d2010ae 973
b0d623f7
A
974 makepath(pathbuf, DIR1, FILE1);
975 init_test(&test, "3.1.2: add a file to a directory with creat()", DIR1, 1, 2, NOTE_EXTEND, YES_EVENT);
976 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
977 init_action(&test.t_helpthreadact, SLEEP, CREAT, 2, (void*)pathbuf, (void*)NULL);
978 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
979 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
980 execute_test(&test);
6d2010ae 981
b0d623f7
A
982 makepath(pathbuf, DIR1, FILE1);
983 init_test(&test, "3.1.3: add a file to a directory with open()", DIR1, 1, 2, NOTE_EXTEND, YES_EVENT);
984 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
985 init_action(&test.t_helpthreadact, SLEEP, CREAT, 2, (void*)pathbuf, (void*)NULL);
986 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
987 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
988 execute_test(&test);
6d2010ae 989
b0d623f7
A
990 makepath(pathbuf, DIR1, FILE1);
991 init_test(&test, "3.1.4: add a file to a directory with rename()", DIR1, 2, 2, NOTE_EXTEND, YES_EVENT);
992 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
993 init_action(&(test.t_prep_actions[1]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
994 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)pathbuf);
995 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
996 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
997 execute_test(&test);
998 */
6d2010ae 999
b0d623f7
A
1000 /* 3.1.5: a placeholder for a potential kernel test */
1001 /*
6d2010ae
A
1002 makepath(pathbuf, DIR1, DIR2);
1003 init_test(&test, "3.1.6: add a file to a directory with mkdir()", DIR1, 1, 2, NOTE_EXTEND, YES_EVENT);
1004 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1005 init_action(&test.t_helpthreadact, SLEEP, MKDIR, 2, (void*)pathbuf, (void*)NULL);
1006 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)pathbuf, (void*)NULL);
1007 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1008 execute_test(&test);
1009 */
b0d623f7
A
1010 init_test(&test, "3.1.7: lengthen a file with truncate()", FILE1, 1, 1, NOTE_EXTEND, YES_EVENT);
1011 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1012 init_action(&test.t_helpthreadact, SLEEP, LENGTHEN, 2, FILE1, (void*)NULL);
1013 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1014 execute_test(&test);
6d2010ae
A
1015
1016
b0d623f7
A
1017 /** ========== NO EVENT SECTION ============== **/
1018 init_test(&test, "3.2.1: setxattr() a file", FILE1, 1, 1, NOTE_EXTEND, NO_EVENT);
1019 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1020 init_action(&test.t_helpthreadact, SLEEP, SETXATTR, 2, FILE1, (void*)NULL);
1021 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1022 execute_test(&test);
6d2010ae 1023
b0d623f7
A
1024 init_test(&test, "3.2.2: chmod a file", FILE1, 1, 1, NOTE_EXTEND, NO_EVENT);
1025 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1026 init_action(&test.t_helpthreadact, SLEEP, CHMOD, 2, (void*)FILE1, (void*)0700);
1027 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1028 execute_test(&test);
6d2010ae 1029
b0d623f7
A
1030 struct passwd *pwd = getpwnam("local");
1031 if (!pwd) {
1032 LOG(2, stderr, "Couldn't getpwnam for local.\n");
1033 exit(1);
1034 }
1035 int uid = pwd->pw_uid;
1036 int gid = pwd->pw_gid;
6d2010ae 1037
b0d623f7
A
1038 init_test(&test, "3.2.3: chown a file", FILE1, 2, 1, NOTE_EXTEND, NO_EVENT);
1039 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1040 init_action(&test.t_prep_actions[1], NOSLEEP, CHOWN, 3, (void*)FILE1, (void*)uid, (void*)gid);
1041 init_action(&test.t_helpthreadact, SLEEP, CHOWN, 3, (void*)FILE1, (void*)getuid(), (void*)getgid());
1042 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1043 execute_test(&test);
6d2010ae
A
1044
1045
b0d623f7
A
1046 init_test(&test, "3.2.4: chmod a dir", DIR1, 1, 1, NOTE_EXTEND, NO_EVENT);
1047 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1048 init_action(&test.t_helpthreadact, SLEEP, CHMOD, 2, (void*)DIR1, (void*)0700);
1049 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1050 execute_test(&test);
6d2010ae 1051
b0d623f7
A
1052 init_test(&test, "3.2.5: chown a dir", DIR1, 2, 1, NOTE_EXTEND, NO_EVENT);
1053 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1054 init_action(&test.t_prep_actions[1], NOSLEEP, CHOWN, 3, (void*)DIR1, (void*)uid, (void*)gid);
1055 init_action(&test.t_helpthreadact, SLEEP, CHOWN, 3, (void*)DIR1, (void*)getuid(), (void*)getgid());
1056 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1057 execute_test(&test);
6d2010ae 1058
b0d623f7
A
1059 init_test(&test, "3.2.6: TRUNC a file with truncate()", FILE1, 1, 1, NOTE_EXTEND, NO_EVENT);
1060 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1061 init_action(&test.t_helpthreadact, SLEEP, TRUNC, 2, FILE1, (void*)NULL);
1062 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1063 execute_test(&test);
1064}
1065
1066void
1067run_note_attrib_tests()
1068{
1069 test_t test;
1070 char pathbuf[50];
6d2010ae 1071
b0d623f7
A
1072 init_test(&test, "4.1.1: chmod a file", FILE1, 1, 1, NOTE_ATTRIB, YES_EVENT);
1073 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1074 init_action(&test.t_helpthreadact, SLEEP, CHMOD, 2, FILE1, (void*)0700);
1075 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1076 execute_test(&test);
6d2010ae 1077
b0d623f7
A
1078 struct passwd *pwd = getpwnam("local");
1079 int uid = pwd->pw_uid;
1080 int gid = pwd->pw_gid;
6d2010ae 1081
b0d623f7
A
1082 init_test(&test, "4.1.2: chown a file", FILE1, 2, 1, NOTE_ATTRIB, YES_EVENT);
1083 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1084 init_action(&(test.t_prep_actions[1]), NOSLEEP, CHOWN, 3, (void*)FILE1, (void*)uid, (void*)gid);
1085 init_action(&test.t_helpthreadact, SLEEP, CHOWN, 3, FILE1, (void*)getuid(), (void*)gid);
1086 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1087 execute_test(&test);
6d2010ae 1088
b0d623f7
A
1089 init_test(&test, "4.1.3: chmod a dir", DIR1, 1, 1, NOTE_ATTRIB, YES_EVENT);
1090 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1091 init_action(&(test.t_helpthreadact), SLEEP, CHMOD, 2, (void*)DIR1, (void*)0700);
1092 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1093 execute_test(&test);
6d2010ae 1094
b0d623f7
A
1095 init_test(&test, "4.1.4: chown a dir", DIR1, 2, 1, NOTE_ATTRIB, YES_EVENT);
1096 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1097 init_action(&(test.t_prep_actions[1]), NOSLEEP, CHOWN, 3, (void*)DIR1, (void*) uid, (void*)gid);
1098 init_action(&test.t_helpthreadact, SLEEP, CHOWN, 3, DIR1, (void*)getuid(), (void*)getgid());
1099 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1100 execute_test(&test);
6d2010ae 1101
b0d623f7
A
1102 init_test(&test, "4.1.5: setxattr on a file", FILE1, 1, 1, NOTE_ATTRIB, YES_EVENT);
1103 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1104 init_action(&test.t_helpthreadact, SLEEP, SETXATTR, 2, (void*)FILE1, (void*)NULL);
1105 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1106 execute_test(&test);
6d2010ae 1107
b0d623f7
A
1108 init_test(&test, "4.1.6: setxattr on a dir", DIR1, 1, 1, NOTE_ATTRIB, YES_EVENT);
1109 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1110 init_action(&test.t_helpthreadact, SLEEP, SETXATTR, 2, (void*)DIR1, (void*)NULL);
1111 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1112 execute_test(&test);
6d2010ae
A
1113
1114
b0d623f7
A
1115 init_test(&test, "4.1.7: exchangedata", FILE1, 2, 2, NOTE_ATTRIB, YES_EVENT);
1116 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1117 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)FILE2, (void*)NULL);
1118 init_action(&test.t_helpthreadact, SLEEP, EXCHANGEDATA, 2, (void*)FILE1, (void*)FILE2);
1119 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1120 init_action(&test.t_cleanup_actions[1], NOSLEEP, UNLINK, 2, (void*)FILE2, (void*)NULL);
1121 execute_test(&test);
6d2010ae
A
1122
1123
b0d623f7
A
1124 init_test(&test, "4.1.8: utimes on a file", FILE1, 1, 1, NOTE_ATTRIB, YES_EVENT);
1125 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1126 init_action(&test.t_helpthreadact, SLEEP, UTIMES, 2, (void*)FILE1, (void*)NULL);
1127 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1128 execute_test(&test);
6d2010ae 1129
b0d623f7
A
1130 init_test(&test, "4.1.9: utimes on a dir", DIR1, 1, 1, NOTE_ATTRIB, YES_EVENT);
1131 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1132 init_action(&test.t_helpthreadact, SLEEP, UTIMES, 2, (void*)DIR1, (void*)NULL);
1133 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1134 execute_test(&test);
6d2010ae
A
1135
1136
b0d623f7 1137 /* ====== NO EVENT TESTS ========== */
6d2010ae 1138
b0d623f7
A
1139 init_test(&test, "4.2.1: rename a file", FILE1, 1, 1, NOTE_ATTRIB, NO_EVENT);
1140 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1141 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)FILE2);
1142 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE2, NULL);
1143 execute_test(&test);
6d2010ae 1144
b0d623f7
A
1145 init_test(&test, "4.2.2: open (do not change) a file", FILE1, 1, 1, NOTE_ATTRIB, NO_EVENT);
1146 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1147 init_action(&test.t_helpthreadact, SLEEP, OPEN, 2, (void*)FILE1, NULL);
1148 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1149 execute_test(&test);
6d2010ae 1150
b0d623f7
A
1151 init_test(&test, "4.2.3: stat a file", FILE1, 1, 1, NOTE_ATTRIB, NO_EVENT);
1152 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1153 init_action(&test.t_helpthreadact, SLEEP, STAT, 2, (void*)FILE1, NULL);
1154 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1155 execute_test(&test);
6d2010ae 1156
b0d623f7
A
1157 init_test(&test, "4.2.4: unlink a file", FILE1, 1, 0, NOTE_ATTRIB, NO_EVENT);
1158 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1159 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 2, (void*)FILE1, NULL);
1160 execute_test(&test);
6d2010ae 1161
b0d623f7
A
1162 init_test(&test, "4.2.5: write to a file", FILE1, 1, 1, NOTE_ATTRIB, NO_EVENT);
1163 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1164 init_action(&test.t_helpthreadact, SLEEP, WRITE, 2, (void*)FILE1, (void*)NULL);
1165 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1166 execute_test(&test);
6d2010ae 1167
b0d623f7
A
1168 LOG(1, stderr, "EXPECT SPURIOUS NOTE_ATTRIB EVENTS FROM DIRECTORY OPERATIONS on HFS.\n");
1169 init_test(&test, "4.2.6: add a file to a directory with creat()", DIR1, 1, 2, NOTE_ATTRIB, NO_EVENT);
1170 makepath(pathbuf, DIR1, FILE1);
1171 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1172 init_action(&test.t_helpthreadact, SLEEP, CREAT, 2, (void*)pathbuf, (void*)NULL);
1173 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
1174 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1175 execute_test(&test);
6d2010ae 1176
b0d623f7
A
1177 init_test(&test, "4.2.7: mkdir in a dir", DIR1, 1, 2, NOTE_ATTRIB, NO_EVENT);
1178 makepath(pathbuf, DIR1, DIR2);
1179 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1180 init_action(&test.t_helpthreadact, SLEEP, MKDIR, 2, (void*)pathbuf, (void*)NULL);
1181 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)pathbuf, (void*)NULL);
1182 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1183 execute_test(&test);
6d2010ae 1184
b0d623f7
A
1185 init_test(&test, "4.2.8: add a symlink to a directory", DIR1, 1, 2, NOTE_ATTRIB, NO_EVENT);
1186 makepath(pathbuf, DIR1, FILE1);
1187 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1188 init_action(&test.t_helpthreadact, SLEEP, SYMLINK, 2, (void*)DOTDOT, (void*)pathbuf);
1189 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
1190 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1191 execute_test(&test);
6d2010ae 1192
b0d623f7
A
1193 init_test(&test, "4.2.9: rename into a dir()", DIR1, 2, 2, NOTE_ATTRIB, NO_EVENT);
1194 makepath(pathbuf, DIR1, FILE1);
1195 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1196 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1197 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)pathbuf);
1198 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
1199 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1200 execute_test(&test);
6d2010ae 1201
b0d623f7
A
1202 init_test(&test, "4.2.10: unlink() file from dir", DIR1, 2, 1, NOTE_ATTRIB, NO_EVENT);
1203 makepath(pathbuf, DIR1, FILE1);
1204 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1205 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)pathbuf, (void*)NULL);
1206 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
1207 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1208 execute_test(&test);
6d2010ae 1209
b0d623f7
A
1210 init_test(&test, "4.2.11: mkfifo in a directory", DIR1, 1, 2, NOTE_ATTRIB, NO_EVENT);
1211 makepath(pathbuf, DIR1, FILE1);
1212 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1213 init_action(&test.t_helpthreadact, SLEEP, MKFIFO, 1, (void*)pathbuf);
1214 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
1215 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1216 execute_test(&test);
6d2010ae
A
1217
1218
b0d623f7
A
1219}
1220
1221
1222void
1223run_note_link_tests()
1224{
1225 test_t test;
1226 char pathbuf[50];
1227 char otherpathbuf[50];
6d2010ae 1228
b0d623f7
A
1229 LOG(1, stderr, "HFS DOES NOT HANDLE UNLINK CORRECTLY...\n");
1230 init_test(&test, "5.1.1: unlink() a file", FILE1, 1, 0, NOTE_LINK, YES_EVENT);
1231 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1232 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 2, (void*)FILE1, (void*)NULL);
1233 execute_test(&test);
6d2010ae
A
1234
1235
b0d623f7
A
1236 init_test(&test, "5.1.1.5: link A to B, watch A, remove B", FILE1, 2, 1, NOTE_LINK, YES_EVENT);
1237 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1238 init_action(&(test.t_prep_actions[1]), NOSLEEP, HARDLINK, 2, (void*)FILE1, (void*)FILE2);
1239 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 2, (void*)FILE2, (void*)NULL);
1240 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1241 execute_test(&test);
6d2010ae 1242
b0d623f7
A
1243 init_test(&test, "5.1.2: link() to a file", FILE1, 1, 2, NOTE_LINK, YES_EVENT);
1244 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1245 init_action(&test.t_helpthreadact, SLEEP, HARDLINK, 2, (void*)FILE1, (void*)FILE2);
1246 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1247 init_action(&test.t_cleanup_actions[1], NOSLEEP, UNLINK, 2, (void*)FILE2, NULL);
1248 execute_test(&test);
6d2010ae 1249
b0d623f7
A
1250 makepath(pathbuf, DIR1, DIR2);
1251 init_test(&test, "5.1.3: make one dir in another", DIR1, 1, 2, NOTE_LINK, YES_EVENT);
1252 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1253 init_action(&test.t_helpthreadact, SLEEP, MKDIR, 2, (void*)pathbuf, (void*)NULL);
1254 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)pathbuf, NULL);
1255 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1256 execute_test(&test);
6d2010ae 1257
b0d623f7
A
1258 makepath(pathbuf, DIR1, DIR2);
1259 init_test(&test, "5.1.4: rmdir a dir from within another", DIR1, 2, 1, NOTE_LINK, YES_EVENT);
1260 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1261 init_action(&(test.t_prep_actions[1]), NOSLEEP, MKDIR, 2, (void*)pathbuf, (void*)NULL);
1262 init_action(&test.t_helpthreadact, SLEEP, RMDIR, 2, (void*)pathbuf, (void*)NULL);
1263 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1264 execute_test(&test);
6d2010ae 1265
b0d623f7
A
1266 makepath(pathbuf, DIR1, DIR2);
1267 makepath(otherpathbuf, DIR1, DIR1);
1268 init_test(&test, "5.1.5: rename dir A over dir B inside dir C", DIR1, 3, 2, NOTE_LINK, YES_EVENT);
1269 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1270 init_action(&(test.t_prep_actions[1]), NOSLEEP, MKDIR, 2, (void*)pathbuf, (void*)NULL);
1271 init_action(&(test.t_prep_actions[2]), NOSLEEP, MKDIR, 2, (void*)otherpathbuf, (void*)NULL);
1272 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)pathbuf, (void*)otherpathbuf);
1273 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)otherpathbuf, NULL);
1274 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1275 execute_test(&test);
6d2010ae 1276
b0d623f7
A
1277 LOG(1, stderr, "HFS bypasses hfs_makenode to create in target, so misses knote.\n");
1278 makepath(pathbuf, DIR1, DIR2);
1279 init_test(&test, "5.1.6: rename one dir into another", DIR1, 2, 2, NOTE_LINK, YES_EVENT);
1280 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1281 init_action(&(test.t_prep_actions[1]), NOSLEEP, MKDIR, 2, (void*)DIR2, (void*)NULL);
1282 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)DIR2, (void*)pathbuf);
1283 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)pathbuf, NULL);
1284 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1285 execute_test(&test);
6d2010ae 1286
b0d623f7
A
1287 LOG(1, stderr, "HFS bypasses hfs_removedir to remove from source, so misses knote.\n");
1288 makepath(pathbuf, DIR1, DIR2);
1289 init_test(&test, "5.1.7: rename one dir out of another", DIR1, 2, 2, NOTE_LINK, YES_EVENT);
1290 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1291 init_action(&(test.t_prep_actions[1]), NOSLEEP, MKDIR, 2, (void*)pathbuf, (void*)NULL);
1292 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)pathbuf, (void*)DIR2);
1293 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR2, NULL);
1294 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1295 execute_test(&test);
6d2010ae 1296
b0d623f7
A
1297 init_test(&test, "5.1.8: rmdir a dir", DIR1, 1, 0, NOTE_LINK, YES_EVENT);
1298 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1299 init_action(&test.t_helpthreadact, SLEEP, RMDIR, 2, (void*)DIR1, (void*)NULL);
1300 execute_test(&test);
6d2010ae 1301
b0d623f7
A
1302 /* ============= NO EVENT SECTION ============== */
1303 makepath(pathbuf, DIR1, FILE1);
1304 init_test(&test, "5.2.1: make a file in a dir", DIR1, 1, 2, NOTE_LINK, NO_EVENT);
1305 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1306 init_action(&test.t_helpthreadact, SLEEP, CREAT, 2, (void*)pathbuf, (void*)NULL);
1307 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, NULL);
1308 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1309 execute_test(&test);
6d2010ae 1310
b0d623f7
A
1311 makepath(pathbuf, DIR1, FILE1);
1312 init_test(&test, "5.2.2: unlink a file in a dir", DIR1, 2, 1, NOTE_LINK, NO_EVENT);
1313 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1314 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)pathbuf, (void*)NULL);
1315 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 2, (void*)pathbuf, (void*)NULL);
1316 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1317 execute_test(&test);
6d2010ae 1318
b0d623f7
A
1319 makepath(pathbuf, DIR1, FILE1);
1320 makepath(otherpathbuf, DIR1, FILE2);
1321 init_test(&test, "5.2.3: rename a file within a dir", DIR1, 2, 2, NOTE_LINK, NO_EVENT);
1322 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1323 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)pathbuf, (void*)NULL);
1324 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)pathbuf, (void*)otherpathbuf);
1325 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)otherpathbuf, NULL);
1326 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1327 execute_test(&test);
6d2010ae 1328
b0d623f7
A
1329 makepath(pathbuf, DIR1, FILE1);
1330 init_test(&test, "5.2.4: rename a file into a dir", DIR1, 2, 2, NOTE_LINK, NO_EVENT);
1331 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1332 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1333 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)pathbuf);
1334 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, NULL);
1335 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1336 execute_test(&test);
6d2010ae 1337
b0d623f7
A
1338 makepath(pathbuf, DIR1, FILE1);
1339 init_test(&test, "5.2.5: make a symlink in a dir", DIR1, 1, 2, NOTE_LINK, NO_EVENT);
1340 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1341 init_action(&test.t_helpthreadact, SLEEP, SYMLINK, 2, (void*)DOTDOT, (void*)pathbuf);
1342 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)pathbuf, NULL);
1343 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1344 execute_test(&test);
6d2010ae 1345
b0d623f7
A
1346 init_test(&test, "5.2.6: make a symlink to a dir", DIR1, 1, 2, NOTE_LINK, NO_EVENT);
1347 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1348 init_action(&test.t_helpthreadact, SLEEP, SYMLINK, 2, (void*)DIR1, (void*)FILE1);
1349 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1350 init_action(&test.t_cleanup_actions[1], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1351 execute_test(&test);
6d2010ae 1352
b0d623f7
A
1353 init_test(&test, "5.2.7: make a symlink to a file", FILE1, 1, 2, NOTE_LINK, NO_EVENT);
1354 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1355 init_action(&test.t_helpthreadact, SLEEP, SYMLINK, 2, (void*)FILE1, (void*)FILE2);
1356 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE2, NULL);
1357 init_action(&test.t_cleanup_actions[1], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1358 execute_test(&test);
1359}
1360
1361void
1362run_note_rename_tests()
1363{
1364 test_t test;
6d2010ae 1365
b0d623f7
A
1366 init_test(&test, "6.1.1: rename a file", FILE1, 1, 1, NOTE_RENAME, YES_EVENT);
1367 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1368 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)FILE2);
1369 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE2, NULL);
1370 execute_test(&test);
6d2010ae 1371
b0d623f7
A
1372 init_test(&test, "6.1.2: rename a dir", DIR1, 1, 1, NOTE_RENAME, YES_EVENT);
1373 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1374 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)DIR1, (void*)DIR2);
1375 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR2, NULL);
1376 execute_test(&test);
6d2010ae 1377
b0d623f7
A
1378 init_test(&test, "6.1.2: rename one file over another", FILE1, 2, 1, NOTE_RENAME, YES_EVENT);
1379 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1380 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)FILE2, (void*)NULL);
1381 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)FILE2);
1382 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE2, NULL);
1383 execute_test(&test);
6d2010ae 1384
b0d623f7
A
1385 init_test(&test, "6.1.3: rename one dir over another", DIR1, 2, 1, NOTE_RENAME, YES_EVENT);
1386 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1387 init_action(&(test.t_prep_actions[1]), NOSLEEP, MKDIR, 2, (void*)DIR2, (void*)NULL);
1388 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)DIR1, (void*)DIR2);
1389 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR2, NULL);
1390 execute_test(&test);
6d2010ae 1391
b0d623f7 1392 /* ========= NO EVENT SECTION =========== */
6d2010ae 1393
b0d623f7
A
1394 init_test(&test, "6.2.1: unlink a file", FILE1, 1, 0, NOTE_RENAME, NO_EVENT);
1395 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1396 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 2, (void*)FILE1, NULL);
1397 execute_test(&test);
6d2010ae 1398
b0d623f7
A
1399 init_test(&test, "6.2.2: rmdir a dir", DIR1, 1, 0, NOTE_RENAME, NO_EVENT);
1400 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1401 init_action(&test.t_helpthreadact, SLEEP, RMDIR, 2, (void*)DIR1, NULL);
1402 execute_test(&test);
6d2010ae 1403
b0d623f7
A
1404 init_test(&test, "6.2.3: link() to a file", FILE1, 1, 2, NOTE_RENAME, NO_EVENT);
1405 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1406 init_action(&test.t_helpthreadact, SLEEP, HARDLINK, 2, (void*)FILE1, (void*)FILE2);
1407 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1408 init_action(&test.t_cleanup_actions[1], NOSLEEP, UNLINK, 2, (void*)FILE2, NULL);
1409 execute_test(&test);
6d2010ae 1410
b0d623f7 1411 init_test(&test, "6.2.4: rename one file over another: watch deceased",
6d2010ae 1412 FILE2, 2, 1, NOTE_RENAME, NO_EVENT);
b0d623f7
A
1413 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1414 init_action(&(test.t_prep_actions[1]), NOSLEEP, CREAT, 2, (void*)FILE2, (void*)NULL);
1415 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)FILE2);
1416 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE2, NULL);
1417 execute_test(&test);
6d2010ae 1418
b0d623f7 1419 init_test(&test, "6.2.5: rename one dir over another: watch deceased",
6d2010ae 1420 DIR2, 2, 1, NOTE_RENAME, NO_EVENT);
b0d623f7
A
1421 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1422 init_action(&(test.t_prep_actions[1]), NOSLEEP, MKDIR, 2, (void*)DIR2, (void*)NULL);
1423 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)DIR1, (void*)DIR2);
1424 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR2, NULL);
1425 execute_test(&test);
6d2010ae 1426
b0d623f7
A
1427 init_test(&test, "6.2.6: rename a file to itself", FILE1, 1, 1, NOTE_RENAME, NO_EVENT);
1428 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1429 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)FILE1);
1430 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1431 execute_test(&test);
6d2010ae 1432
b0d623f7
A
1433 init_test(&test, "6.2.7: rename a dir to itself", DIR1, 1, 1, NOTE_RENAME, NO_EVENT);
1434 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKDIR, 2, (void*)DIR1, (void*)NULL);
1435 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)DIR1, (void*)DIR1);
1436 init_action(&test.t_cleanup_actions[0], NOSLEEP, RMDIR, 2, (void*)DIR1, NULL);
1437 execute_test(&test);
1438}
1439
1440void
1441run_note_revoke_tests()
1442{
1443 test_t test;
1444 init_test(&test, "7.1.1: revoke file", FILE1, 1, 1, NOTE_REVOKE, YES_EVENT);
1445 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1);
1446 init_action(&test.t_helpthreadact, SLEEP, REVOKE, 1, (void*)FILE1);
1447 init_action(&(test.t_cleanup_actions[0]), NOSLEEP, UNLINK, 1, (void*)FILE1);
1448 execute_test(&test);
6d2010ae 1449
b0d623f7
A
1450 init_test(&test, "7.2.1: delete file", FILE1, 1, 0, NOTE_REVOKE, NO_EVENT);
1451 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1);
1452 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 1, (void*)FILE1);
1453 execute_test(&test);
1454}
1455
1456
1457void
1458run_evfilt_read_tests()
1459{
1460 test_t test;
1461 init_test(&test, "8.1.1: how much data in file of length LENGTHEN_SIZE?", FILE1, 2, 1, EVFILT_READ, LENGTHEN_SIZE);
1462 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void*)NULL);
1463 init_action(&(test.t_prep_actions[1]), NOSLEEP, LENGTHEN, 2, (void*)FILE1, (void*)NULL);
1464 init_action(&test.t_helpthreadact, SLEEP, NOTHING, 0);
1465 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1466 execute_test(&test);
6d2010ae 1467
b0d623f7
A
1468 init_test(&test, "8.1.2: block, then write to file", FILE1, 2, 1, EVFILT_READ, strlen(TEST_STRING));
1469 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1);
1470 init_action(&(test.t_prep_actions[1]), NOSLEEP, TRUNC, 1, (void*)FILE1);
1471 init_action(&test.t_helpthreadact, SLEEP, WRITE, 1, (void*)FILE1);
1472 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1473 execute_test(&test);
1474
1475 init_test(&test, "8.1.3: block, then extend", FILE1, 2, 1, EVFILT_READ, LENGTHEN_SIZE);
1476 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1);
1477 init_action(&(test.t_prep_actions[1]), NOSLEEP, TRUNC, 1, (void*)FILE1);
1478 init_action(&test.t_helpthreadact, SLEEP, LENGTHEN, 1, (void*)FILE1);
1479 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1480 execute_test(&test);
6d2010ae 1481
b0d623f7
A
1482 init_test(&test, "8.1.4: block, then seek to beginning", FILE1, 2, 1, EVFILT_READ, strlen(TEST_STRING));
1483 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1);
1484 init_action(&(test.t_prep_actions[1]), NOSLEEP, WRITE, 1, (void*)FILE1);
1485 test.t_read_to_end_first = 1; /* hack means that we've gotten to EOF before we block */
1486 init_action(&test.t_helpthreadact, SLEEP, LSEEK, 1, (void*)0);
1487 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1488 execute_test(&test);
1489
6d2010ae 1490
b0d623f7
A
1491 init_test(&test, "8.1.5: block, then write to fifo", FILE1, 1, 1, EVFILT_READ, strlen(TEST_STRING));
1492 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 1, (void*)FILE1);
1493 test.t_file_is_fifo = 1;
1494 init_action(&test.t_helpthreadact, SLEEP, WRITE, 1, (void*)FILE1);
1495 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1496 execute_test(&test);
6d2010ae 1497
b0d623f7
A
1498 /* No result section... */
1499 init_test(&test, "8.2.1: just rename", FILE1, 2, 1, EVFILT_READ, NO_EVENT);
1500 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1);
1501 init_action(&(test.t_prep_actions[1]), NOSLEEP, TRUNC, 1, (void*)FILE1);
1502 init_action(&test.t_helpthreadact, SLEEP, RENAME, 2, (void*)FILE1, (void*)FILE2);
1503 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE2, NULL);
1504 execute_test(&test);
6d2010ae 1505
b0d623f7
A
1506 init_test(&test, "8.2.2: delete file", FILE1, 2, 0, EVFILT_READ, NO_EVENT);
1507 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1);
1508 init_action(&(test.t_prep_actions[1]), NOSLEEP, TRUNC, 1, (void*)FILE1);
1509 init_action(&test.t_helpthreadact, SLEEP, UNLINK, 1, (void*)FILE1);
1510 execute_test(&test);
6d2010ae 1511
b0d623f7
A
1512 init_test(&test, "8.2.3: write to beginning", FILE1, 2, 1, EVFILT_READ, NO_EVENT);
1513 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1);
1514 init_action(&(test.t_prep_actions[1]), NOSLEEP, WRITE, 1, (void*)FILE1);
1515 test.t_read_to_end_first = 1; /* hack means that we've gotten to EOF before we block */
1516 init_action(&test.t_helpthreadact, SLEEP, WRITE, 1, (void*)FILE1);
1517 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 1, (void*)FILE1);
1518 execute_test(&test);
1519
1520 init_test(&test, "8.1.4: block, then seek to current location", FILE1, 2, 1, EVFILT_READ, 0);
1521 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1);
1522 init_action(&(test.t_prep_actions[1]), NOSLEEP, WRITE, 1, (void*)FILE1);
1523 test.t_read_to_end_first = 1; /* hack means that we've gotten to EOF before we block */
1524 init_action(&test.t_helpthreadact, SLEEP, LSEEK, 1, (void*)strlen(TEST_STRING));
1525 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1526 execute_test(&test);
6d2010ae 1527
b0d623f7
A
1528 init_test(&test, "8.2.5: trying to read from empty fifo", FILE1, 1, 1, EVFILT_READ, 0);
1529 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 1, (void*)FILE1);
1530 test.t_file_is_fifo = 1;
1531 init_action(&test.t_helpthreadact, SLEEP, NOTHING, 1, (void*)0);
1532 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1533 execute_test(&test);
6d2010ae 1534
b0d623f7
A
1535}
1536
1537
1538
1539void*
1540read_from_fd(void *arg)
1541{
1542 char buf[50];
1543 int fd = (int) arg;
1544 sleep(2);
1545 return (void*) read(fd, buf, sizeof(buf));
1546}
1547
1548void*
1549write_to_fd(void *arg)
1550{
1551 char buf[50];
1552 int fd = (int) arg;
1553 sleep(2);
1554 return (void*) write(fd, buf, sizeof(buf));
1555}
1556
1557/*
1558 * We don't (in principle) support EVFILT_WRITE for vnodes; thusly, no tests here
1559 */
1560void
1561run_evfilt_write_tests()
1562{
6d2010ae 1563
b0d623f7
A
1564 test_t test;
1565 init_test(&test, "9.1.1: how much space in empty fifo?", FILE1, 1, 1, EVFILT_WRITE, FIFO_SPACE);
1566 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 1, (void*)FILE1, (void*)NULL);
1567 test.t_file_is_fifo = 1;
1568 init_action(&test.t_helpthreadact, SLEEP, NOTHING, 0);
1569 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1570 execute_test(&test);
1571
1572 init_test(&test, "9.1.2: how much space in slightly written fifo?", FILE1, 1, 1, EVFILT_WRITE, FIFO_SPACE - strlen(TEST_STRING));
1573 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 1, (void*)FILE1, (void*)NULL);
1574 test.t_file_is_fifo = 1;
1575 test.t_write_some_data = 1;
1576 init_action(&(test.t_helpthreadact), NOSLEEP, NOTHING, 0);
1577 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1578 execute_test(&test);
6d2010ae 1579
b0d623f7
A
1580 init_test(&test, "9.2.1: how much space in a full fifo?", FILE1, 1, 1, EVFILT_WRITE, 0);
1581 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 1, (void*)FILE1, (void*)NULL);
1582 test.t_file_is_fifo = 1;
1583 test.t_extra_sleep_hack = 1;
1584 init_action(&(test.t_helpthreadact), NOSLEEP, FILLFD, 1, (void*)FILE1, (void*)NULL);
1585 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1586 execute_test(&test);
1587}
1588
1589void
1590run_poll_tests()
1591{
1592 test_t test;
1593 init_poll_test(&test, "10.1.1: does poll say I can write a regular file?", FILE1, 1, 1, POLLWRNORM, 1);
1594 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1, (void*)NULL);
1595 init_action(&test.t_helpthreadact, SLEEP, NOTHING, 0);
1596 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1597 execute_test(&test);
1598
1599 init_poll_test(&test, "10.1.2: does poll say I can write an empty FIFO?", FILE1, 1, 1, POLLWRNORM, 1);
1600 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 1, (void*)FILE1, (void*)NULL);
1601 test.t_file_is_fifo = 1;
1602 init_action(&test.t_helpthreadact, SLEEP, NOTHING, 0);
1603 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1604 execute_test(&test);
1605
1606 init_poll_test(&test, "10.1.3: does poll say I can read a nonempty FIFO?", FILE1, 1, 1, POLLRDNORM, 1);
1607 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 1, (void*)FILE1, (void*)NULL);
1608 test.t_file_is_fifo = 1;
1609 test.t_write_some_data = 1;
1610 init_action(&test.t_helpthreadact, SLEEP, NOTHING, 0);
1611 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1612 execute_test(&test);
6d2010ae 1613
b0d623f7
A
1614 init_poll_test(&test, "10.1.4: does poll say I can read a nonempty regular file?", FILE1, 2, 1, POLLRDNORM, 1);
1615 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1, (void*)NULL);
1616 init_action(&(test.t_prep_actions[1]), NOSLEEP, LENGTHEN, 1, (void*)FILE1, (void*)NULL);
1617 init_action(&test.t_helpthreadact, SLEEP, NOTHING, 0);
1618 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1619 execute_test(&test);
6d2010ae 1620
b0d623f7
A
1621 init_poll_test(&test, "10.1.5: does poll say I can read an empty file?", FILE1, 1, 1, POLLRDNORM, 1);
1622 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 1, (void*)FILE1, (void*)NULL);
1623 init_action(&test.t_helpthreadact, SLEEP, NOTHING, 0);
1624 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1625 execute_test(&test);
6d2010ae
A
1626
1627
1628
1629
b0d623f7
A
1630 init_poll_test(&test, "10.2.2: does poll say I can read an empty FIFO?", FILE1, 1, 1, POLLRDNORM, 0);
1631 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 1, (void*)FILE1, (void*)NULL);
1632 test.t_file_is_fifo = 1;
1633 init_action(&test.t_helpthreadact, SLEEP, NOTHING, 0);
1634 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1635 execute_test(&test);
1636
1637 init_poll_test(&test, "10.2.3: does poll say I can write a full FIFO?", FILE1, 1, 1, POLLWRNORM, 0);
1638 init_action(&(test.t_prep_actions[0]), NOSLEEP, MKFIFO, 1, (void*)FILE1, (void*)NULL);
1639 test.t_file_is_fifo = 1;
1640 test.t_extra_sleep_hack = 1;
1641 init_action(&(test.t_helpthreadact), NOSLEEP, FILLFD, 1, (void*)FILE1, (void*)NULL);
1642 init_action(&test.t_cleanup_actions[0], NOSLEEP, UNLINK, 2, (void*)FILE1, NULL);
1643 execute_test(&test);
1644}
1645
39037602
A
1646void
1647run_note_funlock_tests()
1648{
1649 test_t test;
1650 init_test(&test, "11.1.1: unlock file", FILE1, 1, 1, NOTE_FUNLOCK, YES_EVENT);
1651 init_action(&(test.t_prep_actions[0]), NOSLEEP, CREAT, 2, (void*)FILE1, (void *)NULL);
1652 init_action(&test.t_helpthreadact, SLEEP, FUNLOCK, 2, (void*)FILE1, (void *)NULL);
1653 init_action(&(test.t_cleanup_actions[0]), NOSLEEP, UNLINK, 2, (void*)FILE1, (void *)NULL);
1654 execute_test(&test);
1655}
1656
1657void
b0d623f7
A
1658run_all_tests()
1659{
1660 run_note_delete_tests();
1661 run_note_write_tests();
1662 run_note_extend_tests();
1663 run_note_attrib_tests();
1664 run_note_link_tests();
1665 run_note_rename_tests();
1666#if 0
1667 run_note_revoke_tests(); /* Can no longer revoke a regular file--need an unmount test */
1668#endif /* 0 */
1669 run_evfilt_read_tests();
1670 run_evfilt_write_tests();
1671 run_poll_tests();
39037602 1672 run_note_funlock_tests();
b0d623f7
A
1673}
1674
6d2010ae 1675int
b0d623f7
A
1676main(int argc, char **argv)
1677{
1678 char *which = NULL;
1679 if (argc > 1) {
1680 which = argv[1];
1681 }
6d2010ae 1682
b0d623f7
A
1683 if ((!which) || (strcmp(which, "all") == 0))
1684 run_all_tests();
1685 else if (strcmp(which, "delete") == 0)
1686 run_note_delete_tests();
1687 else if (strcmp(which, "write") == 0)
1688 run_note_write_tests();
1689 else if (strcmp(which, "extend") == 0)
1690 run_note_extend_tests();
1691 else if (strcmp(which, "attrib") == 0)
1692 run_note_attrib_tests();
1693 else if (strcmp(which, "link") == 0)
1694 run_note_link_tests();
1695 else if (strcmp(which, "rename") == 0)
1696 run_note_rename_tests();
1697 else if (strcmp(which, "revoke") == 0)
1698 run_note_revoke_tests();
1699 else if (strcmp(which, "evfiltread") == 0)
1700 run_evfilt_read_tests();
1701 else if (strcmp(which, "evfiltwrite") == 0)
1702 run_evfilt_write_tests();
1703 else if (strcmp(which, "poll") == 0)
1704 run_poll_tests();
39037602
A
1705 else if (strcmp(which, "funlock") == 0)
1706 run_note_funlock_tests();
b0d623f7 1707 else {
39037602
A
1708 fprintf(stderr, "Valid options are:\n\tdelete, write, extend, "
1709 "attrib, link, rename, revoke, evfiltread, "
1710 "fifo, all, evfiltwrite, funlock<none>\n");
b0d623f7
A
1711 exit(1);
1712 }
1713 return 0;
1714}
1715