xref: /freebsd/tools/regression/doat/doat.c (revision c6ec7d31830ab1c80edae95ad5e4b9dba10c47ac)
1 /*-
2  * Copyright (c) 2007 Roman Divacky
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #include <sys/types.h>
30 #include <sys/syscall.h>
31 #include <sys/stat.h>
32 
33 #include <errno.h>
34 #include <fcntl.h>
35 #include <stdbool.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <unistd.h>
40 
41 void cleanup(void);
42 void setup(void);
43 void setup_once(void);
44 
45 union param {
46 	int		i;
47 	const char	*cp;
48 	mode_t		m;
49 	dev_t		d;
50 	void		*vp;
51 	uid_t		u;
52 	gid_t		g;
53 	const char	**cpp;
54 };
55 
56 struct testcase {
57 	int		result;
58 	union param	params[5];	/* no *at syscall with more than 5 params */
59 };
60 
61 struct test {
62 	int	syscall;
63 	int	num_of_cases;
64 	const char *name;
65 	struct testcase	tests[10];	/* no more than 10 tests */
66 
67 };
68 
69 struct test *tests;
70 #define	NUM_OF_TESTS	14		/* we dont want the fexecve test to run */
71 
72 char *absolute_path = NULL;
73 const char *relative_path = "tmp/";
74 const char *not_dir_path = "/bin/date";
75 
76 const char *file = "foo";
77 char *absolute_file = NULL;
78 char *relative_file = NULL;
79 const char *symlinkf = "link";
80 const char *newlink = "nlink1";
81 const char *newlink2 = "nlink2";
82 const char *newlink3 = "nlink3";
83 const char *newdir = "newdir";
84 const char *fifo = "fifo";
85 const char *nod = "nod";
86 const char *newfile = "newfile";
87 const char *newslink = "nslink1";
88 
89 bool dir_exist = false;
90 bool file_exist = false;
91 bool link_exist = false;
92 
93 int rel_fd, abs_fd, notd_fd, exec_fd;
94 
95 struct timeval times[2];
96 struct stat buf;
97 const char *pargv[2] = { "/bin/date", NULL };
98 #define	PATH_MAX	1024
99 char cbuf[PATH_MAX];
100 
101 void
102 setup(void)
103 {
104 	int i, error;
105 	struct stat sb;
106 	size_t len;
107 
108 	tests = calloc(NUM_OF_TESTS + 1, sizeof(struct test));
109 	if (tests == NULL) {
110 		perror("");
111 		exit(0);
112 	}
113 
114 	absolute_path = (char *)getcwd(NULL, 0);
115 	if (absolute_path == NULL) {
116 		perror("getcwd");
117 		exit(0);
118 	}
119 
120 	len = strlen(absolute_path);
121 	absolute_path = realloc(absolute_path,
122 	    len + 1 + strlen(relative_path) + 1);
123 	if (absolute_path == NULL) {
124 		perror("realloc");
125 		exit(0);
126 	}
127 
128 	absolute_path[len] = '/';
129 	strcpy(absolute_path + len + 1, relative_path);
130 
131 	absolute_file = malloc(strlen(absolute_path) + 1 + strlen(file));
132 	bzero(absolute_file, strlen(absolute_path) + 1 + strlen(file));
133 	if (absolute_file == NULL) {
134 		perror("malloc");
135 		exit(0);
136 	}
137 	strcpy(absolute_file, absolute_path);
138 	absolute_file[strlen(absolute_file)] = '/';
139 	strcpy(absolute_file + strlen(absolute_path), file);
140 
141 	relative_file = malloc(strlen(relative_path) + 1 + strlen(file));
142 	bzero(relative_file, strlen(relative_path) + 1 + strlen(file));
143 	if (relative_file == NULL) {
144 		perror("malloc");
145 		exit(0);
146 	}
147 	strcpy(relative_file, relative_path);
148 	relative_file[strlen(relative_file)] = '/';
149 	strcpy(relative_file + strlen(relative_path), file);
150 
151 	error = mkdir(relative_path, 0700);
152 	dir_exist = (errno == EEXIST);
153 	if (error && errno != EEXIST) {
154 		perror("tmp");
155 		exit(0);
156 	}
157 
158 	error = stat("tmp/foo", &sb);
159 	file_exist = (errno != ENOENT);
160 	i = open("tmp/foo", O_RDONLY | O_CREAT, 0666);
161 	if (i == -1) {
162 		perror("foo");
163 		exit(0);
164 	}
165 
166 	rel_fd = open(relative_path, O_RDONLY);
167 	if (rel_fd == -1) {
168 		perror("relative path");
169 		exit(0);
170 	}
171 
172 	abs_fd = open(absolute_path, O_RDONLY);
173 	if (abs_fd == -1) {
174 		perror("absolute path");
175 		exit(0);
176 	}
177 
178 	notd_fd = open(not_dir_path, O_RDONLY);
179 	if (notd_fd == -1) {
180 		perror("not a directory");
181 		exit(0);
182 	}
183 
184 	exec_fd = open(not_dir_path, O_RDONLY);
185 	if (exec_fd == -1) {
186 		perror("not a directory");
187 		exit(0);
188 	}
189 
190 	error = symlink(absolute_file, symlinkf);
191 	link_exist = (errno == EEXIST);
192 	if (error && errno != EEXIST) {
193 		perror("symlink");
194 		exit(0);
195 	}
196 
197 	/* faccessat */
198 	tests[0].syscall = SYS_faccessat;
199 	tests[0].num_of_cases = 6;
200 	tests[0].name = "faccessat";
201 	tests[0].tests[0].result = EBADF;
202 	tests[0].tests[0].params[0].i = 106;	/* invalid fd */
203 	tests[0].tests[0].params[1].cp = relative_path;
204 	tests[0].tests[0].params[2].m = 0;
205 	tests[0].tests[0].params[3].i = 0;
206 	tests[0].tests[1].result = EBADF;
207 	tests[0].tests[1].params[0].i = 106;	/* invalid fd */
208 	tests[0].tests[1].params[1].cp = relative_path;
209 	tests[0].tests[1].params[2].m = 0;
210 	tests[0].tests[1].params[3].i = AT_EACCESS;
211 	tests[0].tests[2].result = EINVAL;
212 	tests[0].tests[2].params[0].i = rel_fd;
213 	tests[0].tests[2].params[1].cp = absolute_path;
214 	tests[0].tests[2].params[2].m = 0;
215 	tests[0].tests[2].params[3].i = 123;	/* invalid flag */
216 	tests[0].tests[3].result = ENOTDIR;
217 	tests[0].tests[3].params[0].i = notd_fd;
218 	tests[0].tests[3].params[1].cp = relative_file;
219 	tests[0].tests[3].params[2].m = 0;
220 	tests[0].tests[3].params[3].i = 0;
221 	tests[0].tests[4].result = 0;
222 	tests[0].tests[4].params[0].i = rel_fd;
223 	tests[0].tests[4].params[1].cp = file;
224 	tests[0].tests[4].params[2].m = 0;
225 	tests[0].tests[4].params[3].i = 0;
226 	tests[0].tests[5].result = 0;
227 	tests[0].tests[5].params[0].i = rel_fd;
228 	tests[0].tests[5].params[1].cp = file;
229 	tests[0].tests[5].params[2].m = 0;
230 	tests[0].tests[5].params[3].i = AT_EACCESS;
231 	tests[0].tests[6].result = 0;
232 	tests[0].tests[6].params[0].i = 106;	/* invalid fd */
233 	tests[0].tests[6].params[1].cp = absolute_path;
234 	tests[0].tests[6].params[2].m = 0;
235 	tests[0].tests[6].params[3].i = 0;
236 
237 	/* fchmodat */
238 	tests[1].syscall = SYS_fchmodat;
239 	tests[1].num_of_cases = 6;
240 	tests[1].name = "fchmodat";
241 	tests[1].tests[0].result = EBADF;
242 	tests[1].tests[0].params[0].i = 106;	/* invalid fd */
243 	tests[1].tests[0].params[1].cp = relative_path;
244 	tests[1].tests[0].params[2].m = 33190;
245 	tests[1].tests[0].params[3].i = 0;
246 	tests[1].tests[1].result = EINVAL;
247 	tests[1].tests[1].params[0].i = rel_fd;
248 	tests[1].tests[1].params[1].cp = absolute_path;
249 	tests[1].tests[1].params[2].m = 33190;	/* mode 646 translated */
250 	tests[1].tests[1].params[3].i = 123;	/* invalid flag */
251 	tests[1].tests[2].result = ENOTDIR;
252 	tests[1].tests[2].params[0].i = notd_fd;
253 	tests[1].tests[2].params[1].cp = relative_file;
254 	tests[1].tests[2].params[2].m = 33190;
255 	tests[1].tests[2].params[3].i = 0;
256 	tests[1].tests[3].result = 0;
257 	tests[1].tests[3].params[0].i = notd_fd;
258 	tests[1].tests[3].params[1].cp = absolute_file;
259 	tests[1].tests[3].params[2].m = 33190;
260 	tests[1].tests[3].params[3].i = 0;
261 	tests[1].tests[4].result = 0;
262 	tests[1].tests[4].params[0].i = AT_FDCWD;
263 	tests[1].tests[4].params[1].cp = symlinkf;
264 	tests[1].tests[4].params[2].m = 33190;
265 	tests[1].tests[4].params[3].i = AT_SYMLINK_NOFOLLOW;
266 	tests[1].tests[5].result = 0;
267 	tests[1].tests[5].params[0].i = rel_fd;
268 	tests[1].tests[5].params[1].cp = file;
269 	tests[1].tests[5].params[2].m = 33190;
270 	tests[1].tests[5].params[3].i = 0;
271 
272 	/* fchownat */
273 	tests[2].syscall = SYS_fchownat;
274 	tests[2].num_of_cases = 6;
275 	tests[2].name = "fchownat";
276 	tests[2].tests[0].result = EBADF;
277 	tests[2].tests[0].params[0].i = 106;	/* invalid fd */
278 	tests[2].tests[0].params[1].cp = relative_file;
279 	tests[2].tests[0].params[2].u = 65534;
280 	tests[2].tests[0].params[3].g = 65534;
281 	tests[2].tests[0].params[4].i = 0;
282 	tests[2].tests[1].result = EINVAL;
283 	tests[2].tests[1].params[0].i = rel_fd;
284 	tests[2].tests[1].params[1].cp = file;
285 	tests[2].tests[1].params[2].u = 65534;
286 	tests[2].tests[1].params[3].g = 65534;
287 	tests[2].tests[1].params[4].i = 123;	/* invalid flag */
288 	tests[2].tests[2].result = ENOTDIR;
289 	tests[2].tests[2].params[0].i = notd_fd;
290 	tests[2].tests[2].params[1].cp = relative_file;
291 	tests[2].tests[2].params[2].u = 65534;
292 	tests[2].tests[2].params[3].g = 65534;
293 	tests[2].tests[2].params[4].i = 0;
294 	tests[2].tests[3].result = 0;
295 	tests[2].tests[3].params[0].i = notd_fd;
296 	tests[2].tests[3].params[1].cp = absolute_file;
297 	tests[2].tests[3].params[2].u = 65534;
298 	tests[2].tests[3].params[3].g = 65534;
299 	tests[2].tests[3].params[4].i = 0;
300 	tests[2].tests[4].result = 0;
301 	tests[2].tests[4].params[0].i = AT_FDCWD;
302 	tests[2].tests[4].params[1].cp = symlinkf;
303 	tests[2].tests[4].params[2].u = 65534;
304 	tests[2].tests[4].params[3].g = 65534;
305 	tests[2].tests[4].params[4].i = AT_SYMLINK_NOFOLLOW;
306 	tests[2].tests[5].result = 0;
307 	tests[2].tests[5].params[0].i = rel_fd;
308 	tests[2].tests[5].params[1].cp = file;
309 	tests[2].tests[5].params[2].u = 0;
310 	tests[2].tests[5].params[3].g = 0;
311 	tests[2].tests[5].params[4].i = 0;
312 
313 	/* fstatat */
314 	tests[3].syscall = SYS_fstatat;
315 	tests[3].num_of_cases = 5;
316 	tests[3].name = "fstatat";
317 	tests[3].tests[0].result = EBADF;
318 	tests[3].tests[0].params[0].i = 106;	/* invalid fd */
319 	tests[3].tests[0].params[1].cp = relative_file;
320 	tests[3].tests[0].params[2].vp = &buf;
321 	tests[3].tests[0].params[3].i = 0;
322 	tests[3].tests[1].result = EINVAL;
323 	tests[3].tests[1].params[0].i = rel_fd;
324 	tests[3].tests[1].params[1].cp = relative_file;
325 	tests[3].tests[1].params[2].vp = &buf;
326 	tests[3].tests[1].params[3].i = 123;	/* invalid flags */
327 	tests[3].tests[2].result = ENOTDIR;
328 	tests[3].tests[2].params[0].i = notd_fd;
329 	tests[3].tests[2].params[1].cp = relative_file;
330 	tests[3].tests[2].params[2].vp = &buf;
331 	tests[3].tests[2].params[3].i = 0;
332 	tests[3].tests[2].result = 0;
333 	tests[3].tests[2].params[0].i = rel_fd;
334 	tests[3].tests[2].params[1].cp = file;
335 	tests[3].tests[2].params[2].vp = &buf;
336 	tests[3].tests[2].params[3].i = 0;
337 	tests[3].tests[3].result = 0;
338 	tests[3].tests[3].params[0].i = AT_FDCWD;
339 	tests[3].tests[3].params[1].cp = symlinkf;
340 	tests[3].tests[3].params[2].vp = &buf;
341 	tests[3].tests[3].params[3].i = AT_SYMLINK_NOFOLLOW;
342 	tests[3].tests[4].result = 0;
343 	tests[3].tests[4].params[0].i = notd_fd;
344 	tests[3].tests[4].params[1].cp = absolute_file;
345 	tests[3].tests[4].params[2].vp = &buf;
346 	tests[3].tests[4].params[3].i = 0;
347 
348 	/* futimesat */
349 	tests[4].syscall = SYS_futimesat;
350 	tests[4].num_of_cases = 4;
351 	tests[4].name = "futimesat";
352 	tests[4].tests[0].result = EBADF;
353 	tests[4].tests[0].params[0].i = 106;	/* invalid fd */
354 	tests[4].tests[0].params[1].cp = relative_file;
355 	tests[4].tests[0].params[2].vp = times;
356 	tests[4].tests[1].result = ENOTDIR;
357 	tests[4].tests[1].params[0].i = notd_fd;
358 	tests[4].tests[1].params[1].cp = relative_file;
359 	tests[4].tests[1].params[2].vp = times;
360 	tests[4].tests[2].result = 0;
361 	tests[4].tests[2].params[0].i = rel_fd;
362 	tests[4].tests[2].params[1].cp = file;
363 	tests[4].tests[2].params[2].vp = times;
364 	tests[4].tests[3].result = 0;
365 	tests[4].tests[3].params[0].i = notd_fd;
366 	tests[4].tests[3].params[1].cp = absolute_file;
367 	tests[4].tests[3].params[2].vp = times;
368 
369 	/* linkat */
370 	tests[5].syscall = SYS_linkat;
371 	tests[5].num_of_cases = 7;
372 	tests[5].name = "linkat";
373 	tests[5].tests[0].result = EBADF;
374 	tests[5].tests[0].params[0].i = 106;	/* invalid fd */
375 	tests[5].tests[0].params[1].cp = relative_file;
376 	tests[5].tests[0].params[2].i = AT_FDCWD;
377 	tests[5].tests[0].params[3].cp = newlink;
378 	tests[5].tests[0].params[4].i = 0;
379 	tests[5].tests[1].result = EBADF;
380 	tests[5].tests[1].params[0].i = AT_FDCWD;
381 	tests[5].tests[1].params[1].cp = relative_file;
382 	tests[5].tests[1].params[2].i = 106;	/* invalid fd */
383 	tests[5].tests[1].params[3].cp = newlink;
384 	tests[5].tests[1].params[4].i = 0;
385 	tests[5].tests[2].result = EINVAL;
386 	tests[5].tests[2].params[0].i = rel_fd;
387 	tests[5].tests[2].params[1].cp = relative_file;
388 	tests[5].tests[2].params[2].i = AT_FDCWD;
389 	tests[5].tests[2].params[3].cp = newlink;
390 	tests[5].tests[2].params[4].i = 123;	/* invalid flag */
391 	tests[5].tests[3].result = ENOTDIR;
392 	tests[5].tests[3].params[0].i = notd_fd;
393 	tests[5].tests[3].params[1].cp = relative_file;
394 	tests[5].tests[3].params[2].i = AT_FDCWD;
395 	tests[5].tests[3].params[3].cp = newlink;
396 	tests[5].tests[3].params[4].i = 0;
397 	tests[5].tests[4].result = 0;
398 	tests[5].tests[4].params[0].i = rel_fd;
399 	tests[5].tests[4].params[1].cp = file;
400 	tests[5].tests[4].params[2].i = rel_fd;
401 	tests[5].tests[4].params[3].cp = newlink;
402 	tests[5].tests[4].params[4].i = 0;
403 	tests[5].tests[5].result = 0;
404 	tests[5].tests[5].params[0].i = AT_FDCWD;
405 	tests[5].tests[5].params[1].cp = symlinkf;
406 	tests[5].tests[5].params[2].i = rel_fd;
407 	tests[5].tests[5].params[3].cp = newlink2;
408 	tests[5].tests[5].params[4].i = 0;
409 	tests[5].tests[6].result = 0;
410 	tests[5].tests[6].params[0].i = AT_FDCWD;
411 	tests[5].tests[6].params[1].cp = symlinkf;
412 	tests[5].tests[6].params[2].i = rel_fd;
413 	tests[5].tests[6].params[3].cp = newlink3;
414 	tests[5].tests[6].params[4].i = AT_SYMLINK_FOLLOW;
415 
416 	/* mkdirat */
417 	tests[6].syscall = SYS_mkdirat;
418 	tests[6].num_of_cases = 3;
419 	tests[6].name = "mkdirat";
420 	tests[6].tests[0].result = EBADF;
421 	tests[6].tests[0].params[0].i = 106;	/* invalid fd */
422 	tests[6].tests[0].params[1].cp = relative_file;
423 	tests[6].tests[0].params[2].m = 33190;
424 	tests[6].tests[1].result = ENOTDIR;
425 	tests[6].tests[1].params[0].i = notd_fd;
426 	tests[6].tests[1].params[1].cp = relative_file;
427 	tests[6].tests[1].params[2].m = 33190;
428 	tests[6].tests[2].result = 0;
429 	tests[6].tests[2].params[0].i = rel_fd;
430 	tests[6].tests[2].params[1].cp = newdir;
431 	tests[6].tests[2].params[2].m = 33190;
432 
433 	/* mkfifoat */
434 	tests[7].syscall = SYS_mkfifoat;
435 	tests[7].num_of_cases = 3;
436 	tests[7].name = "mkfifoat";
437 	tests[7].tests[0].result = EBADF;
438 	tests[7].tests[0].params[0].i = 107;	/* invalid fd */
439 	tests[7].tests[0].params[1].cp = relative_file;
440 	tests[7].tests[0].params[2].m = 33190;
441 	tests[7].tests[1].result = ENOTDIR;
442 	tests[7].tests[1].params[0].i = notd_fd;
443 	tests[7].tests[1].params[1].cp = relative_file;
444 	tests[7].tests[1].params[2].m = 33190;
445 	tests[7].tests[2].result = 0;
446 	tests[7].tests[2].params[0].i = rel_fd;
447 	tests[7].tests[2].params[1].cp = fifo;
448 	tests[7].tests[2].params[2].m = 33190;
449 
450 	/* mknodat */
451 	tests[8].syscall = SYS_mknodat;
452 	tests[8].num_of_cases = 3;
453 	tests[8].name = "mknodat";
454 	tests[8].tests[0].result = EBADF;
455 	tests[8].tests[0].params[0].i = 108;	/* invalid fd */
456 	tests[8].tests[0].params[1].cp = relative_file;
457 	tests[8].tests[0].params[2].m = 0666 | S_IFCHR;
458 	tests[8].tests[0].params[3].d = 15;
459 	tests[8].tests[1].result = ENOTDIR;
460 	tests[8].tests[1].params[0].i = notd_fd;
461 	tests[8].tests[1].params[1].cp = relative_file;
462 	tests[8].tests[1].params[2].m = 0666 | S_IFCHR;
463 	tests[8].tests[1].params[3].d = 15;
464 	tests[8].tests[2].result = 0;
465 	tests[8].tests[2].params[0].i = rel_fd;
466 	tests[8].tests[2].params[1].cp = nod;
467 	tests[8].tests[2].params[2].m = 0666 | S_IFCHR;
468 	tests[8].tests[2].params[3].d = 2570;
469 
470 	/* openat */
471 	tests[9].syscall = SYS_openat;
472 	tests[9].num_of_cases = 5;
473 	tests[9].name = "openat";
474 	tests[9].tests[0].result = EBADF;
475 	tests[9].tests[0].params[0].i = 106;	/* invalid fd */
476 	tests[9].tests[0].params[1].cp = relative_file;
477 	tests[9].tests[0].params[2].i = O_RDONLY;
478 	tests[9].tests[0].params[3].i = 0666;
479 	tests[9].tests[1].result = ENOTDIR;
480 	tests[9].tests[1].params[0].i = notd_fd;
481 	tests[9].tests[1].params[1].cp = relative_file;
482 	tests[9].tests[1].params[2].i = O_RDONLY;
483 	tests[9].tests[1].params[3].i = 0666;
484 	tests[9].tests[2].result = 8;		/* hardcoded fd */
485 	tests[9].tests[2].params[0].i = rel_fd;
486 	tests[9].tests[2].params[1].cp = file;
487 	tests[9].tests[2].params[2].i = O_RDONLY;
488 	tests[9].tests[2].params[3].i = 0400;
489 	tests[9].tests[3].result = 9;		/* hardcoded fd */
490 	tests[9].tests[3].params[0].i = notd_fd;
491 	tests[9].tests[3].params[1].cp = absolute_file;
492 	tests[9].tests[3].params[2].i = O_RDONLY;
493 	tests[9].tests[3].params[3].i = 0400;
494 	tests[9].tests[4].result = 10;		/* hardcoded fd */
495 	tests[9].tests[4].params[0].i = rel_fd;
496 	tests[9].tests[4].params[1].cp = newfile;
497 	tests[9].tests[4].params[2].i = O_RDONLY | O_CREAT;
498 	tests[9].tests[4].params[3].i = 0666;
499 
500 	/* readlinkat */
501 	tests[10].syscall = SYS_readlinkat;
502 	tests[10].num_of_cases = 3;
503 	tests[10].name = "readlinkat";
504 	tests[10].tests[0].result = EBADF;
505 	tests[10].tests[0].params[0].i = 106;	/* invalid fd */
506 	tests[10].tests[0].params[1].cp = relative_file;
507 	tests[10].tests[0].params[2].vp = cbuf;
508 	tests[10].tests[0].params[3].i = PATH_MAX;
509 	tests[10].tests[1].result = ENOTDIR;
510 	tests[10].tests[1].params[0].i = notd_fd;
511 	tests[10].tests[1].params[1].cp = relative_file;
512 	tests[10].tests[1].params[2].vp = cbuf;
513 	tests[10].tests[1].params[3].i = PATH_MAX;
514 	tests[10].tests[2].result = strlen(absolute_file);
515 	tests[10].tests[2].params[0].i = AT_FDCWD;
516 	tests[10].tests[2].params[1].cp = symlinkf;
517 	tests[10].tests[2].params[2].vp = cbuf;
518 	tests[10].tests[2].params[3].i = PATH_MAX;
519 
520 	/* renameat */
521 	tests[11].syscall = SYS_renameat;
522 	tests[11].num_of_cases = 5;
523 	tests[11].name = "renameat";
524 	tests[11].tests[0].result = EBADF;
525 	tests[11].tests[0].params[0].i = 106;	/* invalid fd */
526 	tests[11].tests[0].params[1].cp = file;
527 	tests[11].tests[0].params[2].i = rel_fd;
528 	tests[11].tests[0].params[3].cp = file;
529 	tests[11].tests[1].result = EBADF;
530 	tests[11].tests[1].params[0].i = rel_fd;
531 	tests[11].tests[1].params[1].cp = file;
532 	tests[11].tests[1].params[2].i = 106;	/* invalid fd */
533 	tests[11].tests[1].params[3].cp = file;
534 	tests[11].tests[2].result = ENOTDIR;
535 	tests[11].tests[2].params[0].i = notd_fd;
536 	tests[11].tests[2].params[1].cp = relative_file;
537 	tests[11].tests[2].params[2].i = rel_fd;
538 	tests[11].tests[2].params[3].cp = file;
539 	tests[11].tests[3].result = ENOTDIR;
540 	tests[11].tests[3].params[0].i = rel_fd;
541 	tests[11].tests[3].params[1].cp = file;
542 	tests[11].tests[3].params[2].i = notd_fd;
543 	tests[11].tests[3].params[3].cp = relative_file;
544 	tests[11].tests[4].result = 0;
545 	tests[11].tests[4].params[0].i = rel_fd;
546 	tests[11].tests[4].params[1].cp = newfile;
547 	tests[11].tests[4].params[2].i = AT_FDCWD;
548 	tests[11].tests[4].params[3].cp = newfile;
549 
550 	/* symlinkat */
551 	tests[12].syscall = SYS_symlinkat;
552 	tests[12].num_of_cases = 3;
553 	tests[12].name = "symlinkat";
554 	tests[12].tests[0].result = EBADF;
555 	tests[12].tests[0].params[0].cp = file;
556 	tests[12].tests[0].params[1].i = 106;	/* invalid fd */
557 	tests[12].tests[0].params[2].cp = file;
558 	tests[12].tests[1].result = ENOTDIR;
559 	tests[12].tests[1].params[0].cp = file;
560 	tests[12].tests[1].params[1].i = notd_fd;
561 	tests[12].tests[1].params[2].cp = relative_file;
562 	tests[12].tests[2].result = 0;
563 	tests[12].tests[2].params[0].cp = absolute_file;
564 	tests[12].tests[2].params[1].i = rel_fd;
565 	tests[12].tests[2].params[2].cp = newslink;
566 
567 
568 	/* unlinkat */
569 	tests[13].syscall = SYS_unlinkat;
570 	tests[13].num_of_cases = 7;
571 	tests[13].name = "unlinkat";
572 	tests[13].tests[0].result = EBADF;
573 	tests[13].tests[0].params[0].i = 106;	/* invalid fd */
574 	tests[13].tests[0].params[1].cp = relative_file;
575 	tests[13].tests[0].params[2].i = 0;
576 	tests[13].tests[1].result = ENOTDIR;
577 	tests[13].tests[1].params[0].i = notd_fd;
578 	tests[13].tests[1].params[1].cp = relative_file;
579 	tests[13].tests[1].params[2].i = 0;
580 	tests[13].tests[2].result = EINVAL;
581 	tests[13].tests[2].params[0].i = rel_fd;
582 	tests[13].tests[2].params[1].cp = file;
583 	tests[13].tests[2].params[2].i = 123;	/* invalid flag */
584 	tests[13].tests[3].result = ENOTDIR;
585 	tests[13].tests[3].params[0].i = rel_fd;
586 	tests[13].tests[3].params[1].cp = not_dir_path;
587 	tests[13].tests[3].params[2].i = AT_REMOVEDIR;
588 	tests[13].tests[4].result = ENOTEMPTY;
589 	tests[13].tests[4].params[0].i = AT_FDCWD;
590 	tests[13].tests[4].params[1].cp = relative_path;
591 	tests[13].tests[4].params[2].i = AT_REMOVEDIR;
592 	tests[13].tests[5].result = 0;
593 	tests[13].tests[5].params[0].i = rel_fd;
594 	tests[13].tests[5].params[1].cp = newdir;
595 	tests[13].tests[5].params[2].i = AT_REMOVEDIR;
596 	tests[13].tests[6].result = 0;
597 	tests[13].tests[6].params[0].i = AT_FDCWD;
598 	tests[13].tests[6].params[1].cp = newfile;
599 	tests[13].tests[6].params[2].i = 0;
600 
601 
602 	/* fexecve */
603 	tests[14].syscall = SYS_fexecve;
604 	tests[14].num_of_cases = 2;
605 	tests[14].name = "fexecve";
606 	tests[14].tests[0].result = EBADF;
607 	tests[14].tests[0].params[0].i = 106;	/* invalid fd */
608 	tests[14].tests[0].params[1].cpp = pargv;
609 	tests[14].tests[0].params[2].cpp = NULL;
610 	/* This is EXPECTED to execve /bin/date, so dont expect OK output */
611 	tests[14].tests[1].result = 0;
612 	tests[14].tests[1].params[0].i = exec_fd;
613 	tests[14].tests[1].params[1].cpp = pargv;
614 	tests[14].tests[1].params[2].cpp = NULL;
615 }
616 
617 void
618 cleanup(void)
619 {
620 	system("/bin/sh -c 'rm -rf tmp'");
621 }
622 
623 void
624 setup_once(void)
625 {
626 }
627 
628 int
629 main(int argc, char *argv[])
630 {
631 	int i,j;
632 	int error;
633 
634 	(void)argc;
635 	(void)argv;
636 
637 	setup();
638 
639 	for (i = 0; i < NUM_OF_TESTS; i++) {
640 		printf("\nTest: %s\n", tests[i].name);
641 		for (j = 0; j < tests[i].num_of_cases; j++) {
642 			error = syscall(tests[i].syscall,
643 				tests[i].tests[j].params[0],
644 				tests[i].tests[j].params[1],
645 				tests[i].tests[j].params[2],
646 				tests[i].tests[j].params[3],
647 				tests[i].tests[j].params[4]);
648 			if (error == 0) {
649 				if (tests[i].tests[j].result == 0)
650    					printf("#%i ... OK\n", j);
651 				else {
652 					printf("#%i ... BAD: ", j);
653 					printf("expected %i, but got %i\n", tests[i].tests[j].result, error);
654 				}
655 			} else 	{
656 				if (tests[i].tests[j].result == errno)
657 					printf("#%i ... OK\n", j);
658 				else {
659 				   	if (error != tests[i].tests[j].result) {
660 						printf("#%i ... BAD: ", j);
661 						printf("expected %i, but got %i\n", tests[i].tests[j].result, error);
662 					} else
663 						printf("#%i ... OK\n", j);
664 				}
665 			}
666 		}
667 	}
668 
669 	cleanup();
670 
671 	return (0);
672 }
673