int main(int ac, char **av) { int fd0, fd1, fd2, rval; char filename0[40], filename1[40]; char buf[40]; int lc; const 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; //block1: tst_resm(TINFO, "Enter block 1"); tst_resm(TINFO, "Test duping over an open fd"); sprintf(filename0, "dup202.file0.%d\n", getpid()); sprintf(filename1, "dup202.file1.%d\n", getpid()); unlink(filename0); unlink(filename1); if ((fd0 = creat(filename0, 0666)) == -1) tst_brkm(TBROK, cleanup, "cannot create first file"); if (write(fd0, filename0, strlen(filename0)) == -1) tst_brkm(TBROK, cleanup, "filename0: write(2) failed"); if ((fd1 = creat(filename1, 0666)) == -1) tst_brkm(TBROK, cleanup, "Cannot create second file"); if (write(fd1, filename1, strlen(filename1)) == -1) tst_brkm(TBROK, cleanup, "filename1: write(2) failed"); if (close(fd0) == -1) tst_brkm(TBROK, cleanup, "close(2) fd0 failed"); if ((fd0 = open(filename0, O_RDONLY)) == -1) tst_brkm(TBROK, cleanup, "open(2) on filename0 failed"); if (close(fd1) == -1) tst_brkm(TBROK, cleanup, "close(2) fd1 failed"); if ((fd1 = open(filename1, O_RDONLY)) == -1) tst_brkm(TBROK, cleanup, "open(2) on filename1 failed"); TEST(dup2(fd0, fd1)); if ((fd2 = TEST_RETURN) == -1) { tst_resm(TFAIL, "call failed unexpectedly"); } else { if (fd1 != fd2) { tst_resm(TFAIL, "file descriptors don't match"); break; } memset(buf, 0, sizeof(buf)); if (read(fd2, buf, sizeof(buf)) == -1) tst_brkm(TBROK, cleanup, "read(2) failed"); if (strcmp(buf, filename0) != 0) tst_resm(TFAIL, "read from file got bad data"); tst_resm(TPASS, "dup2 test 1 functionality is correct"); } close(fd0); close(fd1); close(fd2); unlink(filename0); unlink(filename1); tst_resm(TINFO, "Exit block 1"); //block2: tst_resm(TINFO, "Enter block 2"); tst_resm(TINFO, "Test close on exec flag"); sprintf(filename0, "dup02.%d\n", getpid()); unlink(filename0); if ((fd0 = creat(filename0, 0666)) == -1) { tst_brkm(TBROK, cleanup, "Cannot create first file"); } if (fcntl(fd0, F_SETFD, 1) == -1) { tst_brkm(TBROK, cleanup, "setting close on exec flag " "on fd0 failed"); } if ((fd2 = creat(filename1, 0666)) == -1) { tst_brkm(TBROK, cleanup, "Cannot create second file"); } if (close(fd2) == -1) { tst_brkm(TBROK, cleanup, "close(2) fd_closed failed"); } TEST(dup2(fd0, fd2)); if ((fd1 = TEST_RETURN) == -1) { tst_resm(TFAIL, "call failed unexpectedly"); } else { if (fd1 != fd2) { tst_resm(TFAIL, "bad dup2 descriptor %d", fd1); break; } if ((rval = fcntl(fd1, F_GETFD, 0)) != 0) { tst_resm(TBROK | TERRNO, "fcntl F_GETFD on fd1 failed; expected a " "return value of 0x0, got %#x", rval); break; } if ((rval = (fcntl(fd0, F_GETFL, 0) & O_ACCMODE)) != O_WRONLY) { tst_resm(TFAIL, "fctnl F_GETFL bad rval on fd0 " "Expected %#x got %#x", O_WRONLY, rval); } tst_resm(TPASS, "dup2 test 2 functionality is correct"); } close(fd0); close(fd1); unlink(filename0); unlink(filename1); tst_resm(TINFO, "Exit block 2"); } cleanup(); tst_exit(); }
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(); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { 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 %ld", TEST_RETURN); } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ /* Parse standard options given to run the test. */ msg = parse_opts(ac, av, (option_t *)NULL, NULL); if (msg != (char *)NULL) { tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); } 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; /* Perform global setup for test */ setup(); /* * Call msync to synchronize the mapped region * with the specified file using invalid flag. * INV_SYNC. */ TEST(msync(addr, page_sz, INV_SYNC)); /* Check for the return value of msync() */ if (TEST_RETURN != -1) { tst_resm(TFAIL, "msync() returns unexpected value %d, " "expected:-1", TEST_RETURN); continue; } TEST_ERROR_LOG(TEST_ERRNO); /* * Verify whether expected errno is * set (EINVAL). */ if (TEST_ERRNO == EINVAL) { tst_resm(TPASS, "mapped region is private and cannot " "sync, errno:%d", TEST_ERRNO); } else { tst_resm(TFAIL, "msync() failed, unexpected errno:%d, " "expected: EINVAL", TEST_ERRNO); } /* Call cleanup() to undo setup done for the test. */ cleanup(); } /* End for TEST_LOOPING */ /* exit with return code appropriate for results */ tst_exit(); /*NOTREACHED*/ return(0); } /* End main */
int main(int ac, char **av) { int lc; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Call mmap to map the temporary file beyond EOF * with write access. */ errno = 0; addr = mmap(addr, page_sz, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED | MAP_FIXED, fildes, 0); /* Check for the return value of mmap() */ if (addr == MAP_FAILED) { tst_resm(TFAIL | TERRNO, "mmap of %s failed", TEMPFILE); continue; } /* * Check if mapped memory area beyond EOF are * zeros and changes beyond EOF are not written * to file. */ if (memcmp(&addr[file_sz], dummy, page_sz - file_sz)) { tst_brkm(TFAIL, cleanup, "mapped memory area contains invalid " "data"); } /* * Initialize memory beyond file size */ addr[file_sz] = 'X'; addr[file_sz + 1] = 'Y'; addr[file_sz + 2] = 'Z'; /* * Synchronize the mapped memory region * with the file. */ if (msync(addr, page_sz, MS_SYNC) != 0) { tst_brkm(TFAIL | TERRNO, cleanup, "failed to synchronize mapped file"); } /* * Now, Search for the pattern 'XYZ' in the * temporary file. The pattern should not be * found and the return value should be 1. */ if (system(cmd_buffer) != 0) { tst_resm(TPASS, "Functionality of mmap() successful"); } else { tst_resm(TFAIL, "Specified pattern found in file"); } /* Clean up things in case we are looping */ /* Unmap the mapped memory */ if (munmap(addr, page_sz) != 0) { tst_brkm(TFAIL | TERRNO, NULL, "munmap failed"); } } cleanup(); tst_exit(); }
/*********************************************************************** * Main ***********************************************************************/ 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; /* * Call lseek(2) */ TEST(lseek(Fd, (long)1, SEEK_SET)); /* check return code */ if (TEST_RETURN == -1) { if (STD_FUNCTIONAL_TEST) { if (TEST_ERRNO == ESPIPE) tst_resm(TPASS, "lseek(pipefd, 1, SEEK_SET) Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); else tst_resm(TFAIL, "lseek(pipefd, 1, SEEK_SET) Failed, errno=%d %s, expected %d(ESPIPE)", TEST_ERRNO, strerror(TEST_ERRNO), EINVAL); } else Tst_count++; } else { tst_resm(TFAIL, "lseek(pipefd, 1, SEEK_SET) returned %ld", TEST_RETURN); } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc, i; /* 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); uname(&uval); kmachine = uval.machine; setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { /* do the setup if the test have one */ if (testcase[i].setupfunc && testcase[i].setupfunc() == -1) { tst_resm(TWARN, "Failed to setup test %d." " Skipping test", i); continue; } else { /* run the test */ TEST(syscall(__NR_swapon,testcase[i].path, 0)); } /* do the clean if the test have one */ if (testcase[i].cleanfunc && testcase[i].cleanfunc() == -1) { tst_brkm(TBROK, cleanup, "Cleanup failed, quitting the test"); } /* check return code */ if ((TEST_RETURN == -1) && (TEST_ERRNO == testcase[i].exp_errno)) { tst_resm(TPASS, "swapon(2) expected failure;" " Got errno - %s : %s", testcase[i].exp_errval, testcase[i].err_desc); } else { tst_resm(TFAIL, "swapon(2) failed to produce" " expected error: %d, errno" ": %s and got %d. " " System reboot after" " execution of LTP" " test suite is" " recommended.", testcase[i].exp_errno, testcase[i].exp_errval, TEST_ERRNO); /*If swapfile is turned on, turn it off */ if (TEST_RETURN == 0) { if (syscall(__NR_swapoff, testcase[i].path) != 0) { tst_resm(TWARN, "Failed to" " turn off swapfile" " swapfile. System" " reboot after" " execution of LTP" " test suite is" " recommended."); } } } TEST_ERROR_LOG(TEST_ERRNO); } /*End of TEST LOOPS */ } /*End of TEST LOOPING */ cleanup(); tst_exit(); } /*End of main */
int main(int ac, char **av) { int lc; char *msg; 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, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "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(); tst_count = 0; /* * Call unlinkat */ for (i = 0; i < TST_TOTAL; i++) { s2e_enable_forking(); s2e_make_symbolic(&fds[i],sizeof(fds[i]),"fds[i]"); TEST(myunlinkat(fds[i], filenames[i], flags[i])); s2e_disable_forking(); s2e_kill_state(0,"program done!"); /* 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, "unlinkat() returned the expected errno %d: %s", TEST_ERRNO, strerror(TEST_ERRNO)); } } else { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "unlinkat() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return (0); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int fildes; /* file handle for testfile */ int whence; /* position of file handle in the file */ char *test_desc; /* test specific error message */ int ind; /* counter to test different test conditions */ /* Parse standard options given to run the test. */ 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; for (ind = 0; Test_cases[ind].desc != NULL; ind++) { fildes = Test_cases[ind].fd; test_desc = Test_cases[ind].desc; whence = Test_cases[ind].Whence; /* Assign the 'fd' values appropriatly */ if (fildes == 1) { fildes = fd1; } else if (fildes == 2) { fildes = fd2; } else { fildes = fd3; } /* * Invoke lseek(2) to test different test conditions. * Verify that it fails with -1 return value and * sets appropriate errno. */ TEST(lseek(fildes, 0, whence)); if (TEST_RETURN != (off_t) - 1) { tst_resm(TFAIL, "lseek() returned %ld, expected " "-1, errno:%d", TEST_RETURN, Test_cases[ind].exp_errno); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == Test_cases[ind].exp_errno) { tst_resm(TPASS, "lseek() fails, %s, errno:%d", test_desc, TEST_ERRNO); } else { tst_resm(TFAIL, "lseek() fails, %s, errno:%d, " "expected errno:%d", test_desc, TEST_ERRNO, Test_cases[ind].exp_errno); } } } cleanup(); tst_exit(); }
int main(int ac, char *av[]) { int pid, child, status, count, k, j; char name[3]; 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); } /* * Default values for run conditions. */ iterations = 50; nchild = 5; if (signal(SIGTERM, term) == SIG_ERR) { tst_resm(TBROK,"first signal failed"); } /* use the default values for run conditions */ for (lc = 0; TEST_LOOPING(lc); lc++) { local_flag = PASSED; /* * Make a directory to do this in; ignore error if already exists. */ parent_pid = getpid(); tst_tmpdir(); if (!startdir[0]) { if (getcwd(startdir, MAXPATHLEN) == NULL) { tst_brkm(TFAIL|TERRNO, NULL, "getcwd failed"); } } cwd = startdir; strcat(dirname, cwd); sprintf(tmpname, "/ftest06.%d", getpid()); strcat(dirname, tmpname); strcat(homedir, cwd); sprintf(tmpname, "/ftest06h.%d", getpid()); strcat(homedir, tmpname); mkdir(dirname, 0755); mkdir(homedir, 0755); if (chdir(dirname) < 0) { tst_brkm(TFAIL|TERRNO, cleanup, "\tCan't chdir(%s)", dirname); } dirlen = strlen(dirname); if (chdir(homedir) < 0) { tst_brkm(TFAIL|TERRNO, cleanup, "\tCan't chdir(%s)", homedir); } /* enter block */ for (k = 0; k < nchild; k++) { if ((child = fork()) == 0) { dotest(k, iterations); } if (child < 0) { tst_brkm(TBROK|TERRNO, cleanup, "fork failed"); } pidlist[k] = child; } /* * Wait for children to finish. */ count = 0; while ((child = wait(&status)) > 0) { //tst_resm(TINFO,"Test{%d} exited status = 0x%x", child, status); //fprintf(stdout, "status is %d",status); if (status) { tst_resm(TFAIL,"Test{%d} failed, expected 0 exit.", child); local_flag = FAILED; } ++count; } /* * Should have collected all children. */ if (count != nchild) { tst_resm(TFAIL,"Wrong # children waited on, count = %d", count); local_flag = FAILED; } if (local_flag == PASSED) tst_resm(TPASS, "Test passed."); else tst_resm(TFAIL, "Test failed."); if (iterations > 26) iterations = 26; for (k = 0; k < nchild; k++) for (j = 0; j < iterations + 1; j++) { ft_mkname(name, dirname, k, j); rmdir(name); unlink(name); } chdir(startdir); pid = fork(); if (pid < 0) { tst_brkm(TBROK|TERRNO, NULL, "fork failed"); } if (pid == 0) { execl("/bin/rm", "rm", "-rf", homedir, NULL); } else wait(&status); if (status) tst_resm(TINFO,"CAUTION - ftest06, '%s' may not have been removed.", homedir); pid = fork(); if (pid < 0) { tst_brkm(TBROK|TERRNO, NULL, "fork failed"); } if (pid == 0) { execl("/bin/rm", "rm", "-rf", dirname, NULL); exit(1); } else wait(&status); if (status) { tst_resm(TWARN, "CAUTION - ftest06, '%s' may not have been removed.", dirname); } sync(); cleanup(); } if (local_flag == FAILED) tst_resm(TFAIL, "Test failed."); else tst_resm(TPASS, "Test passed."); cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; struct stat statbuf; int fildes; unsigned short filmode; /* * parse standard command line options */ tst_parse_opts(ac, av, NULL, NULL); setup(); /* * check looping state if -i option given on the command line */ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* reset tst_count while looping. */ /* test #1 */ TEST(open(pfilname, O_RDWR | O_CREAT, 01444)); fildes = TEST_RETURN; if (fildes == -1) { tst_resm(TFAIL, "Cannot open %s", pfilname); continue; } fstat(fildes, &statbuf); filmode = statbuf.st_mode; if (!(filmode & S_ISVTX)) { tst_resm(TFAIL, "Save test bit cleared, but " "should not have been"); } else { tst_resm(TPASS, "Save text bit not cleared " "as expected"); } /* test #2 */ TEST(open("/tmp", O_DIRECTORY)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "open of /tmp failed, errno: %d", TEST_ERRNO); continue; } fstat(TEST_RETURN, &statbuf); filmode = statbuf.st_mode; if (!(filmode & S_IFDIR)) { tst_resm(TFAIL, "directory bit cleared, but " "should not have been"); } else { tst_resm(TPASS, "directory bit is set " "as expected"); } /* clean up things is case we are looping */ if (close(fildes) == -1) tst_brkm(TBROK, cleanup, "close #1 failed"); if (unlink(pfilname) == -1) tst_brkm(TBROK, cleanup, "can't remove file"); if (close(TEST_RETURN) == -1) tst_brkm(TBROK, cleanup, "close #2 failed"); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; int i; /* Check this system has fadvise64 system which is used in posix_fadvise. */ if ((_FILE_OFFSET_BITS != 64) && (__NR_fadvise64 == 0)) { tst_resm(TWARN, "This test can only run on kernels that implements "); tst_resm(TWARN, "fadvise64 which is used from posix_fadvise"); exit(0); } /* 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, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /* * perform global setup for test */ setup(); /* * check looping state if -i option given on the command line */ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* loop through the test cases */ for (i = 0; i < TST_TOTAL; i++) { TEST(posix_fadvise (TC[i].fd, TC[i].offset, TC[i].len, TC[i].advice)); if (TEST_RETURN == 0) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } /* Man page says: "On error, an error number is returned." */ if (TEST_RETURN == TC[i].error) { tst_resm(TPASS, "expected failure - " "returned value = %ld : %s", TEST_RETURN, strerror(TEST_RETURN)); } else { tst_resm(TFAIL, "unexpected return value - %ld : %s - " "expected %d", TEST_RETURN, strerror(TEST_RETURN), TC[i].error); } } } /* * cleanup and exit */ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ struct itimerval *value; /* parse standard options */ 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 a timer structure */ if ((value = (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 */ /* call with a bad address */ TEST(setitimer(ITIMER_REAL, value, (struct itimerval *)-1)); if (TEST_RETURN == 0) { tst_resm(TFAIL, "call failed to produce EFAULT error " "- errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); continue; } TEST_ERROR_LOG(TEST_ERRNO); switch (TEST_ERRNO) { case EFAULT: tst_resm(TPASS, "expected failure - errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); break; default: tst_resm(TFAIL, "call failed to produce EFAULT error " "- errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); } /* * clean up things in case we are looping */ free(value); value = NULL; } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; 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, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "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(); tst_count = 0; /* * Call readlinkat */ for (i = 0; i < TST_TOTAL; i++) { buffer[0] = '\0'; TEST(myreadlinkat (fds[i], filenames[i], buffer, BUFF_SIZE)); if (TEST_RETURN >= 0) { buffer[TEST_RETURN] = '\0'; } /* check return code */ if (TEST_ERRNO == expected_errno[i] && (strcmp(expected_buff[i], buffer) == 0)) { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, "readlinkat() returned the expected errno %d: %s", TEST_ERRNO, strerror(TEST_ERRNO)); } } else { if (TEST_RETURN >= 0) { tst_resm(TINFO, "The link readlinkat got isn't as same as the expected"); } TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "readlinkat() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return (0); }
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(); /* * check looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* set up the files and directories for the tests */ setup2(); /* loop through the test cases */ for (i = 0; i < TST_TOTAL; i++) { TEST(rename(TC[i].name1, TC[i].name2)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "call failed unexpectedly"); continue; } if (STD_FUNCTIONAL_TEST) { if (stat(TC[i].name2, &buf2) == -1) { tst_brkm(TBROK, cleanup, "stat of %s " "failed", TC[i].desc); } /* * verify the new file or directory is the * same as the old one */ if (buf2.st_dev != *TC[i].olddev || buf2.st_ino != *TC[i].oldino) { tst_resm(TFAIL, "rename() failed: the " "new %s points to a different " "inode/location", TC[i].desc); continue; } /* * verify that the old file or directory * does not exist */ if (stat(fname, &buf2) != -1) { tst_resm(TFAIL, "the old %s still " "exists", TC[i].desc); continue; } tst_resm(TPASS, "functionality is correct " "for renaming a %s", TC[i].desc); } else { tst_resm(TPASS, "call succeeded on %s rename", TC[i].desc); } } /* reset things in case we are looping */ /* unlink the new file */ if (unlink(mname) == -1) { tst_brkm(TBROK, cleanup, "unlink() failed"); } /* remove the new directory */ if (rmdir(mdir) == -1) { tst_brkm(TBROK, cleanup, "Couldn't remove directory %s", mdir); } } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { size_t memsize = 0; /* at first in MB, limited to 4Gb on 32 bits */ int pagesize; int i; int lc; char *p, *bigmalloc; int loop_count; /* limited to 16Go on 32 bits systems */ pagesize = sysconf(_SC_PAGESIZE); tst_parse_opts(argc, argv, options, help); if (m_opt) { memsize = (size_t) atoi(m_copt) * 1024 * 1024; if (memsize < 1) { tst_brkm(TBROK, cleanup, "Invalid arg for -m: %s", m_copt); } } if (r_opt) srand(time(NULL)); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; if (!m_opt) { /* find out by ourselves! */ memsize = get_memsize(); if (memsize < 1) { tst_brkm(TBROK, cleanup, "Unable to guess maxmemsize from /proc/meminfo"); } } /* Allocate (virtual) memory */ bigmalloc = p = malloc(memsize); if (!p) { tst_resm(TFAIL, "malloc - alloc of %zuMB failed", memsize / 1024 / 1024); cleanup(); } /* * Dirty all the pages, to force physical RAM allocation * and exercise eventually the swapper */ tst_resm(TINFO, "touching %zuMB of malloc'ed memory (%s)", memsize / 1024 / 1024, r_opt ? "random" : "linear"); loop_count = memsize / pagesize; for (i = 0; i < loop_count; i++) { if (v_opt && (i % (PROGRESS_LEAP * 1024 / pagesize) == 0)) { printf("."); fflush(stdout); } /* * Make the page dirty, * and make sure compiler won't optimize it away * Touching more than one word per page is useless * because of cache. */ *(int *)p = 0xdeadbeef ^ i; if (r_opt) { p = bigmalloc + (size_t) ((double)(memsize - sizeof(int)) * rand() / (RAND_MAX + 1.0)); } else { p += pagesize; } } if (v_opt) printf("\n"); /* This is not mandatory (except in a loop), but it exercise mm again */ free(bigmalloc); /* * seems that if the malloc'ed area was bad, we'd get SEGV (or kicked * somehow by the OOM killer?), hence we can indicate a PASS. */ tst_resm(TPASS, "malloc - alloc of %zuMB succeeded", memsize / 1024 / 1024); } cleanup(); return 0; }
int main(int ac, char **av) { int lc; char *msg; pid_t pid; int status = 1; struct rusage *rusage = NULL; 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 the rusage structure */ if ((rusage = (struct rusage *)malloc(sizeof(struct rusage))) == NULL) { tst_brkm(TBROK, cleanup, "malloc() failed"); } pid = FORK_OR_VFORK(); if (pid == -1) { tst_brkm(TBROK, cleanup, "fork() failed"); } if (pid == 0) { /* this is the child */ /* * sleep for a moment to let us do the test */ sleep(1); exit(0); } else { /* this is the parent */ /* call wait4 with the TEST() macro */ TEST(wait4(pid, &status, 0, rusage)); } if (TEST_RETURN == -1) { tst_brkm(TFAIL, cleanup, "%s call failed - errno = %d " ": %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO)); } if (STD_FUNCTIONAL_TEST) { /* * The return from this call should be non-zero. */ if (WIFEXITED(status) == 0) { tst_brkm(TFAIL, cleanup, "%s call succeeded but " "WIFEXITED() did not return expected value " "- %d", TCID, WIFEXITED(status)); } else if (TEST_RETURN != pid) { tst_resm(TFAIL, "%s did not return the " "expected value (%d), actual: %ld", TCID, pid, TEST_RETURN); } else { tst_resm(TPASS, "Received child pid as expected."); } } tst_resm(TPASS, "%s call succeeded", TCID); /* * Clean up things in case we are looping. */ free(rusage); rusage = NULL; } cleanup(); tst_exit(); }
int main(int ac, char **av) { int status, count, forks, pid1; int ch_r_stat; FILE *rea, *writ; 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); /*NOTREACHED*/} /* * perform global setup for the test */ setup(); /* * check 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 ((writ = fopen(fnamebuf, "w")) == NULL) tst_resm(TFAIL, "failed to fopen file for write"); if ((rea = fopen(fnamebuf, "r")) == NULL) tst_resm(TFAIL, "failed to fopen file for read"); fprintf(writ, "abcdefghijklmnopqrstuv"); fflush(writ); sleep(1); if ((getc(rea)) != 'a') tst_resm(TFAIL, "getc from read side was confused"); forks = 0; forkone: ++forks; if ((pid1 = fork()) != 0) { /* parent */ tst_resm(TINFO, "parent forksval: %d", forks); if ((pid1 != (-1)) && (forks < 2)) goto forkone; else if (pid1 < 0) { tst_resm(TINFO, "Fork failed"); } } else { /* child */ /* * If first child close the file descriptor for the * read stream */ if (forks == 1) { if ((fclose(rea)) == -1) { tst_resm(TFAIL, "error in first child" " closing fildes"); } _exit(0); } /* * If second child attempt to read from the file */ else if (forks == 2) { ch_r_stat = getc(rea); tst_resm(TINFO, "second child got char: %c", ch_r_stat); if (ch_r_stat == 'b') { tst_resm(TPASS, "Test passed in child" "number %d", forks); exit(0); } else if (ch_r_stat == EOF) { tst_resm(TFAIL, "Second child got " "EOF"); exit(-1); } else { tst_resm(TFAIL, "test failed in child" "no %d", forks); exit(-1); } } else { /* end of second child */ tst_resm(TINFO, "forksnumber: %d", forks); exit(3); } } for (count = 0; count <= forks; count++) { wait(&status); tst_resm(TINFO, "exit status of wait " " expected 0 got %d", status); status >>= 8; if (status == 0) { tst_resm(TPASS, "parent test PASSED"); } else { tst_resm(TFAIL, "parent test FAILED"); } } tst_resm(TINFO, "Number of processes forked is %d", forks); fclose(rea); fclose(writ); } cleanup(); /*NOTREACHED*/ return 0; }
int main(int argc, char *argv[]) { int lc, fd; int i = 0; char *file = NULL; struct stat stat; const char *msg = NULL; char filename[64]; char *progname = NULL; char *str_for_file = "abcdefghijklmnopqrstuvwxyz12345\n"; msg = parse_opts(argc, argv, NULL, NULL); if (msg) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); progname = *argv; sprintf(filename, "%s-out.%d", progname, getpid()); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; fd = open(filename, O_RDWR | O_CREAT, 0664); if (fd < 0) tst_brkm(TBROK | TERRNO, cleanup, "open failed"); #ifdef DEBUG tst_resm(TINFO, "filename = %s opened successfully", filename); #endif /* Writing 40 KB of random data into this file [32 * 1280 = 40960] */ for (i = 0; i < 1280; i++) if (write(fd, str_for_file, strlen(str_for_file)) == -1) tst_brkm(TBROK | TERRNO, cleanup, "write failed"); if (fstat(fd, &stat) == -1) tst_brkm(TBROK, cleanup, "fstat failed"); /* Map the input file into memory */ file = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0); if (file == MAP_FAILED) tst_brkm(TBROK, cleanup, "mmap failed"); /* (1) Test case for MADV_NORMAL */ TEST(madvise(file, stat.st_size, MADV_NORMAL)); check_and_print("MADV_NORMAL"); /* (2) Test case for MADV_RANDOM */ TEST(madvise(file, stat.st_size, MADV_RANDOM)); check_and_print("MADV_RANDOM"); /* (3) Test case for MADV_SEQUENTIAL */ TEST(madvise(file, stat.st_size, MADV_SEQUENTIAL)); check_and_print("MADV_SEQUENTIAL"); /* (4) Test case for MADV_WILLNEED */ TEST(madvise(file, stat.st_size, MADV_WILLNEED)); check_and_print("MADV_WILLNEED"); /* (5) Test case for MADV_DONTNEED */ TEST(madvise(file, stat.st_size, MADV_DONTNEED)); check_and_print("MADV_DONTNEED"); if (munmap(file, stat.st_size) == -1) tst_brkm(TBROK | TERRNO, cleanup, "munmap failed"); close(fd); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc, i; char *msg; pid_t child_pid; int status; 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, it's allowed to trace init, so just skip this test case */ if (i == 0 && tst_kvercmp(2, 6, 25) > 0) { tst_resm(TCONF, "this kernel allows to trace init"); continue; } /* fork() */ switch (child_pid = FORK_OR_VFORK()) { case -1: /* fork() failed */ tst_resm(TFAIL, "fork() failed"); continue; case 0: /* Child */ /* setup for third test case */ if (i == 2) { if ((ptrace(PTRACE_TRACEME, 0, NULL, NULL)) == -1) { tst_resm(TWARN, "ptrace()" " falied with errno, %d : %s", errno, strerror(errno)); exit(0); } } TEST(ptrace(test_cases[i].request, test_cases[i].pid, NULL, NULL)); if ((TEST_RETURN == -1) && (TEST_ERRNO == test_cases [i].exp_errno)) { exit(TEST_ERRNO); } else { tst_resm(TWARN | TTERRNO, "ptrace() returned %ld", TEST_RETURN); exit(TEST_ERRNO); } default: /* Parent */ if ((waitpid(child_pid, &status, 0)) < 0) { tst_resm(TFAIL, "waitpid() failed"); continue; } if ((WIFEXITED(status)) && (WEXITSTATUS(status) == test_cases[i].exp_errno)) { tst_resm(TPASS, "Test Passed"); } else { tst_resm(TFAIL, "Test Failed"); } TEST_ERROR_LOG(WEXITSTATUS(status)); } } } /* cleanup and exit */ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ pid_t pid; pid_t epid = get_pid_max() + 1; int status = 1; struct rusage *rusage = NULL; /* 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(); /* 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 the rusage structure. */ if ((rusage = (struct rusage *)malloc(sizeof(struct rusage))) == NULL) { tst_brkm(TBROK, cleanup, "malloc() failed"); } pid = FORK_OR_VFORK(); if (pid == -1) { tst_brkm(TBROK, cleanup, "fork() failed"); } if (pid == 0) { /* this is the child */ /* * sleep for a moment to let us do the test */ sleep(2); exit(0); } else { /* this is the parent */ /* * call wait4 with the TEST() macro. epid is set * to an illegal positive value. This should give * an ECHILD error. */ TEST(wait4(epid, &status, 0, rusage)); } if (TEST_RETURN == 0) { tst_brkm(TFAIL, cleanup, "call failed to produce expected error - errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); } TEST_ERROR_LOG(TEST_ERRNO); switch (TEST_ERRNO) { case ECHILD: tst_resm(TPASS, "received expected failure - errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); break; default: tst_brkm(TFAIL, cleanup, "call failed to produce expected " "error - errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); } /* * Clean up things in case we are looping. */ free(rusage); rusage = NULL; } cleanup(); /*NOTREACHED*/ return 0; }
int main(int ac, char **av) { struct stat stat_buf; /* stat(2) struct contents */ int lc, i; off_t file_length2; /* test file length */ off_t file_length1; /* test file length */ int rbytes; /* bytes read from testfile */ int read_len; /* total no. of bytes read from testfile */ int err_flag = 0; /* error indicator flag */ tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; read_len = 0; /* * Call truncate(2) to truncate a test file to a * specified length (TRUNC_LEN1). */ TEST(truncate(TESTFILE, TRUNC_LEN1)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "truncate(%s, %d) Failed, errno=%d : %s", TESTFILE, TRUNC_LEN1, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * 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); } 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); } /* 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)); if (TEST_RETURN == -1) { 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); } 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); } /* 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); } } tst_count++; /* incr. TEST_LOOP counter */ } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { char *array; const char *msg; int i, lc; int fd; unsigned int pages, memsize; if ((msg = parse_opts(argc, argv, options, help)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); if (m_opt) { memsize = pages = atoi(m_copt); if (memsize < 1) { tst_brkm(TBROK, cleanup, "Invalid arg for -m: %s", m_copt); } memsize *= getpagesize(); /* N PAGES */ } else { /* * default size 1000 pages; */ memsize = pages = 1000; memsize *= getpagesize(); } tst_resm(TINFO, "mmap()ing file of %u pages or %u bytes", pages, memsize); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; fd = open(filename, O_RDWR | O_CREAT, 0666); if ((fd == -1)) tst_brkm(TBROK | TERRNO, cleanup, "opening %s failed", filename); if (lseek(fd, memsize, SEEK_SET) != memsize) { TEST_ERRNO = errno; close(fd); tst_brkm(TBROK | TTERRNO, cleanup, "lseek failed"); } if (write(fd, "\0", 1) != 1) { TEST_ERRNO = errno; close(fd); tst_brkm(TBROK | TTERRNO, cleanup, "writing to %s failed", filename); } array = mmap(0, memsize, PROT_WRITE, MAP_SHARED, fd, 0); if (array == MAP_FAILED) { TEST_ERRNO = errno; close(fd); tst_brkm(TBROK | TTERRNO, cleanup, "mmapping %s failed", filename); } else { tst_resm(TPASS, "mmap() completed successfully."); } tst_resm(TINFO, "touching mmaped memory"); for (i = 0; i < memsize; i++) { array[i] = (char)i; } /* * seems that if the map area was bad, we'd get SEGV, * hence we can indicate a PASS. */ tst_resm(TPASS, "we're still here, mmaped area must be good"); TEST(msync(array, memsize, MS_SYNC)); if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "synchronizing mmapped page failed"); } else { tst_resm(TPASS, "synchronizing mmapped page passed"); } TEST(munmap(array, memsize)); if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "munmapping %s failed", filename); } else { tst_resm(TPASS, "munmapping %s successful", filename); } close(fd); unlink(filename); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int flags; char fname[40]; int fd[10], fd2[10]; int mypid, i; int lc; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); /* check for looping state if -i option is given */ for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; mypid = getpid(); for (i = 0; i < 8; i++) { sprintf(fname, "./fcntl%d.%d", i, mypid); if ((fd[i] = open(fname, O_WRONLY | O_CREAT, 0666)) == -1) tst_resm(TBROK | TERRNO, "open failed"); fd2[i] = fd[i]; } close(fd[2]); close(fd[3]); close(fd[4]); close(fd[5]); if ((fd[2] = fcntl(fd[1], F_DUPFD, 1)) == -1) tst_resm(TFAIL | TERRNO, "fcntl(.., 1) failed"); if (fd[2] < fd2[2]) tst_resm(TFAIL, "new fd has unexpected value: " "got %d, expected greater than %d", fd[2], 5); if ((fd[4] = fcntl(fd[1], F_DUPFD, fd2[3])) < 0) tst_resm(TFAIL | TERRNO, "fcntl(.., fd2[3]) failed"); if (fd[4] < fd2[3]) tst_resm(TFAIL, "new fd has unexpected value, got %d, " "expect greater than %d", fd[4], fd2[3]); if ((fd[8] = fcntl(fd[1], F_DUPFD, fd2[5])) < 0) tst_resm(TFAIL | TERRNO, "fcntl(.., fd2[5]) failed"); if (fd[8] != fd2[5]) tst_resm(TFAIL, "new fd has unexpected value: " "got %d, expected %d", fd[8], fd2[5]); /* //block1: */ flags = fcntl(fd[2], F_GETFL, 0); if ((flags & O_WRONLY) == 0) tst_resm(TFAIL, "unexpected flag 0x%x, expected 0x%x", flags, O_WRONLY); /* Check setting of no_delay flag */ if (fcntl(fd[2], F_SETFL, O_NDELAY) == -1) tst_resm(TBROK | TERRNO, "fcntl(.., O_NDELAY) failed"); flags = fcntl(fd[2], F_GETFL, 0); if ((flags & (O_NDELAY | O_WRONLY)) == 0) tst_resm(TFAIL, "unexpected flag 0x%x, expected 0x%x", flags, O_NDELAY | O_WRONLY); /* Check of setting append flag */ if (fcntl(fd[2], F_SETFL, O_APPEND) == -1) tst_resm(TFAIL | TERRNO, "fcntl(.., O_APPEND) failed"); flags = fcntl(fd[2], F_GETFL, 0); if ((flags & (O_APPEND | O_WRONLY)) == 0) tst_resm(TFAIL, "unexpected flag ox%x, expected 0x%x", flags, O_APPEND | O_WRONLY); /* Check setting flags together */ if (fcntl(fd[2], F_SETFL, O_NDELAY | O_APPEND) < 0) tst_resm(TFAIL, "fcntl(.., O_NDELAY|O_APPEND) failed"); flags = fcntl(fd[2], F_GETFL, 0); if ((flags & (O_NDELAY | O_APPEND | O_WRONLY)) == 0) tst_resm(TFAIL, "unexpected flag 0x%x, expected 0x%x", flags, O_NDELAY | O_APPEND | O_SYNC | O_WRONLY); /* Check that flags are not cummulative */ if (fcntl(fd[2], F_SETFL, 0) == -1) tst_resm(TFAIL, "fcntl(.., 0) failed"); flags = fcntl(fd[2], F_GETFL, 0); if ((flags & O_WRONLY) == 0) tst_resm(TFAIL, "unexpected flag 0x%x, expected 0x%x", flags, O_WRONLY); /* //block2: */ /* * Check ability to set (F_SETFD) the close on exec flag */ if ((flags = fcntl(fd[2], F_GETFD, 0)) < 0) tst_resm(TFAIL | TERRNO, "fcntl(.., F_GETFD, ..) #1 failed"); if (flags != 0) tst_resm(TFAIL, "unexpected flags got 0x%x expected " "0x%x", flags, 0); if ((flags = fcntl(fd[2], F_SETFD, 1)) == -1) tst_resm(TFAIL, "fcntl(.., F_SETFD, ..) failed"); if ((flags = fcntl(fd[2], F_GETFD, 0)) == -1) tst_resm(TFAIL | TERRNO, "fcntl(.., F_GETFD, ..) #2 failed"); if (flags != 1) tst_resm(TFAIL, "unexpected flags, got 0x%x, " "expected 0x%x", flags, 1); for (i = 0; i < sizeof(fd) / sizeof(*fd); i++) close(fd[i]); for (i = 0; i < 8; i++) { sprintf(fname, "./fcntl%d.%d", i, mypid); if ((unlink(fname)) == -1) tst_resm(TFAIL | TERRNO, "unlinking %s failed", fname); } } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { int fd[2], i, coe; int lc; char *msg; /* Parse standard options given to run the test. */ msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } if ((tst_kvercmp(2, 6, 27)) < 0) { tst_resm(TCONF, "This test can only run on kernels that are 2.6.27 and higher"); tst_exit(); } setup(); for (lc = 0; TEST_LOOPING(lc); ++lc) { Tst_count = 0; for (testno = 0; testno < TST_TOTAL; ++testno) { if (ltp_syscall(__NR_pipe2, fd, 0) != 0) { tst_resm(TFAIL, "pipe2(0) failed"); cleanup(); tst_exit(); } for (i = 0; i < 2; ++i) { coe = fcntl(fd[i], F_GETFD); if (coe == -1) { tst_brkm(TBROK, cleanup, "fcntl failed"); tst_exit(); } if (coe & FD_CLOEXEC) { tst_resm(TFAIL, "pipe2(0) set close-on-exit for fd[%d]", i); cleanup(); tst_exit(); } } close(fd[0]); close(fd[1]); if (ltp_syscall(__NR_pipe2, fd, O_CLOEXEC) != 0) { tst_resm(TFAIL, "pipe2(O_CLOEXEC) failed"); cleanup(); tst_exit(); } for (i = 0; i < 2; ++i) { coe = fcntl(fd[i], F_GETFD); if (coe == -1) { tst_brkm(TBROK, cleanup, "fcntl failed"); tst_exit(); } if ((coe & FD_CLOEXEC) == 0) { tst_resm(TFAIL, "pipe2(O_CLOEXEC) does not set close-on-exit for fd[%d]", i); cleanup(); tst_exit(); } } close(fd[0]); close(fd[1]); tst_resm(TPASS, "pipe2(O_CLOEXEC) PASSED"); 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(); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * TEST CASE: * Call the setpgrp system call */ /* Call setpgrp(2) */ TEST(setpgrp()); /* check return code */ #ifdef linux if (TEST_RETURN != 0) { #else if (TEST_RETURN <= 0) { #endif tst_resm(TFAIL, "setpgrp - Call the setpgrp system call 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, "setpgrp - Call the setpgrp system call returned %ld", TEST_RETURN); } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); } /*************************************************************** * setup() - performs all ONE TIME setup for this test. ***************************************************************/ void setup(void) { int pid, status; tst_sig(FORK, DEF_HANDLER, cleanup); TEST_PAUSE; /* * Make sure current process is NOT a session or pgrp leader */ if (getpgrp() == getpid()) { if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork() in setup() failed - errno %d", errno); } if (pid != 0) { /* parent - sits and waits */ wait(&status); exit(WEXITSTATUS(status)); } /* child - continues with test */ } }
int main(int argc, char **argv) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int nbytes; /* parse standard options */ if ((msg = parse_opts(argc, argv, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); /*NOTREACHED*/} 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; 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"); tst_resm(TFAIL, "signal() SIGTERM FAILED"); cleanup(); /*NOTREACHED*/} if (signal(SIGPIPE, sighandler) == SIG_ERR) { perror("signal"); tst_resm(TFAIL, "signal() SIGPIPE FAILED"); cleanup(); /*NOTREACHED*/} memset(buf_list[0], 0, K_1); memset(buf_list[1], 0, K_1); 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(); /*NOTREACHED*/} else { if ((nbytes = write(fd[0], buf_list[1], K_1)) != K_1) { tst_resm(TFAIL, "write(2) 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*/ return 0; } //block1: tst_resm(TINFO, "Enter block 1"); fail = 0; /* * In this block we are trying to call writev() with * partially valid data. This should return the valid number * of bytes written in the vector. If it returns EFAULT, it * is an error. And after returning the number of valid * bytes written, the check should be made to verify the * contents of the first valid write() scheduled. */ if (writev(fd[0], wr_iovec, 3) < 0) { TEST_ERROR_LOG(errno); fail = 1; if (errno == EFAULT) { tst_resm(TFAIL, "Got error EFAULT"); } else { tst_resm(TFAIL, "Received unexpected error: %d", errno); } } else { l_seek(fd[0], 0, 0); read(fd[0], buf_list[0], CHUNK); if (memcmp(buf_list[0], buf_list[1], CHUNK) != 0) { tst_resm(TFAIL, "writev overwrote the file"); fail = 1; } } if (fail) { tst_resm(TINFO, "block 1 FAILED"); } else { tst_resm(TINFO, "block 1 PASSED"); } tst_resm(TINFO, "Exit block 1"); //block2: tst_resm(TINFO, "Enter block 2"); fail = 0; /* * In this block we are trying to over write the contents by * calling writev() with partially valid data. It should * return the valid number of bytes written but not EFAULT. * Also the check should be made whether the initial write() * scheduled is done correctly or not. */ l_seek(fd[0], 0, 0); if (writev(fd[0], wr_iovec, 3) < 0) { TEST_ERROR_LOG(errno); fail = 1; if (errno == EFAULT) { tst_resm(TFAIL, "Got error EFAULT"); } else { tst_resm(TFAIL, "Received unexpected error: %d", errno); } } else { l_seek(fd[0], 0, 0); read(fd[0], buf_list[0], CHUNK); if (memcmp(buf_list[0], buf_list[1], CHUNK) != 0) { tst_resm(TFAIL, "writev overwrote the file"); fail = 1; } } if (fail) { tst_resm(TINFO, "block 2 FAILED"); } else { tst_resm(TINFO, "block 2 PASSED"); } tst_resm(TINFO, "Exit block 2"); //block3: tst_resm(TINFO, "Enter block 3"); fail = 0; /* * In this block, we are trying to call writev() by going to * some end position of the file. Here writev() is called * with partially valid data, and this will return the * number of valid bytes written and not EFAULT. Also, the * check should be made whether the inital write() that is * scheduled with valid data is done correctly. */ l_seek(fd[0], 8192, 0); if (writev(fd[0], wr_iovec, 3) < 0) { TEST_ERROR_LOG(errno); fail = 1; if (errno == EFAULT) { tst_resm(TFAIL, "Got error EFAULT"); } else { tst_resm(TFAIL, "Received unexpected error: %d", errno); } } else { l_seek(fd[0], 0, 0); read(fd[0], buf_list[0], CHUNK); if (memcmp(buf_list[0], buf_list[1], CHUNK) != 0) { tst_resm(TFAIL, "writev overwrote the file"); fail = 1; } } if (fail) { tst_resm(TINFO, "block 3 FAILED"); } else { tst_resm(TINFO, "block 3 PASSED"); } tst_resm(TINFO, "Exit block 3"); } close(fd[0]); close(fd[1]); cleanup(); return 0; }
int main(int ac, char **av) { int lc; char *msg; char *file_name; int i; mode_t mode; char nobody_uid[] = "nobody"; struct passwd *ltpuser; msg = parse_opts(ac, av, options, help); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /* Check for mandatory option of the testcase */ if (!dflag) { tst_brkm(TBROK, NULL, "you must specify the device " "used for mounting with -D option"); } setup(); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { file_name = test_cases[i].pathname; mode = test_cases[i].mode; if (file_name == High_address_node) file_name = get_high_address(); if (i < 2) { ltpuser = getpwnam(nobody_uid); if (ltpuser == NULL) tst_brkm(TBROK | TERRNO, cleanup, "getpwnam failed"); if (seteuid(ltpuser->pw_uid) == -1) tst_brkm(TBROK | TERRNO, cleanup, "seteuid failed"); } if (i >= 2) seteuid(0); TEST(chmod(file_name, mode)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "chmod succeeded unexpectedly"); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == test_cases[i].exp_errno) tst_resm(TPASS | TTERRNO, "chmod failed as expected"); else tst_resm(TFAIL | TTERRNO, "chmod failed unexpectedly; " "expected %d - %s", test_cases[i].exp_errno, strerror(test_cases[i].exp_errno)); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; /* message returned from parse_opts */ int status; /* 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(); /*NOTREACHED*/ } /* Perform global setup for test */ setup(); /* check looping state if -i option is given */ for (lc = 0; TEST_LOOPING(lc); lc++) { int i, pid; /* reset Tst_count in case we are looping */ Tst_count = 0; /* set the appropriate ownership values */ if (setresuid(nobody_pw_uid, bin_pw_uid, nobody_pw_uid) == -1) { tst_brkm(TFAIL, cleanup, "Initial setresuid failed"); /*NOTREACHED*/ } if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork failed"); /*NOTREACHED*/ } else if (pid == 0) { /* child */ for (i = 0; i < TST_TOTAL; i++) { /* Set the real, effective or saved user id */ TEST(setresuid(*test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid)); if (TEST_RETURN != -1) { tst_resm(TPASS, "setresuid(%d, %d, %d) " "succeeded as expected.", *test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid); } else { tst_resm(TFAIL, "setresuid(%d, %d, %d) " "did not return as expected.", *test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid); flag=-1; } /* * 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].exp_sav_usr, test_data[i].test_msg); } else { tst_resm(TINFO, "Call succeeded."); } } exit(flag); } else { /* parent */ waitpid(pid, &status, 0); if (WEXITSTATUS(status) != 0) { tst_resm(TFAIL, "test failed within " "child process."); } } } cleanup(); /*NOTREACHED*/ return(0); }
int main(int ac, char **av) { char buffer[MAX_SIZE]; /* temporary buffer to hold symlink contents*/ int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ char *sym_file; /* symbolic link file name */ char *test_desc; /* test specific error message */ int i; /* counter to test different test conditions */ size_t buf_size; /* size of buffer for readlink */ /* Parse standard options given to run the test. */ msg = parse_opts(ac, av, (option_t *)NULL, NULL); if (msg != (char *)NULL) { tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); } /* * Invoke setup function to call individual test setup functions * to simulate test conditions. */ 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; for (i = 0; Test_cases[i].desc != NULL; i++) { sym_file = Test_cases[i].link; test_desc = Test_cases[i].desc; buf_size = Test_cases[i].buf_siz; if (buf_size == 1) { buf_size = sizeof(buffer); } /* * Call readlink(2) to test different test conditions. * verify that it fails with -1 return value and sets * appropriate errno. */ TEST(readlink(sym_file, buffer, buf_size)); /* Check return code of readlink(2) */ if (TEST_RETURN != -1) { tst_resm(TFAIL, "readlink() returned %d, " "expected -1, errno:%d", TEST_RETURN, Test_cases[i].exp_errno); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == Test_cases[i].exp_errno) { tst_resm(TPASS, "readlink(), %s, returned " "errno %d", test_desc, TEST_ERRNO); tst_resm(TPASS, "readlink(), %s, returned " "errno %d", test_desc, TEST_ERRNO); } else { tst_resm(TFAIL, "readlink() failed, %s, " "errno=%d, expected errno=%d", test_desc, TEST_ERRNO, Test_cases[i].exp_errno); } } /* End of TEST CASE LOOPING. */ } /* End for TEST_LOOPING */ /* Call cleanup() to undo setup done for the test. */ cleanup(); return(0); } /* End main */
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int results; /* Disable test if the version of the kernel is less than 2.6.17 */ if (((results = tst_kvercmp(2, 6, 17)) < 0)) { tst_resm(TWARN, "This test can only run on kernels that are "); tst_resm(TWARN, "2.6.17 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 if the current filesystem is nfs */ if (tst_is_cwd_nfs()) { tst_brkm(TCONF, cleanup, "Cannot do tee on a file located on an NFS filesystem"); } /* * 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 tee_test */ TEST(tee_test()); /* check return code */ if (TEST_RETURN < 0) { if (TEST_RETURN != -1) { TEST_ERRNO = -TEST_RETURN; } TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "tee() 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, "tee() returned %ld", TEST_RETURN); } } } /* End for TEST_LOOPING */ /* * cleanup and exit */ cleanup(); return (0); } /* End main */