int main(int argc, char **argv) { int nbytes, ret; int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ /* parse standard options */ if ((msg = parse_opts(argc, argv, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /*NOTREACHED*/ } /* set "tstdir", and "testfile" vars */ setup(); /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; buf_list[0] = buf1; buf_list[1] = buf2; buf_list[2] = buf3; buf_list[3] = (char *)NULL; fd[1] = -1; /* Invalid file descriptor */ if (signal(SIGTERM, sighandler) == SIG_ERR) { perror("signal: SIGTERM"); cleanup(); /*NOTREACHED*/ } if (signal(SIGPIPE, sighandler) == SIG_ERR) { perror("signal: SIGPIPE"); cleanup(); /*NOTREACHED*/ } init_buffs(buf_list); if ((fd[0] = open(f_name, O_WRONLY | O_CREAT, 0666)) < 0) { tst_resm(TFAIL, "open failed: fname = %s, errno = %d", f_name, errno); cleanup(); /*NOTREACHED*/ } else if ((nbytes = write(fd[0], buf_list[2], K_1)) != K_1) { tst_resm(TFAIL, "write failed: nbytes = %d, " "errno = %d", nbytes, errno); cleanup(); /*NOTREACHED*/ } if (close(fd[0]) < 0) { tst_resm(TFAIL, "close failed: errno: %d", errno); cleanup(); /*NOTREACHED*/ } if ((fd[0] = open(f_name, O_RDWR, 0666)) < 0) { tst_resm(TFAIL, "open failed: fname = %s, errno = %d", f_name, errno); cleanup(); /*NOTREACHED*/ } //block1: /* given vector length -1, writev() return EINVAL. */ tst_resm(TINFO, "Enter Block 1"); fail = 0; TEST(writev(fd[0], wr_iovec, 1)); if (TEST_RETURN < 0) { TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == EINVAL) { tst_resm(TINFO, "Received EINVAL as expected"); } else { tst_resm(TFAIL, "Expected errno = EINVAL, " "got %d", TEST_ERRNO); fail = 1; } } else { tst_resm(TFAIL, "writev() failed to fail"); fail = 1; } if (fail) { tst_resm(TINFO, "block 1 FAILED"); } else { tst_resm(TINFO, "block 1 PASSED"); } tst_resm(TINFO, "Exit block 1"); //block2: /* This testcases doesn't look like what it intent to do * 1. it is not using the wr_iovec initialized * 2. read() and following message is not consistent */ tst_resm(TINFO, "Enter block 2"); fail = 0; if (l_seek(fd[0], CHUNK * 6, 0) < 0) { TEST_ERROR_LOG(errno); tst_resm(TBROK, "block2: 1st lseek failed"); fail = 1; } if ((ret = writev(fd[0], (wr_iovec + 6), 3)) == CHUNK) { if (l_seek(fd[0], CHUNK * 6, 0) < 0) { TEST_ERROR_LOG(errno); tst_resm(TFAIL, "block2: 2nd lseek failed"); fail = 1; } if ((nbytes = read(fd[0], buf_list[0], CHUNK)) != CHUNK) { perror("read error"); tst_resm(TFAIL, "expected nbytes = 1024, " "got = %d", nbytes); fail = 1; } else if (memcmp((buf_list[0] + CHUNK * 6), (buf_list[2] + CHUNK * 6), CHUNK) != 0) { tst_resm(TFAIL, "Error: writev() over " "wrote %s", f_name); fail = 1; } } else { tst_resm(TFAIL, "writev() failed unexpectedly"); fail = 1; } if (fail) { tst_resm(TINFO, "block 2 FAILED"); } else { tst_resm(TINFO, "block 2 PASSED"); } tst_resm(TINFO, "Exit block 2"); //block3: /* given 1 bad vector buffer with good ones, writev() success */ tst_resm(TINFO, "Enter block 3"); fail = 0; if (lseek(fd[0], CHUNK * 6, 0) < 0) { TEST_ERROR_LOG(errno); tst_resm(TFAIL, "block3: 1st lseek failed"); fail = 1; } if ((nbytes = writev(fd[0], (wr_iovec + 6), 3)) < 0) { TEST_ERROR_LOG(errno); if (errno == EFAULT) { tst_resm(TFAIL, "Got EFAULT"); fail = 1; } } if (l_seek(fd[0], 0, 0) < 0) { TEST_ERROR_LOG(errno); tst_resm(TFAIL, "block3: 2nd lseek failed"); fail = 1; } if ((nbytes = read(fd[0], buf_list[0], K_1)) != K_1) { perror("read error"); tst_resm(TFAIL, "expected nbytes = 1024, got = %d", nbytes); fail = 1; } else if (memcmp((buf_list[0] + CHUNK * 6), (buf_list[2] + CHUNK * 6), CHUNK * 3) != 0) { tst_resm(TFAIL, "Error: writev() over wrote %s", f_name); fail = 1; } if (fail) { tst_resm(TINFO, "block 3 FAILED"); } else { tst_resm(TINFO, "block 3 PASSED"); } tst_resm(TINFO, "Exit block 3"); //block4: /* given bad file discriptor, writev() return EBADF. */ tst_resm(TINFO, "Enter block 4"); fail = 0; TEST(writev(fd[1], (wr_iovec + 9), 1)); if (TEST_RETURN < 0) { TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == EBADF) { tst_resm(TINFO, "Received EBADF as expected"); } else { tst_resm(TFAIL, "expected errno = EBADF, " "got %d", TEST_ERRNO); fail = 1; } } else { tst_resm(TFAIL, "Error: writev() returned a " "positive value"); fail = 1; } if (fail) { tst_resm(TINFO, "block 4 FAILED"); } else { tst_resm(TINFO, "block 4 PASSED"); } tst_resm(TINFO, "Exit block 4"); //block5: /* given invalid vector count, writev() return EINVAL */ tst_resm(TINFO, "Enter block 5"); fail = 0; TEST(writev(fd[0], (wr_iovec + 10), -1)); if (TEST_RETURN < 0) { TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == EINVAL) { tst_resm(TINFO, "Received EINVAL as expected"); } else { tst_resm(TFAIL, "expected errno = EINVAL, " "got %d", TEST_ERRNO); fail = 1; } } else { tst_resm(TFAIL, "Error: writev() returned a " "positive value"); fail = 1; } if (fail) { tst_resm(TINFO, "block 5 FAILED"); } else { tst_resm(TINFO, "block 5 PASSED"); } tst_resm(TINFO, "Exit block 5"); //block6: /* given no buffer vector, writev() success */ tst_resm(TINFO, "Enter block 6"); fail = 0; TEST(writev(fd[0], (wr_iovec + 11), 0)); if (TEST_RETURN < 0) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "writev() failed with unexpected errno " "%d", TEST_ERRNO); fail = 1; } else { tst_resm(TPASS, "writev() wrote 0 iovectors"); } if (fail) { tst_resm(TINFO, "block 6 FAILED"); } else { tst_resm(TINFO, "block 6 PASSED"); } tst_resm(TINFO, "Exit block 6"); //block7: /* given 4 vectors, 2 are NULL, 1 with 0 length and 1 with fixed length, * writev() success writing fixed length. */ tst_resm(TINFO, "Enter block 7"); fail = 0; l_seek(fd[0], CHUNK * 12, 0); if ((ret = writev(fd[0], (wr_iovec + 12), 4)) != CHUNK) { tst_resm(TFAIL, "writev() failed writing %d bytes, " "followed by two NULL vectors", CHUNK); fail = 1; } else { tst_resm(TPASS, "writev passed writing %d bytes, " "followed by two NULL vectors", CHUNK); } if (fail) { tst_resm(TINFO, "block 7 FAILED"); } else { tst_resm(TINFO, "block 7 PASSED"); } tst_resm(TINFO, "Exit block 7"); //block8: /* try to write to a closed pipe, writev() return EPIPE. */ tst_resm(TINFO, "Enter block 8"); fail = 0; if (pipe(pfd) < 0) { TEST_ERROR_LOG(errno); perror("pipe"); tst_resm(TFAIL, "pipe failed: errno = %d", errno); fail = 1; } else { if (close(pfd[0]) < 0) { TEST_ERROR_LOG(errno); perror("close"); tst_resm(TFAIL, "close failed: errno = %d", errno); fail = 1; } else if ((writev(pfd[1], (wr_iovec + 12), 1) < 0) && in_sighandler) { TEST_ERROR_LOG(errno); if (errno == EPIPE) { tst_resm(TINFO, "Received EPIPE as " "expected"); } else { tst_resm(TFAIL, "expected errno = " "EPIPE, got %d", errno); fail = 1; } } else { tst_resm(TFAIL, "Error: writev() returned a " "positive value"); fail = 1; } } if (fail) { tst_resm(TINFO, "block 8 FAILED"); } else { tst_resm(TINFO, "block 8 PASSED"); } tst_resm(TINFO, "Exit block 8"); } close(fd[0]); close(fd[1]); cleanup(); /*NOTREACHED*/ return 0; }
int main(int ac, char **av) { int lc; const char *msg; int val; /* value for SETVAL */ int i; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); /* global setup */ /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset tst_count in case we are looping */ tst_count = 0; val = 1; for (i = 0; i < TST_TOTAL; i++) { /* initialize the s_buf buffer */ s_buf.sem_op = TC[i].op; s_buf.sem_flg = TC[i].flg; s_buf.sem_num = TC[i].num; /* initialize all the primitive semaphores */ TC[i].get_arr.val = val--; if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].get_arr) == -1) { tst_brkm(TBROK, cleanup, "semctl() failed"); } /* * make the call with the TEST macro */ TEST(semop(sem_id_1, &s_buf, 1)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == TC[i].error) { tst_resm(TPASS, "expected failure - errno = %d" " : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TFAIL, "unexpected error - " "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int exec_return; /* return from do_exec */ int **tcp; /* testcase pointer (pointer to FD) */ char **tcd; /* testcase description pointer */ /*************************************************************** * parse standard options, and exit if there is an error ***************************************************************/ if ((msg = parse_opts(ac, av, options, &help)) != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } if (fflag) /* -F option */ File1 = fopt; if (Tflag) { /* -T option */ exit(test_open(Topt)); } /*************************************************************** * perform global setup for test ***************************************************************/ setup(av[0]); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count = 0; for (tcp = testfds, tcd = testfdtypes; *tcp; tcp++, tcd++) { TEST(fcntl(**tcp, F_SETFD, FD_CLOEXEC)); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "fcntl(%s[%d], F_SETFD, FD_CLOEXEC) Failed, errno=%d : %s", *tcd, **tcp, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /************************************************************* * only perform functional verification if flag set * (-f not given) *************************************************************/ if (STD_FUNCTIONAL_TEST) { exec_return = do_exec(subprog_path, **tcp, *tcd); switch (exec_return) { case -1: tst_resm(TBROK, "fork failed. Errno %s [%d]", strerror(errno), errno); break; case 1: tst_resm(TBROK, "waitpid return was 0%o", stat_loc); break; case 2: tst_resm(TBROK, "exec failed"); /* errno was in child */ break; case 0: tst_resm(TPASS, "%s child exited 0, indicating that the file was closed", *tcd); break; default: tst_resm(TFAIL, "%s child exited non-zero, %d", *tcd, exec_return); break; } } } } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int i; /* Disable test if the version of the kernel is less than 2.6.16 */ if((tst_kvercmp(2,6,16)) < 0) { tst_resm(TWARN, "This test can only run on kernels that are "); tst_resm(TWARN, "2.6.16 and higher"); exit(0); } /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { setup_every_copy(); /* reset Tst_count in case we are looping. */ Tst_count = 0; /* * Call fchmodat */ for (i = 0; i < TST_TOTAL; i++) { TEST(myfchmodat(fds[i], filenames[i], 0600)); /* check return code */ if (TEST_ERRNO == expected_errno[i]) { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, "fchmodat() returned the expected errno %d: %s", TEST_ERRNO, strerror(TEST_ERRNO)); } } else { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "fchmodat() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return (0); } /* End main */
/* * do_master_child() */ void do_master_child() { int lc; int pid; int status; for (lc = 0; TEST_LOOPING(lc); lc++) { int tst_fd; /* Reset tst_count in case we are looping */ tst_count = 0; if (setresuid(0, ltpuser->pw_uid, 0) == -1) { perror("setfsuid failed"); exit(1); } /* Test 1: Check the process with new uid cannot open the file * with RDWR permissions. */ TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { printf("open succeeded unexpectedly\n"); close(tst_fd); exit(1); } if (TEST_ERRNO == EACCES) { printf("open failed with EACCES as expected\n"); } else { perror("open failed unexpectedly"); exit(1); } /* Test 2: Check a son process cannot open the file * with RDWR permissions. */ pid = FORK_OR_VFORK(); if (pid < 0) tst_brkm(TBROK, cleanup, "Fork failed"); if (pid == 0) { int tst_fd2; /* Test to open the file in son process */ TEST(tst_fd2 = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { printf("call succeeded unexpectedly\n"); close(tst_fd2); exit(1); } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == EACCES) { printf("open failed with EACCES as expected\n"); exit(0); } else { printf("open failed unexpectedly\n"); exit(1); } } else { /* Wait for son completion */ if (waitpid(pid, &status, 0) == -1) { perror("waitpid failed"); exit(1); } if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) exit(WEXITSTATUS(status)); } /* Test 3: Fallback to initial uid and check we can again open * the file with RDWR permissions. */ tst_count++; if (setresuid(0, 0, 0) == -1) { perror("setfsuid failed"); exit(1); } TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN == -1) { perror("open failed unexpectedly"); exit(1); } else { printf("open call succeeded\n"); close(tst_fd); } } exit(0); }
/*********************************************************************** * Main ***********************************************************************/ int main(int ac, char **av) { int lc; /* loop counter */ const char *msg; /* message returned from parse_opts */ struct stat fbuf, lbuf; int cnt; int nlinks; char lname[255]; Tst_nobuf=1; /*************************************************************** * parse standard options ***************************************************************/ if ( (msg=parse_opts(ac, av, options, &help)) != (char *) NULL ) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } if ( Nflag ) { if (sscanf(Nlinkarg, "%i", &Nlinks) != 1 ) { tst_brkm(TBROK, NULL, "--N option arg is not a number"); tst_exit(); } if ( Nlinks > 1000 ) { tst_resm(TWARN, "--N option arg > 1000 - may get errno:%d (EMLINK)", EMLINK); } } /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc=0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count=0; if ( Nlinks ) nlinks = Nlinks; else /* min of 10 links and max of a 100 links */ nlinks = (lc%90)+10; for(cnt=1; cnt < nlinks; cnt++) { sprintf(lname, "%s%d", Basename, cnt); /* * Call link(2) */ TEST(link(Fname, lname)); /* check return code */ if ( TEST_RETURN == -1 ) { TEST_ERROR_LOG(TEST_ERRNO); tst_brkm(TFAIL, cleanup, "link(%s, %s) Failed, errno=%d : %s", Fname, lname, TEST_ERRNO, strerror(TEST_ERRNO)); } } /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if ( STD_FUNCTIONAL_TEST ) { stat(Fname, &fbuf); for(cnt=1; cnt < nlinks; cnt++) { sprintf(lname, "%s%d", Basename, cnt); stat(lname, &lbuf); if ( fbuf.st_nlink <= 1 || lbuf.st_nlink <= 1 || (fbuf.st_nlink != lbuf.st_nlink) ) { tst_resm(TFAIL, "link(%s, %s[1-%d]) ret %d for %d files, stat values do not match %d %d", Fname, Basename, nlinks, TEST_RETURN, nlinks, fbuf.st_nlink, lbuf.st_nlink); break; } } if ( cnt >= nlinks ) { tst_resm(TPASS, "link(%s, %s[1-%d]) ret %d for %d files, stat linkcounts match %d", Fname, Basename, nlinks, TEST_RETURN, nlinks, fbuf.st_nlink); } } else Tst_count++; for(cnt=1; cnt < nlinks; cnt++) { sprintf(lname, "%s%d", Basename, cnt); if (unlink(lname) == -1) { tst_res(TWARN, "unlink(%s) Failed, errno=%d : %s", Fname, errno, strerror(errno)); } } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { struct stat stat_buf; /* stat(2) struct contents */ int lc, i; /* loop counter */ char *msg; /* message returned from parse_opts */ off_t file_length2; /* test file length */ off_t file_length1; /* test file length */ int rbytes; /* bytes read from testfile */ int read_len = 0; /* total no. of bytes read from testfile */ int err_flag = 0; /* error indicator flag */ /* Parse standard options given to run the test. */ msg = parse_opts(ac, av, (option_t *) NULL, NULL); if (msg != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } /* Perform global setup for test */ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /* Check looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* Reset Tst_count in case we are looping. */ Tst_count = 0; /* * Call truncate(2) to truncate a test file to a * specified length (TRUNC_LEN1). */ TEST(truncate(TESTFILE, TRUNC_LEN1)); /* check return code of truncate(2) */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "truncate(%s, %d) Failed, errno=%d : %s", TESTFILE, TRUNC_LEN1, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Get the testfile information using * stat(2). */ if (stat(TESTFILE, &stat_buf) < 0) { tst_brkm(TFAIL, cleanup, "stat(2) of " "%s failed after 1st truncate, " "error:%d", TESTFILE, errno); /*NOTREACHED*/} file_length1 = stat_buf.st_size; /* * Set the file pointer of testfile to the * beginning of the file. */ if (lseek(fd, 0, SEEK_SET) < 0) { tst_brkm(TFAIL, cleanup, "lseek(2) on " "%s failed after 1st truncate, " "error:%d", TESTFILE, errno); /*NOTREACHED*/} /* Read the testfile from the beginning. */ while ((rbytes = read(fd, tst_buff, sizeof(tst_buff))) > 0) { read_len += rbytes; } /* * Execute truncate(2) again to truncate * testfile to a size TRUNC_LEN2. */ TEST(truncate(TESTFILE, TRUNC_LEN2)); /* check return code of truncate(2) */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "truncate of %s to " "size %d Failed, errno=%d : %s", TESTFILE, TRUNC_LEN2, TEST_ERRNO, strerror(TEST_ERRNO)); } /* * Get the testfile information using * stat(2) */ if (stat(TESTFILE, &stat_buf) < 0) { tst_brkm(TFAIL, cleanup, "stat(2) of " "%s failed after 2nd truncate, " "error:%d", TESTFILE, errno); /*NOTREACHED*/} file_length2 = stat_buf.st_size; /* * Set the file pointer of testfile to the * offset TRUNC_LEN1 of testfile. */ if (lseek(fd, TRUNC_LEN1, SEEK_SET) < 0) { tst_brkm(TFAIL, cleanup, "lseek(2) on " "%s failed after 2nd truncate, " "error:%d", TESTFILE, errno); /*NOTREACHED*/} /* Read the testfile contents till EOF */ while ((rbytes = read(fd, tst_buff, sizeof(tst_buff))) > 0) { for (i = 0; i < rbytes; i++) { if (tst_buff[i] != 0) { err_flag++; } } } /* * Check for expected size of testfile after * issuing truncate(2) on it. */ if ((file_length1 != TRUNC_LEN1) || (file_length2 != TRUNC_LEN2) || (read_len != TRUNC_LEN1) || (err_flag != 0)) { tst_resm(TFAIL, "Functionality of " "truncate(2) on %s Failed", TESTFILE); } else { tst_resm(TPASS, "Functionality of truncate(2) " "on %s successful", TESTFILE); } } else { tst_resm(TPASS, "%s call succeeded", TCID); } } Tst_count++; /* incr. TEST_LOOP counter */ } /* End for TEST_LOOPING */ /* Call cleanup() to undo setup done for the test. */ cleanup(); /*NOTREACHED*/ return 0; } /* End main */
int main(int ac, char **av) { int lc; char *msg; int count, rval, fd; size_t size = 0; char *dir_name = NULL; struct dirent *dirp; struct stat *sbuf; char *newfile; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; if ((dir_name = getcwd(dir_name, size)) == NULL) tst_brkm(TBROK, cleanup, "Can not get current " "directory name"); if ((dirp = malloc(sizeof(struct dirent))) == NULL) tst_brkm(TBROK, cleanup, "malloc failed"); count = (int)sizeof(struct dirent); /* set up some space for a file name */ if ((newfile = malloc(sizeof(char) * 20)) == NULL) tst_brkm(TBROK, cleanup, "newfile malloc failed"); if ((rval = sprintf(newfile, "getdents03.%d", getpid())) < 0) tst_brkm(TBROK, cleanup, "sprintf failed"); if ((fd = open(newfile, O_CREAT | O_RDWR, 0777)) == -1) tst_brkm(TBROK|TERRNO, cleanup, "open of file failed"); /* set up some space for the stat buffer */ if ((sbuf = malloc(sizeof(struct stat))) == NULL) tst_brkm(TBROK, cleanup, "stat malloc failed"); /* make sure fd is not a directory */ if ((rval = fstat(fd, sbuf)) == -1) tst_brkm(TBROK, cleanup, "fstat failed"); if (S_ISDIR(sbuf->st_mode)) tst_brkm(TBROK, cleanup, "fd is a directory"); rval = getdents(fd, dirp, count); /* * Calling with a non directory file descriptor should give * an ENOTDIR error. */ if (rval < 0) { TEST_ERROR_LOG(errno); switch (errno) { case ENOTDIR: tst_resm(TPASS, "getdents failed as expected with ENOTDIR"); break; default: tst_resm(TFAIL|TERRNO, "getdents failed unexpectedly"); break; } } else tst_resm(TFAIL, "getdents call succeeded unexpectedly"); free(dir_name); dir_name = NULL; free(dirp); if ((rval = close(fd)) == -1) tst_brkm(TBROK, cleanup, "fd close failed"); if ((rval = unlink(newfile)) == -1) tst_brkm(TBROK, cleanup, "file unlink failed"); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; int fails; int kid_status, wait_status; msg = parse_opts(ac, av, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; fails = 0; TEST(fork()); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); if (STD_FUNCTIONAL_TEST) { tst_resm(TFAIL, "fork() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); tst_resm(TBROK, "unable to continue"); } } if (TEST_RETURN == 0) { /* child */ if (STD_FUNCTIONAL_TEST) child_pid(); exit(KIDEXIT); } else { /* parent */ if (STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "fork() returned %ld", TEST_RETURN); } /* wait for the child to complete */ wait_status = waitpid(TEST_RETURN, &kid_status, 0); if (STD_FUNCTIONAL_TEST) { if (wait_status == TEST_RETURN) { if (kid_status != KIDEXIT << 8) { tst_resm(TBROK, "incorrect child status returned on wait(): %d", kid_status); fails++; } } else { tst_resm(TBROK, "wait() for child status failed with %d errno: %d : %s", wait_status, errno, strerror(errno)); fails++; } if (fails == 0) { /* verification tests */ parent_pid(); } } /* STD_FUNCTIONAL_TEST */ } /* TEST_RETURN */ } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /* * check if the current filesystem is nfs */ if (tst_is_cwd_nfs()) { tst_brkm(TCONF, cleanup, "Cannot do fcntl on a file located on an NFS filesystem"); } /* * check if the current filesystem is tmpfs */ if (tst_is_cwd_tmpfs()) { tst_brkm(TCONF, cleanup, "Cannot do fcntl on a file located on an TMPFS filesystem"); } /* * check if the current filesystem is ramfs */ if (tst_is_cwd_ramfs()) { tst_brkm(TCONF, cleanup, "Cannot do fcntl on a file located on an RAMFS filesystem"); } /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; #ifdef F_SETLEASE /* * Call fcntl(2) with F_SETLEASE & F_WRLCK argument on fname */ TEST(fcntl(fd, F_SETLEASE, F_WRLCK)); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "fcntl(%s, F_SETLEASE, F_WRLCK) Failed, errno=%d : %s", fname, TEST_ERRNO, strerror(TEST_ERRNO)); } else { if (STD_FUNCTIONAL_TEST) { TEST(fcntl(fd, F_GETLEASE)); if (TEST_RETURN != F_WRLCK) tst_resm(TFAIL, "fcntl(%s, F_GETLEASE) did not return F_WRLCK, returned %ld", fname, TEST_RETURN); else { TEST(fcntl(fd, F_SETLEASE, F_UNLCK)); if (TEST_RETURN != 0) tst_resm(TFAIL, "fcntl(%s, F_SETLEASE, F_UNLCK) did not return 0, returned %ld", fname, TEST_RETURN); else tst_resm(TPASS, "fcntl(%s, F_SETLEASE, F_WRLCK)", fname); } } } #else tst_resm(TINFO, "F_SETLEASE not defined, skipping test"); #endif } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; pid_t pid, pid1; int retval = 3, status; char *argv[1], *env[1]; if ((msg = parse_opts(ac, av, options, &help)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); #ifdef UCLINUX maybe_run_child(&do_child_1, "nS", 1, &test_app); #endif if (!Fflag) tst_brkm(TBROK, NULL, "You must specify an executable file with the -F option."); setup(*av); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; if (sync_pipe_create(start_sync_pipes, PIPE_NAME_START) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_create failed"); if (sync_pipe_create(end_sync_pipes, PIPE_NAME_END) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_create failed"); /* * to test whether execve(2) sets ETXTBSY when a second * child process attempts to execve the executable opened * by the first child process */ if ((pid = FORK_OR_VFORK()) == -1) tst_brkm(TBROK, cleanup, "fork #1 failed"); else if (pid == 0) { #ifdef UCLINUX if (self_exec(av[0], "nS", 1, test_app) < 0) tst_brkm(TBROK, cleanup, "self_exec failed"); #else do_child_1(); #endif } if (sync_pipe_wait(start_sync_pipes) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_wait failed"); if (sync_pipe_close(start_sync_pipes, PIPE_NAME_START) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_close failed"); if ((pid1 = FORK_OR_VFORK()) == -1) tst_brkm(TBROK, cleanup, "fork #2 failed"); if (pid1 == 0) { retval = 3; argv[0] = 0; env[0] = 0; /* do not interfere with end synchronization of first * child */ sync_pipe_close(end_sync_pipes, PIPE_NAME_END); TEST(execve(test_app, argv, env)); TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO != ETXTBSY) { retval = 1; perror("didn't get ETXTBSY\n"); } else printf("execve failed with ETXTBSY as " "expected\n"); exit(retval); } /* wait for the child to finish */ if (waitpid(pid1, &status, 0) == -1) tst_brkm(TBROK|TERRNO, cleanup, "waitpid failed"); if (WIFEXITED(status) && WEXITSTATUS(status) == 3) tst_resm(TPASS, "execve failed as expected"); else tst_resm(TFAIL, "execve succeeded, expected failure"); /* terminate first child */ sync_pipe_notify(end_sync_pipes); (void) waitpid(pid, NULL, 0); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ pid_t pid, fake_pid; int exno, status, fake_status, nsig; /* parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } #ifdef UCLINUX maybe_run_child(&do_child, ""); #endif setup(); /* global setup */ TEST_EXP_ENOS(exp_enos); /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; status = 1; exno = 1; pid = FORK_OR_VFORK(); if (pid < 0) { tst_brkm(TBROK, cleanup, "Fork failed"); } else if (pid == 0) { #ifdef UCLINUX if (self_exec(av[0], "") < 0) { tst_brkm(TBROK, cleanup, "self_exec of child failed"); } #else do_child(); #endif } else { fake_pid = FORK_OR_VFORK(); if (fake_pid < 0) { tst_brkm(TBROK, cleanup, "Second fork failed"); } else if (fake_pid == 0) { #ifdef UCLINUX if (self_exec(av[0], "") < 0) { tst_brkm(TBROK, cleanup, "second self_exec " "of child failed"); } #else do_child(); #endif } kill(fake_pid, TEST_SIG); waitpid(fake_pid, &fake_status, 0); TEST(kill(fake_pid, TEST_SIG)); kill(pid, TEST_SIG); waitpid(pid, &status, 0); } if (TEST_RETURN != -1) { tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s " "Expected a return value of -1 got %ld", TCID, TEST_ERRNO, strerror(TEST_ERRNO), TEST_RETURN); } if (STD_FUNCTIONAL_TEST) { /* * Check to see if the errno was set to the expected * value of 3 : ESRCH */ nsig = WTERMSIG(status); TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == ESRCH) { tst_resm(TPASS, "errno set to %d : %s, as " "expected", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TFAIL, "errno set to %d : %s expected " "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO), 3, strerror(3)); } } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; const char *msg; /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { int type; for (type = 0; type < 2; type++) { tst_count = 0; flocks.l_type = type ? F_RDLCK : F_WRLCK; /* * Call fcntl(2) with F_SETLKW flocks.l_type = F_UNLCK argument on fname */ TEST(fcntl(fd, F_SETLKW, &flocks)); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "fcntl(%s, F_SETLKW, &flocks) flocks.l_type = %s Failed, errno=%d : %s", fname, type ? "F_RDLCK" : "F_WRLCK", TEST_ERRNO, strerror(TEST_ERRNO)); } else { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, "fcntl(%s, F_SETLKW, &flocks) flocks.l_type = %s returned %ld", fname, type ? "F_RDLCK" : "F_WRLCK", TEST_RETURN); } } flocks.l_type = F_UNLCK; /* * Call fcntl(2) with F_SETLKW flocks.l_type = F_UNLCK argument on fname */ TEST(fcntl(fd, F_SETLKW, &flocks)); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "fcntl(%s, F_SETLKW, &flocks) flocks.l_type = F_UNLCK Failed, errno=%d : %s", fname, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, "fcntl(%s, F_SETLKW, &flocks) flocks.l_type = F_UNLCK returned %ld", fname, TEST_RETURN); } } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; const char *msg; struct itimerval *value, *ovalue; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); /* global setup */ /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset tst_count in case we are looping */ tst_count = 0; /* allocate some space for timer structures */ if ((value = (struct itimerval *)malloc((size_t) sizeof(struct itimerval))) == NULL) { tst_brkm(TBROK, cleanup, "value malloc failed"); } if ((ovalue = (struct itimerval *)malloc((size_t) sizeof(struct itimerval))) == NULL) { tst_brkm(TBROK, cleanup, "value malloc failed"); } /* set up some reasonable values */ value->it_value.tv_sec = 30; value->it_value.tv_usec = 0; value->it_interval.tv_sec = 0; value->it_interval.tv_usec = 0; /* * issue the system call with the TEST() macro * ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 */ /* make the first value negative to get a failure */ TEST(setitimer(-ITIMER_PROF, value, ovalue)); if (TEST_RETURN == 0) { tst_resm(TFAIL, "call failed to produce expected error " "- errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); continue; } TEST_ERROR_LOG(TEST_ERRNO); switch (TEST_ERRNO) { case EINVAL: tst_resm(TPASS, "expected failure - errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); break; default: tst_resm(TFAIL, "call failed to produce expected error " "- errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); } /* * clean up things in case we are looping */ free(value); free(ovalue); value = NULL; ovalue = NULL; } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; int rval, fd; int count; size_t size = 0; char *dir_name = NULL; struct dirent *dirp; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; if ((dir_name = getcwd(dir_name, size)) == NULL) tst_brkm(TBROK, cleanup, "Can not get current " "directory name"); if ((dirp = malloc(sizeof(struct dirent))) == NULL) tst_brkm(TBROK, cleanup, "malloc failed"); /* Set count to be very small. The result should be EINVAL */ count = 1; if ((fd = open(dir_name, O_RDONLY)) == -1) tst_brkm(TBROK, cleanup, "open of directory failed"); rval = getdents(fd, dirp, count); /* * Hopefully we get an error due to the small buffer. */ if (rval < 0) { TEST_ERROR_LOG(errno); switch (errno) { case EINVAL: tst_resm(TPASS, "getdents failed with EINVAL as expected"); break; default: tst_resm(TFAIL|TERRNO, "getdents call failed unexpectedly"); break; } } else tst_resm(TFAIL, "getdents passed unexpectedly"); free(dir_name); dir_name = NULL; free(dirp); if ((rval = close(fd)) == -1) tst_brkm(TBROK, cleanup, "fd close failed"); } cleanup(); tst_exit(); }
int main(int argc, char **argv) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ /* parse standard options */ if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); /* set "tstdir", and "testfile" vars */ /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; fd[1] = -1; /* Invalid file descriptor */ if (signal(SIGTERM, sighandler) == SIG_ERR) { perror("signal"); tst_resm(TFAIL, "signal() SIGTERM FAILED"); cleanup(); } if (signal(SIGPIPE, sighandler) == SIG_ERR) { perror("signal"); tst_resm(TFAIL, "signal() SIGPIPE FAILED"); cleanup(); } if ((fd[0] = open(f_name, O_WRONLY | O_CREAT, 0666)) < 0) { tst_resm(TFAIL, "open(2) failed: fname = %s, " "errno = %d", f_name, errno); cleanup(); } /* * Iovecs passed to writev points to valid (readable) regions, * so all bytes must be successfully written. */ //block1: tst_resm(TINFO, "Enter block 1"); fail = 0; TEST(writev(fd[0], wr_iovec, 2)); if (TEST_RETURN >= 0) { if (TEST_RETURN == 2) { tst_resm(TINFO, "writev returned %d as expected", 2); } else { tst_resm(TFAIL, "Expected nbytes = %d, got " "%ld", 2, TEST_RETURN); fail = 1; } } else { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL|TTERRNO, "Error writev return value = %ld", TEST_RETURN); fail = 1; } if (fail) { tst_resm(TINFO, "block 1 FAILED"); } else { tst_resm(TINFO, "block 1 PASSED"); } tst_resm(TINFO, "Exit block 1"); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; pid_t cpid; /* process id of the child process */ int exit_status; /* exit status of child process */ sigset_t PendSig; /* variable to hold pending signal */ msg = parse_opts(ac, av, NULL, NULL); if (msg != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Call vfork(2) to create a child process without * fully copying the address space of parent. */ TEST(vfork()); if ((cpid = TEST_RETURN) == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "vfork() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else if (cpid == 0) { /* Child process */ /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Check whether the pending signal SIGUSR1 * in the parent is also pending in the child * process by storing it in a variable. */ if (sigpending(&PendSig) == -1) { tst_resm(TFAIL, "sigpending function " "failed in child"); _exit(1); } /* Check if SIGUSR1 is pending in child */ if (sigismember(&PendSig, SIGUSR1) != 0) { tst_resm(TFAIL, "SIGUSR1 also pending " "in child process"); _exit(1); } /* * Exit with normal exit code if everything * fine */ _exit(0); } } else { /* parent process */ /* * Let the parent process wait till child completes * its execution. */ wait(&exit_status); /* Check for the exit status of child process */ if (WEXITSTATUS(exit_status) == 0) { tst_resm(TPASS, "Call to vfork() " "successful"); } else if (WEXITSTATUS(exit_status) == 1) { tst_resm(TFAIL, "Child process exited abnormally"); } } tst_count++; /* incr. TEST_LOOP counter */ } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * TEST CASE: 1 * mkdir() call with pointer below allocated address space. */ /* Call mkdir(2) */ TEST(mkdir(bad_addr, 0777)); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); } if (STD_FUNCTIONAL_TEST) { if (TEST_RETURN == -1) { if (TEST_ERRNO == EFAULT) { tst_resm(TPASS, "mkdir - path argument pointing below allocated address space failed as expected with errno %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TFAIL, "mkdir - path argument pointing below allocated address space failed with errno %d : %s but expected %d (EFAULT)", TEST_ERRNO, strerror(TEST_ERRNO), EFAULT); } } else { tst_resm(TFAIL, "mkdir - path argument pointing below allocated address space succeeded unexpectedly."); } } #if !defined(UCLINUX) /* * TEST CASE: 2 * mkdir() call with pointer above allocated address space. */ /* Call mkdir(2) */ TEST(mkdir(get_high_address(), 0777)); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); } if (STD_FUNCTIONAL_TEST) { if (TEST_RETURN == -1) { if (TEST_ERRNO == EFAULT) { tst_resm(TPASS, "mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TFAIL, "mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)", TEST_ERRNO, strerror(TEST_ERRNO), EFAULT); } } else { tst_resm(TFAIL, "mkdir - path argument pointing above allocated address space succeeded unexpectedly."); } } #endif /* if !defined(UCLINUX) */ } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ const char *msg; /* message returned from parse_opts */ /*************************************************************** * parse standard options ***************************************************************/ if ( (msg=parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *) NULL ) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc=0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count=0; /* * TEST CASE: * Set the effective user ID to the current real uid */ uid=getuid(); /* Call setuid(2) */ TEST(setuid(uid)); /* check return code */ if ( TEST_RETURN == -1 ) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setuid - Set the effective user ID to the current real uid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if ( STD_FUNCTIONAL_TEST ) { /* No Verification test, yet... */ tst_resm(TPASS, "setuid - Set the effective user ID to the current real uid returned %d", TEST_RETURN); } } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int i; /* * parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } /* * perform global setup for test */ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /* * check looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* loop through the test cases */ for (i = 0; i < TST_TOTAL; i++) { /* perform test specific setup if necessary */ if (TC[i].setupfunc != NULL) { (*TC[i].setupfunc) (); } TEST(mkdir(TC[i].dir, TC[i].perms)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == TC[i].error) { tst_resm(TPASS, "expected failure - " "errno = %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TFAIL, "unexpected error - %d : %s - " "expected %d", TEST_ERRNO, strerror(TEST_ERRNO), TC[i].error); } } } /* * cleanup and exit */ cleanup(); tst_exit(); }
int main(int ac, char **av) { struct stat stat_buf; /* stat structure buffer */ int lc; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Call stat(2) to get the status of * specified 'file' into stat structure. */ TEST(stat(TESTFILE, &stat_buf)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "stat(%s, &stat_buf) Failed, errno=%d : %s", TESTFILE, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { stat_buf.st_mode &= ~S_IFREG; /* * Verify the data returned by stat(2) * aganist the expected data. */ if ((stat_buf.st_uid != user_id) || (stat_buf.st_gid != group_id) || (stat_buf.st_size != FILE_SIZE) || ((stat_buf.st_mode & MASK) != NEW_MODE)) { tst_resm(TFAIL, "Functionality of " "stat(2) on '%s' Failed", TESTFILE); } else { tst_resm(TPASS, "Functionality of " "stat(2) on '%s' Succcessful", TESTFILE); } } else { tst_resm(TPASS, "Call succeeded"); } } tst_count++; /* incr TEST_LOOP counter */ } cleanup(); tst_exit(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ TST_TOTAL = (sizeof(tcases) / sizeof(tcases[0])); /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count = 0; /* * TEST CASES: * Make nodes in tcases array */ for (i = 0; i < TST_TOTAL; i++) { /* Call mknod(2) */ TEST(mknod(Path, tcases[i], 0)); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "mknod(%s, %#o, 0) failed, errno=%d : %s", Path, tcases[i], TEST_ERRNO, strerror(TEST_ERRNO)); } else { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, "mknod(%s, %#o, 0) returned %ld", Path, tcases[i], TEST_RETURN); } } /* remove the node for the next go `round */ if (unlink(Path) == -1) { if (rmdir(Path) == -1) { tst_resm(TWARN, "unlink(%s) & rmdir(%s) failed, errno:%d %s", Path, Path, errno, strerror(errno)); } } } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { int lc; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { int i; /* reset Tst_count in case we are looping */ Tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective user id */ TEST(setreuid(*test_data[i].real_uid, *test_data[i].eff_uid)); if (TEST_RETURN == *test_data[i].exp_ret) { if (TEST_RETURN == neg_one) { if (TEST_ERRNO != EPERM) { tst_resm(TFAIL, "setreuid(%d, %d) " "did not set errno " "value as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); continue; } tst_resm(TPASS, "setreuid(%d, %d) " "failed as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } else { tst_resm(TPASS, "setreuid(%d, %d) " "succeeded as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } } else { tst_resm(TFAIL, "setreuid(%d, %d) " "did not return as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); } /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { uid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, test_data[i].test_msg); } } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc, i; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; i < TST_TOTAL; ++i) { /* * since Linux 2.6.26, if buf.offset value is outside * the acceptable range, it is simply normalized instead * of letting the syscall fail. so just skip this test * case. */ if ((i == 3 || i == 4) && tst_kvercmp(2, 6, 25) > 0) { tst_resm(TCONF, "this kernel normalizes buf." "offset value if it is outside" " the acceptable range."); continue; } buff = tim_save; buff.modes = SET_MODE; if ((test_cases[i].setup) && (test_cases[i].setup())) { tst_resm(TWARN, "setup() failed, skipping" " this test case"); continue; } /* Call adjtimex(2) */ TEST(adjtimex(test_cases[i].buffp)); if ((TEST_RETURN == -1) && (TEST_ERRNO == test_cases[i].exp_errno)) { tst_resm(TPASS | TTERRNO, "Test Passed, adjtimex() returned -1"); } else { tst_resm(TFAIL | TTERRNO, "Test Failed, adjtimex() returned %ld", TEST_RETURN); } TEST_ERROR_LOG(TEST_ERRNO); if (test_cases[i].cleanup) { test_cases[i].cleanup(); } } } /* cleanup and exit */ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ /*************************************************************** * parse standard options ***************************************************************/ if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc=0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count=0; /* * Call open(2) */ TEST(open(fname,O_RDWR|O_CREAT,0700)); fd=TEST_RETURN; /* check return code */ if ( TEST_RETURN == -1 ) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "open(%s,O_RDWR|O_CREAT,0700) Failed, errno=%d : %s", fname, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if ( STD_FUNCTIONAL_TEST ) { /* No Verification test, yet... */ tst_resm(TPASS, "open(%s, O_RDWR|O_CREAT,0700) returned %d", fname, TEST_RETURN); } if (close(fd) == -1) { tst_brkm(TBROK, cleanup, "close(%s) Failed, errno=%d : %s", fname, errno, strerror(errno)); } else if (unlink(fname) == -1) { tst_brkm(TBROK, cleanup, "unlink(%s) Failed, errno=%d : %s", fname, errno, strerror(errno)); } } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { int lc, i; char *msg; if ((msg = parse_opts(ac, av, options, &help)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } /* Check for mandatory option of the testcase */ if (Dflag == 0) { tst_brkm(TBROK, NULL, "You must specifiy the device used for " " mounting with -D option, Run '%s -h' for option " " information.", TCID); tst_exit(); } if (STD_COPIES != 1) { tst_resm(TINFO, "-c option has no effect for this testcase - " "%s doesn't allow running more than one instance " "at a time", TCID); STD_COPIES = 1; } setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; i < TST_TOTAL; ++i) { if (setup_test(i, lc)) { tst_resm(TWARN, "Not able to test mount(2) for " "error %s as setup failed", testcases[i].exp_errval); continue; } /* Call umount(2) to test different test conditions. * verify that it fails with -1 return value and * sets appropriate errno.*/ TEST(umount(Mntpoint)); /* check return code */ if ((TEST_RETURN == -1) && (TEST_ERRNO == testcases[i].exp_errno)) { tst_resm(TPASS, "umount(2) expected failure; " "Got errno - %s : %s", testcases[i].exp_errval, testcases[i].err_desc); } else { tst_resm(TFAIL, "umount(2) failed to produce " "expected error; %d, errno:%s got %d", testcases[i].exp_errno, testcases[i].exp_errval, TEST_ERRNO); } TEST_ERROR_LOG(TEST_ERRNO); cleanup_test(i); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ void *alt_stk; /* address of alternate stack for signal */ /* Parse standard options given to run the test. */ msg = parse_opts(ac, av, (option_t *) NULL, NULL); if (msg != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); /*NOTREACHED*/} /* Perform global setup for test */ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /* Check looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* Reset Tst_count in case we are looping. */ Tst_count = 0; /* Call sigaltstack() to set up an alternate stack */ sigstk.ss_size = SIGSTKSZ; sigstk.ss_flags = 0; TEST(sigaltstack(&sigstk, &osigstk)); /* check return code of sigaltstack */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "sigaltstack() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* Set up the signal handler for 'SIGUSR1' */ act.sa_flags = SA_ONSTACK; act.sa_handler = (void (*)())sig_handler; if ((sigaction(SIGUSR1, &act, &oact)) == -1) { tst_brkm(TFAIL, cleanup, "sigaction() " "fails to trap signal " "delivered on alt. stack, " "error=%d", errno); } /* Deliver signal onto the alternate stack */ kill(my_pid, SIGUSR1); /* wait till the signal arrives */ while (!got_signal) ; got_signal = 0; alt_stk = addr; /* * First, * Check that alt_stk is within the * alternate stk boundaries * * Second, * Check that main_stk is outside the * alternate stk boundaries. */ if ((alt_stk < sigstk.ss_sp) || (alt_stk > (sigstk.ss_sp + SIGSTKSZ))) { tst_resm(TFAIL, "alt. stack is not within the " "alternate stk boundaries"); } else if ((main_stk >= sigstk.ss_sp) && (main_stk <= (sigstk.ss_sp + SIGSTKSZ))) { tst_resm(TFAIL, "main stk. not outside the " "alt. stack boundaries"); } else { tst_resm(TPASS, "Functionality of " "sigaltstack() successful"); } } else { tst_resm(TPASS, "CALL succeeded."); } } Tst_count++; /* incr. TEST_LOOP counter */ } /* End for TEST_LOOPING */ /* Call cleanup() to undo setup done for the test. */ cleanup(); /*NOTREACHED*/ return 0; } /* End main */
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ pid_t pid; int status; /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); } setup(); /* set up the expected errnos */ TEST_EXP_ENOS(exp_enos); /* check for looping state if -i option is given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; if ((pid = FORK_OR_VFORK()) < 0) { tst_brkm(TBROK, cleanup, "fork failed"); } if (pid == 0) { /* child */ /* * set the child's ID to ltpuser1 using seteuid() * so that the ID can be changed back after the * TEST call is made. */ if (seteuid(ltpuser1->pw_uid) != 0) { tst_resm(TINFO, "setreuid failed in child #1"); exit(1); } if (mkdir(good_dir, 00400) != 0) { tst_resm(TINFO, "mkdir failed in child #1"); exit(1); } if ((fd = open(good_dir, O_RDONLY)) == -1) { tst_brkm(TBROK, cleanup, "open of directory failed"); } TEST(fchdir(fd)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); } else if (TEST_ERRNO != EACCES) { tst_resm(TFAIL, "expected EACCES - got %d", TEST_ERRNO); } else { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TPASS, "expected failure - errno = %d" " : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } /* reset the process ID to the saved ID (root) */ if (setuid(0) == -1) { tst_resm(TINFO, "setuid(0) failed"); } } else { /* parent */ wait(&status); /* let the child carry on */ exit(0); } /* clean up things in case we are looping */ if (rmdir(good_dir) == -1) { tst_brkm(TBROK, cleanup, "Couldn't remove directory"); } } cleanup(); /*NOTREACHED*/ return 0; }
int main(int ac, char **av) { int lc; char *msg; /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; (void)signal(SIGALRM, go); alarm(1); /* * Call pause(2) */ TEST(pause()); /* check return code. Pause returns -1 and EINTR errno */ if (TEST_RETURN != -1) { tst_resm(TFAIL, "pause() returned WITHOUT an error return code : %d", TEST_ERRNO); } else { /* log the errno */ TEST_ERROR_LOG(TEST_ERRNO); /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* check the errno */ if (TEST_ERRNO == EINTR) tst_resm(TPASS, "pause() returned %ld", TEST_RETURN); else tst_resm(TFAIL, "pause() returned %ld. Expected %d (EINTR)", TEST_RETURN, EINTR); } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ int retval = 0; char *msg; /* message returned from parse_opts */ pid_t pid, pid1; int i, status, fd; /* parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK|TERRNO, cleanup, "fork() #1 failed"); } if (pid == 0) { /* first child */ if (mkdir(good_dir, DMODE) != 0) { perror("mkdir() failed"); exit(1); } if ((fd = open(fname1, O_RDWR | O_CREAT, 0444)) == -1) { perror("open failed"); exit(1); } exit(0); } wait(&status); /* make sure the child returned a good exit status */ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { tst_brkm(TBROK, cleanup, "child #1 failed"); } if ((pid1 = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK|TERRNO, cleanup, "fork() #2 failed"); } if (pid1 == 0) { /* second child */ ltpuser1 = my_getpwnam(user1name); if (ltpuser1 == NULL) { perror("getpwnam"); exit(1); } if (seteuid(ltpuser1->pw_uid) == -1) { perror("seteuid"); exit(1); } /* loop through the test cases */ for (i = 0; i < TST_TOTAL; i++) { TEST(creat(TC[i].fname, FMODE)); if (TEST_RETURN != -1) { retval = 1; tst_resm(TFAIL, "call succeeded " "unexpectedly"); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO != EACCES) { retval = 1; tst_resm(TFAIL|TTERRNO, "Expected EACCES"); } else { tst_resm(TPASS, "call failed with " "EACCES as expected"); } } seteuid(0); /* clean up things in case we are looping */ unlink(fname); unlink(fname1); rmdir(good_dir); exit(retval); } else { /* parent */ /* wait for the child to finish */ wait(&status); /* make sure the child returned a good exit status */ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { tst_resm(TFAIL, "see failures reported above"); } } } cleanup(); tst_exit(); }