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