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