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