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