Path: blob/main/tools/test/stress2/testcases/openat/doat.c
39566 views
/*-1* Copyright (c) 2007 Roman Divacky <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*25*/2627#include <sys/param.h>28#include <sys/stat.h>29#include <sys/syscall.h>30#include <sys/types.h>31#include <errno.h>32#include <fcntl.h>33#include <stdbool.h>34#include <stdio.h>35#include <stdlib.h>36#include <string.h>37#include <unistd.h>3839union param {40int i;41char *cp;42mode_t m;43dev_t d;44void *vp;45uid_t u;46gid_t g;47char **cpp;48};4950struct testcase {51int result;52union param params[5]; // no *at syscall with more than 5 params53};5455struct test {56int syscall;57int num_of_cases;58char *name;59struct testcase tests[10]; // no more than 10 tests6061};6263struct test *tests;64#define NUM_OF_TESTS 156566char *absolute_path = NULL;67char *relative_path = "tmp/";68char *not_dir_path = "/bin/date";6970char *file = "foo";71char *absolute_file = NULL;72char *relative_file = NULL;73char *symlinkf = "link";74char *newlink = "nlink1";75char *newlink2 = "nlink2";76char *newlink3 = "nlink3";77char *newdir = "newdir";78char *fifo = "fifo";79char *nod = "nod";80char *newfile = "newfile";81char *newslink = "nslink1";8283bool dir_exist = false;84bool file_exist = false;85bool link_exist = false;8687int rel_fd, abs_fd, notd_fd, exec_fd;8889struct timeval times[2];90struct stat buf;91char *pargv[2] = { "/bin/date", NULL };92char cbuf[PATH_MAX];9394void95setup()96{97int i, error;98struct stat sb;99100tests = calloc(NUM_OF_TESTS, sizeof(struct test));101if (tests == NULL) {102perror("");103exit(0);104}105106absolute_path = getcwd(NULL, 0);107if (absolute_path == NULL) {108perror("getcwd");109exit(0);110}111112absolute_path = realloc(absolute_path, strlen(absolute_path) + 5);113if (absolute_path == NULL) {114perror("realloc");115exit(0);116}117118strcat(absolute_path, "/");119strcat(absolute_path, relative_path);120121absolute_file = malloc(strlen(absolute_path) + 1 + strlen(file));122bzero(absolute_file, strlen(absolute_path) + 1 + strlen(file));123if (absolute_file == NULL) {124perror("malloc");125exit(0);126}127strcpy(absolute_file, absolute_path);128absolute_file[strlen(absolute_file)] = '/';129strcpy(absolute_file + strlen(absolute_path), file);130131printf("XX: %s\n", absolute_file);132133relative_file = malloc(strlen(relative_path) + 1 + strlen(file));134bzero(relative_file, strlen(relative_path) + 1 + strlen(file));135if (relative_file == NULL) {136perror("malloc");137exit(0);138}139strcpy(relative_file, relative_path);140relative_file[strlen(relative_file)] = '/';141strcpy(relative_file + strlen(relative_path), file);142143printf("YY: %s\n", relative_file);144145error = mkdir(relative_path, 0744);146dir_exist = (errno == EEXIST);147if (error && errno != EEXIST) {148perror("tmp");149exit(0);150}151152error = stat("tmp/foo", &sb);153file_exist = (errno != ENOENT);154i = open("tmp/foo", O_RDONLY | O_CREAT, 0644);155if (i == -1) {156perror("foo");157exit(0);158}159160rel_fd = open(relative_path, O_RDONLY);161if (rel_fd == -1) {162perror("relative path");163exit(0);164}165166abs_fd = open(absolute_path, O_RDONLY);167if (abs_fd == -1) {168perror("absolute path");169exit(0);170}171172notd_fd = open(not_dir_path, O_RDONLY);173if (notd_fd == -1) {174perror("not a directory");175exit(0);176}177178exec_fd = open(not_dir_path, O_RDONLY);179if (exec_fd == -1) {180perror("not a directory");181exit(0);182}183184error = symlink(absolute_file, symlinkf);185link_exist = (errno == EEXIST);186if (error && errno != EEXIST) {187perror("symlink");188exit(0);189}190191// faccessat192tests[0].syscall = SYS_faccessat;193tests[0].num_of_cases = 6;194tests[0].name = "faccessat";195tests[0].tests[0].result = EBADF;196tests[0].tests[0].params[0].i = 106; // invalid fd197tests[0].tests[0].params[1].cp = relative_path;198tests[0].tests[0].params[2].m = 0;199tests[0].tests[0].params[3].i = 0;200tests[0].tests[1].result = EBADF;201tests[0].tests[1].params[0].i = 106; // invalid fd202tests[0].tests[1].params[1].cp = relative_path;203tests[0].tests[1].params[2].m = 0;204tests[0].tests[1].params[3].i = AT_EACCESS;205tests[0].tests[2].result = EINVAL;206tests[0].tests[2].params[0].i = rel_fd;207tests[0].tests[2].params[1].cp = absolute_path;208tests[0].tests[2].params[2].m = 0;209tests[0].tests[2].params[3].i = 123; // invalid flag210tests[0].tests[3].result = ENOTDIR;211tests[0].tests[3].params[0].i = notd_fd;212tests[0].tests[3].params[1].cp = relative_file;213tests[0].tests[3].params[2].m = 0;214tests[0].tests[3].params[3].i = 0;215tests[0].tests[4].result = 0;216tests[0].tests[4].params[0].i = rel_fd;217tests[0].tests[4].params[1].cp = file;218tests[0].tests[4].params[2].m = 0;219tests[0].tests[4].params[3].i = 0;220tests[0].tests[5].result = 0;221tests[0].tests[5].params[0].i = rel_fd;222tests[0].tests[5].params[1].cp = file;223tests[0].tests[5].params[2].m = 0;224tests[0].tests[5].params[3].i = AT_EACCESS;225tests[0].tests[6].result = 0;226tests[0].tests[6].params[0].i = 106; // invalid fd227tests[0].tests[6].params[1].cp = absolute_path;228tests[0].tests[6].params[2].m = 0;229tests[0].tests[6].params[3].i = 0;230231// fchmodat232tests[1].syscall = SYS_fchmodat;233tests[1].num_of_cases = 6;234tests[1].name = "fchmodat";235tests[1].tests[0].result = EBADF;236tests[1].tests[0].params[0].i = 106; // invalid fd237tests[1].tests[0].params[1].cp = relative_path;238tests[1].tests[0].params[2].m = 33190;239tests[1].tests[0].params[3].i = 0;240tests[1].tests[1].result = EINVAL;241tests[1].tests[1].params[0].i = rel_fd;242tests[1].tests[1].params[1].cp = absolute_path;243tests[1].tests[1].params[2].m = 33190; // mode 646 translated244tests[1].tests[1].params[3].i = 123; // invalid flag245tests[1].tests[2].result = ENOTDIR;246tests[1].tests[2].params[0].i = notd_fd;247tests[1].tests[2].params[1].cp = relative_file;248tests[1].tests[2].params[2].m = 33190;249tests[1].tests[2].params[3].i = 0;250tests[1].tests[3].result = 0;251tests[1].tests[3].params[0].i = notd_fd;252tests[1].tests[3].params[1].cp = absolute_file;253tests[1].tests[3].params[2].m = 33190;254tests[1].tests[3].params[3].i = 0;255tests[1].tests[4].result = 0;256tests[1].tests[4].params[0].i = AT_FDCWD;257tests[1].tests[4].params[1].cp = symlinkf;258tests[1].tests[4].params[2].m = 33190;259tests[1].tests[4].params[3].i = AT_SYMLINK_NOFOLLOW;260tests[1].tests[5].result = 0;261tests[1].tests[5].params[0].i = rel_fd;262tests[1].tests[5].params[1].cp = file;263tests[1].tests[5].params[2].m = 33190;264tests[1].tests[5].params[3].i = 0;265266// fchownat267tests[2].syscall = SYS_fchownat;268tests[2].num_of_cases = 6;269tests[2].name = "fchownat";270tests[2].tests[0].result = EBADF;271tests[2].tests[0].params[0].i = 106; // invalid fd272tests[2].tests[0].params[1].cp = relative_file;273tests[2].tests[0].params[2].u = 65534;274tests[2].tests[0].params[3].g = 65534;275tests[2].tests[0].params[4].i = 0;276tests[2].tests[1].result = EINVAL;277tests[2].tests[1].params[0].i = rel_fd;278tests[2].tests[1].params[1].cp = file;279tests[2].tests[1].params[2].u = 65534;280tests[2].tests[1].params[3].g = 65534;281tests[2].tests[1].params[4].i = 123; // invalid flag282tests[2].tests[2].result = ENOTDIR;283tests[2].tests[2].params[0].i = notd_fd;284tests[2].tests[2].params[1].cp = relative_file;285tests[2].tests[2].params[2].u = 65534;286tests[2].tests[2].params[3].g = 65534;287tests[2].tests[2].params[4].i = 0;288tests[2].tests[3].result = 0;289tests[2].tests[3].params[0].i = notd_fd;290tests[2].tests[3].params[1].cp = absolute_file;291tests[2].tests[3].params[2].u = 65534;292tests[2].tests[3].params[3].g = 65534;293tests[2].tests[3].params[4].i = 0;294tests[2].tests[4].result = 0;295tests[2].tests[4].params[0].i = AT_FDCWD;296tests[2].tests[4].params[1].cp = symlinkf;297tests[2].tests[4].params[2].u = 65534;298tests[2].tests[4].params[3].g = 65534;299tests[2].tests[4].params[4].i = AT_SYMLINK_NOFOLLOW;300tests[2].tests[5].result = 0;301tests[2].tests[5].params[0].i = rel_fd;302tests[2].tests[5].params[1].cp = file;303tests[2].tests[5].params[2].u = 0;304tests[2].tests[5].params[3].g = 0;305tests[2].tests[5].params[4].i = 0;306307// fstatat308tests[3].syscall = SYS_fstatat;309tests[3].num_of_cases = 5;310tests[3].name = "fstatat";311tests[3].tests[0].result = EBADF;312tests[3].tests[0].params[0].i = 106; // invalid fd313tests[3].tests[0].params[1].cp = relative_file;314tests[3].tests[0].params[2].vp = &buf;315tests[3].tests[0].params[3].i = 0;316tests[3].tests[1].result = EINVAL;317tests[3].tests[1].params[0].i = rel_fd;318tests[3].tests[1].params[1].cp = relative_file;319tests[3].tests[1].params[2].vp = &buf;320tests[3].tests[1].params[3].i = 123; // invalid flags321tests[3].tests[2].result = ENOTDIR;322tests[3].tests[2].params[0].i = notd_fd;323tests[3].tests[2].params[1].cp = relative_file;324tests[3].tests[2].params[2].vp = &buf;325tests[3].tests[2].params[3].i = 0;326tests[3].tests[2].result = 0;327tests[3].tests[2].params[0].i = rel_fd;328tests[3].tests[2].params[1].cp = file;329tests[3].tests[2].params[2].vp = &buf;330tests[3].tests[2].params[3].i = 0;331tests[3].tests[3].result = 0;332tests[3].tests[3].params[0].i = AT_FDCWD;333tests[3].tests[3].params[1].cp = symlinkf;334tests[3].tests[3].params[2].vp = &buf;335tests[3].tests[3].params[3].i = AT_SYMLINK_NOFOLLOW;336tests[3].tests[4].result = 0;337tests[3].tests[4].params[0].i = notd_fd;338tests[3].tests[4].params[1].cp = absolute_file;339tests[3].tests[4].params[2].vp = &buf;340tests[3].tests[4].params[3].i = 0;341342// futimesat343tests[4].syscall = SYS_futimesat;344tests[4].num_of_cases = 4;345tests[4].name = "futimesat";346tests[4].tests[0].result = EBADF;347tests[4].tests[0].params[0].i = 106; // invalid fd348tests[4].tests[0].params[1].cp = relative_file;349tests[4].tests[0].params[2].vp = times;350tests[4].tests[1].result = ENOTDIR;351tests[4].tests[1].params[0].i = notd_fd;352tests[4].tests[1].params[1].cp = relative_file;353tests[4].tests[1].params[2].vp = times;354tests[4].tests[2].result = 0;355tests[4].tests[2].params[0].i = rel_fd;356tests[4].tests[2].params[1].cp = file;357tests[4].tests[2].params[2].vp = times;358tests[4].tests[3].result = 0;359tests[4].tests[3].params[0].i = notd_fd;360tests[4].tests[3].params[1].cp = absolute_file;361tests[4].tests[3].params[2].vp = times;362363// linkat364tests[5].syscall = SYS_linkat;365tests[5].num_of_cases = 7;366tests[5].name = "linkat";367tests[5].tests[0].result = EBADF;368tests[5].tests[0].params[0].i = 106; // invalid fd369tests[5].tests[0].params[1].cp = relative_file;370tests[5].tests[0].params[2].i = AT_FDCWD;371tests[5].tests[0].params[3].cp = newlink;372tests[5].tests[0].params[4].i = 0;373tests[5].tests[1].result = EBADF;374tests[5].tests[1].params[0].i = AT_FDCWD;375tests[5].tests[1].params[1].cp = relative_file;376tests[5].tests[1].params[2].i = 106; // invalid fd377tests[5].tests[1].params[3].cp = newlink;378tests[5].tests[1].params[4].i = 0;379tests[5].tests[2].result = EINVAL;380tests[5].tests[2].params[0].i = rel_fd;381tests[5].tests[2].params[1].cp = relative_file;382tests[5].tests[2].params[2].i = AT_FDCWD;383tests[5].tests[2].params[3].cp = newlink;384tests[5].tests[2].params[4].i = 123; // invalid flag385tests[5].tests[3].result = ENOTDIR;386tests[5].tests[3].params[0].i = notd_fd;387tests[5].tests[3].params[1].cp = relative_file;388tests[5].tests[3].params[2].i = AT_FDCWD;389tests[5].tests[3].params[3].cp = newlink;390tests[5].tests[3].params[4].i = 0;391tests[5].tests[4].result = 0;392tests[5].tests[4].params[0].i = rel_fd;393tests[5].tests[4].params[1].cp = file;394tests[5].tests[4].params[2].i = rel_fd;395tests[5].tests[4].params[3].cp = newlink;396tests[5].tests[4].params[4].i = 0;397tests[5].tests[5].result = 0;398tests[5].tests[5].params[0].i = AT_FDCWD;399tests[5].tests[5].params[1].cp = symlinkf;400tests[5].tests[5].params[2].i = rel_fd;401tests[5].tests[5].params[3].cp = newlink2;402tests[5].tests[5].params[4].i = 0;403tests[5].tests[6].result = 0;404tests[5].tests[6].params[0].i = AT_FDCWD;405tests[5].tests[6].params[1].cp = symlinkf;406tests[5].tests[6].params[2].i = rel_fd;407tests[5].tests[6].params[3].cp = newlink3;408tests[5].tests[6].params[4].i = AT_SYMLINK_FOLLOW;409410// mkdirat411tests[6].syscall = SYS_mkdirat;412tests[6].num_of_cases = 3;413tests[6].name = "mkdirat";414tests[6].tests[0].result = EBADF;415tests[6].tests[0].params[0].i = 106; // invalid fd416tests[6].tests[0].params[1].cp = relative_file;417tests[6].tests[0].params[2].m = 33190;418tests[6].tests[1].result = ENOTDIR;419tests[6].tests[1].params[0].i = notd_fd;420tests[6].tests[1].params[1].cp = relative_file;421tests[6].tests[1].params[2].m = 33190;422tests[6].tests[2].result = 0;423tests[6].tests[2].params[0].i = rel_fd;424tests[6].tests[2].params[1].cp = newdir;425tests[6].tests[2].params[2].m = 33190;426427// mkfifoat428tests[7].syscall = SYS_mkfifoat;429tests[7].num_of_cases = 3;430tests[7].name = "mkfifoat";431tests[7].tests[0].result = EBADF;432tests[7].tests[0].params[0].i = 107; // invalid fd433tests[7].tests[0].params[1].cp = relative_file;434tests[7].tests[0].params[2].m = 33190;435tests[7].tests[1].result = ENOTDIR;436tests[7].tests[1].params[0].i = notd_fd;437tests[7].tests[1].params[1].cp = relative_file;438tests[7].tests[1].params[2].m = 33190;439tests[7].tests[2].result = 0;440tests[7].tests[2].params[0].i = rel_fd;441tests[7].tests[2].params[1].cp = fifo;442tests[7].tests[2].params[2].m = 33190;443444// mknodat445tests[8].syscall = SYS_mknodat;446tests[8].num_of_cases = 3;447tests[8].name = "mknodat";448tests[8].tests[0].result = EBADF;449tests[8].tests[0].params[0].i = 108; // invalid fd450tests[8].tests[0].params[1].cp = relative_file;451tests[8].tests[0].params[2].m = 0666 | S_IFCHR;452tests[8].tests[0].params[3].d = 15;453tests[8].tests[1].result = ENOTDIR;454tests[8].tests[1].params[0].i = notd_fd;455tests[8].tests[1].params[1].cp = relative_file;456tests[8].tests[1].params[2].m = 0666 | S_IFCHR;457tests[8].tests[1].params[3].d = 15;458tests[8].tests[2].result = 0;459tests[8].tests[2].params[0].i = rel_fd;460tests[8].tests[2].params[1].cp = nod;461tests[8].tests[2].params[2].m = 0666 | S_IFCHR;462tests[8].tests[2].params[3].d = 2570;463464// openat465tests[9].syscall = SYS_openat;466tests[9].num_of_cases = 5;467tests[9].name = "openat";468tests[9].tests[0].result = EBADF;469tests[9].tests[0].params[0].i = 106; // invalid fd470tests[9].tests[0].params[1].cp = relative_file;471tests[9].tests[0].params[2].i = O_RDONLY;472tests[9].tests[0].params[3].i = 0666;473tests[9].tests[1].result = ENOTDIR;474tests[9].tests[1].params[0].i = notd_fd;475tests[9].tests[1].params[1].cp = relative_file;476tests[9].tests[1].params[2].i = O_RDONLY;477tests[9].tests[1].params[3].i = 0666;478tests[9].tests[2].result = 7; // hardcoded fd479tests[9].tests[2].params[0].i = rel_fd;480tests[9].tests[2].params[1].cp = file;481tests[9].tests[2].params[2].i = O_RDONLY;482tests[9].tests[2].params[3].i = 0400;483tests[9].tests[3].result = 8; // hardcoded fd484tests[9].tests[3].params[0].i = notd_fd;485tests[9].tests[3].params[1].cp = absolute_file;486tests[9].tests[3].params[2].i = O_RDONLY;487tests[9].tests[3].params[3].i = 0400;488tests[9].tests[4].result = 9; // hardcoded fd489tests[9].tests[4].params[0].i = rel_fd;490tests[9].tests[4].params[1].cp = newfile;491tests[9].tests[4].params[2].i = O_RDONLY | O_CREAT;492tests[9].tests[4].params[3].i = 0666;493494// readlinkat495tests[10].syscall = SYS_readlinkat;496tests[10].num_of_cases = 3;497tests[10].name = "readlinkat";498tests[10].tests[0].result = EBADF;499tests[10].tests[0].params[0].i = 106; // invalid fd500tests[10].tests[0].params[1].cp = relative_file;501tests[10].tests[0].params[2].vp = cbuf;502tests[10].tests[0].params[3].i = PATH_MAX;503tests[10].tests[1].result = ENOTDIR;504tests[10].tests[1].params[0].i = notd_fd;505tests[10].tests[1].params[1].cp = relative_file;506tests[10].tests[1].params[2].vp = cbuf;507tests[10].tests[1].params[3].i = PATH_MAX;508tests[10].tests[2].result = strlen(absolute_file);509tests[10].tests[2].params[0].i = AT_FDCWD;510tests[10].tests[2].params[1].cp = symlinkf;511tests[10].tests[2].params[2].vp = cbuf;512tests[10].tests[2].params[3].i = PATH_MAX;513514// renameat515tests[11].syscall = SYS_renameat;516tests[11].num_of_cases = 5;517tests[11].name = "renameat";518tests[11].tests[0].result = EBADF;519tests[11].tests[0].params[0].i = 106; // invalid fd520tests[11].tests[0].params[1].cp = file;521tests[11].tests[0].params[2].i = rel_fd;522tests[11].tests[0].params[3].cp = file;523tests[11].tests[1].result = EBADF;524tests[11].tests[1].params[0].i = rel_fd;525tests[11].tests[1].params[1].cp = file;526tests[11].tests[1].params[2].i = 106; // invalid fd527tests[11].tests[1].params[3].cp = file;528tests[11].tests[2].result = ENOTDIR;529tests[11].tests[2].params[0].i = notd_fd;530tests[11].tests[2].params[1].cp = relative_file;531tests[11].tests[2].params[2].i = rel_fd;532tests[11].tests[2].params[3].cp = file;533tests[11].tests[3].result = ENOTDIR;534tests[11].tests[3].params[0].i = rel_fd;535tests[11].tests[3].params[1].cp = file;536tests[11].tests[3].params[2].i = notd_fd;537tests[11].tests[3].params[3].cp = relative_file;538tests[11].tests[4].result = 0;539tests[11].tests[4].params[0].i = rel_fd;540tests[11].tests[4].params[1].cp = newfile;541tests[11].tests[4].params[2].i = AT_FDCWD;542tests[11].tests[4].params[3].cp = newfile;543544// symlinkat545tests[12].syscall = SYS_symlinkat;546tests[12].num_of_cases = 3;547tests[12].name = "symlinkat";548tests[12].tests[0].result = EBADF;549tests[12].tests[0].params[0].cp = file;550tests[12].tests[0].params[1].i = 106; // invalid fd551tests[12].tests[0].params[2].cp = file;552tests[12].tests[1].result = ENOTDIR;553tests[12].tests[1].params[0].cp = file;554tests[12].tests[1].params[1].i = notd_fd;555tests[12].tests[1].params[2].cp = relative_file;556tests[12].tests[2].result = 0;557tests[12].tests[2].params[0].cp = absolute_file;558tests[12].tests[2].params[1].i = rel_fd;559tests[12].tests[2].params[2].cp = newslink;560561// unlinkat562tests[13].syscall = SYS_unlinkat;563tests[13].num_of_cases = 7;564tests[13].name = "unlinkat";565tests[13].tests[0].result = EBADF;566tests[13].tests[0].params[0].i = 106; // invalid fd567tests[13].tests[0].params[1].cp = relative_file;568tests[13].tests[0].params[2].i = 0;569tests[13].tests[1].result = ENOTDIR;570tests[13].tests[1].params[0].i = notd_fd;571tests[13].tests[1].params[1].cp = relative_file;572tests[13].tests[1].params[2].i = 0;573tests[13].tests[2].result = EINVAL;574tests[13].tests[2].params[0].i = rel_fd;575tests[13].tests[2].params[1].cp = file;576tests[13].tests[2].params[2].i = 123; // invalid flag577tests[13].tests[3].result = ENOTDIR;578tests[13].tests[3].params[0].i = rel_fd;579tests[13].tests[3].params[1].cp = not_dir_path;580tests[13].tests[3].params[2].i = AT_REMOVEDIR;581tests[13].tests[4].result = ENOTEMPTY;582tests[13].tests[4].params[0].i = AT_FDCWD;583tests[13].tests[4].params[1].cp = relative_path;584tests[13].tests[4].params[2].i = AT_REMOVEDIR;585tests[13].tests[5].result = 0;586tests[13].tests[5].params[0].i = rel_fd;587tests[13].tests[5].params[1].cp = newdir;588tests[13].tests[5].params[2].i = AT_REMOVEDIR;589tests[13].tests[6].result = 0;590tests[13].tests[6].params[0].i = AT_FDCWD;591tests[13].tests[6].params[1].cp = newfile;592tests[13].tests[6].params[2].i = 0;593594// fexecve595tests[14].syscall = SYS_fexecve;596tests[14].num_of_cases = 2;597tests[14].name = "fexecve";598tests[14].tests[0].result = EBADF;599tests[14].tests[0].params[0].i = 106; // invalid fd600tests[14].tests[0].params[1].cpp = pargv;601tests[14].tests[0].params[2].cpp = NULL;602// This is EXPECTED to execve /bin/date, so dont expect OK output603tests[14].tests[1].result = 0;604tests[14].tests[1].params[0].i = exec_fd;605tests[14].tests[1].params[1].cpp = pargv;606tests[14].tests[1].params[2].cpp = NULL;607}608609void610cleanup()611{612int error;613614close(notd_fd);615close(rel_fd);616close(abs_fd);617618if (!file_exist) {619error = unlink("tmp/foo");620if (error) {621perror("unlink");622exit(0);623}624}625if (!dir_exist) {626error = rmdir(absolute_path);627if (error) {628perror("rmdir");629exit(0);630}631}632if (link_exist) {633error = unlink(symlinkf);634if (error) {635perror("unlink");636exit(0);637}638}639}640641void642setup_once()643{644}645646int647main(int argc, char *argv[])648{649int i,j;650int error;651652setup();653654for (i = 0; i < NUM_OF_TESTS; i++) {655printf("\nTest: %s\n", tests[i].name);656for (j = 0; j < tests[i].num_of_cases; j++) {657error = syscall(tests[i].syscall,658tests[i].tests[j].params[0],659tests[i].tests[j].params[1],660tests[i].tests[j].params[2],661tests[i].tests[j].params[3],662tests[i].tests[j].params[4]);663if (error == 0) {664if (tests[i].tests[j].result == 0)665printf("#%i ... OK\n", j);666else {667printf("#%i ... BAD: ", j);668printf("expected %i, but got %i\n", tests[i].tests[j].result, error);669}670} else {671if (tests[i].tests[j].result == errno)672printf("#%i ... OK\n", j);673else {674if (error != tests[i].tests[j].result) {675printf("#%i ... BAD: ", j);676printf("expected %i, but got %i\n", tests[i].tests[j].result, error);677} else678printf("#%i ... OK\n", j);679}680}681682}683}684685686return (0);687}688689690