From: Cyril H. <su...@li...> - 2013-04-23 19:21:21
|
The branch, master, has been updated via 4758cb19e6ffad42ba3b026938f9f63e85ac6d9f (commit) via d354733e75178bc1a33a91eff075dfecaf2dce57 (commit) from 738f74ec1a67ec9522508969a72e3e9f2d19b9f8 (commit) - Log ----------------------------------------------------------------- commit 4758cb19e6ffad42ba3b026938f9f63e85ac6d9f Author: Cyril Hrubis <ch...@su...> Date: Tue Apr 23 20:41:01 2013 +0200 syscalls/dup06: Fixes. The testcases had several problems: * Wasn't using tst_tmpdir() and created files in CWD * The test wasn't closing the filedescriptors and so the test has failed on second and any other run (-i or -I) * The fail flag was set only once at the start and not reset along the way, so after one failure the rest of the tests would be marked as failed * etc. Signed-off-by: Cyril Hrubis <ch...@su...> commit d354733e75178bc1a33a91eff075dfecaf2dce57 Author: Cyril Hrubis <ch...@su...> Date: Tue Apr 23 19:11:59 2013 +0200 syscalls/dup07: Fixes. The testcases had several problems: * Wasn't using tst_tmpdir() and created files in CWD * The main loop contained tst_exit() and because of that options as -i and -I weren't working at all * The fail flag was set only once at the start and not reset along the way, so after one failure the rest of the tests would be marked as failed * etc. Signed-off-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/dup/dup06.c | 90 +++++++++++++-------------- testcases/kernel/syscalls/dup/dup07.c | 108 ++++++++++++-------------------- 2 files changed, 85 insertions(+), 113 deletions(-) diff --git a/testcases/kernel/syscalls/dup/dup06.c b/testcases/kernel/syscalls/dup/dup06.c index f9cbaa9..44d5b43 100644 --- a/testcases/kernel/syscalls/dup/dup06.c +++ b/testcases/kernel/syscalls/dup/dup06.c @@ -1,6 +1,7 @@ /* - * * Copyright (c) International Business Machines Corp., 2002 + * ported from SPIE, section2/iosuite/dup1.c, by Airong Zhang + * Copyright (c) 2013 Cyril Hrubis <ch...@su...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,17 +18,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* Pored from SPIE, section2/iosuite/dup1.c, by Airong Zhang */ - -/*====================================================================== - =================== TESTPLAN SEGMENT =================== ->KEYS: < dup() ->WHAT: < Does dup return -1 on the 21st file? ->HOW: < Create up to _NFILE (20) files and check for -1 return on the - < next attempt - < Should check NOFILE as well as _NFILE. 19-Jun-84 Dale. ->BUGS: < -======================================================================*/ +/* + WHAT: Does dup return -1 on the 21st file? + HOW: Create up to _NFILE (20) files and check for -1 return on the + next attempt + Should check NOFILE as well as _NFILE. 19-Jun-84 Dale. +*/ #include <stdio.h> #include <fcntl.h> @@ -41,12 +37,8 @@ char *TCID = "dup06"; int TST_TOTAL = 1; -int local_flag; -#define PASSED 1 -#define FAILED 0 - -int cnt_free_fds(int maxfd) +static int cnt_free_fds(int maxfd) { int freefds = 0; @@ -57,63 +49,69 @@ int cnt_free_fds(int maxfd) return (freefds); } +static void setup(void); +static void cleanup(void); + int main(int ac, char **av) { - int *fildes, j; - int ifile; - char pfilname[40]; + int *fildes, i; int min; int freefds; int lc; char *msg; - - ifile = -1; + const char *pfilname = "dup06"; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); + setup(); + min = getdtablesize(); freefds = cnt_free_fds(min); - fildes = (int *)malloc((min + 5) * sizeof(int)); - local_flag = PASSED; - - for (lc = 0; TEST_LOOPING(lc); lc++) { + fildes = malloc((min + 5) * sizeof(int)); - for (j = 0; j < min + 5; j++) - fildes[j] = 0; + for (i = 0; i < min + 5; i++) + fildes[i] = 0; - sprintf(pfilname, "dup06.%d\n", getpid()); + for (lc = 0; TEST_LOOPING(lc); lc++) { unlink(pfilname); + if ((fildes[0] = creat(pfilname, 0666)) == -1) { tst_resm(TFAIL, "Cannot open first file"); - local_flag = FAILED; } else { - for (ifile = 1; ifile < min + 5; ifile++) { - if ((fildes[ifile] = - dup(fildes[ifile - 1])) == -1) { + for (i = 1; i < min + 5; i++) { + if ((fildes[i] = dup(fildes[i - 1])) == -1) break; - } - } - if (ifile < freefds) { + if (i < freefds) { tst_resm(TFAIL, "Not enough files duped"); - local_flag = FAILED; - } else if (ifile > freefds) { + } else if (i > freefds) { tst_resm(TFAIL, "Too many files duped"); - local_flag = FAILED; + } else { + tst_resm(TPASS, "Test passed."); } } - unlink(pfilname); - if (ifile > 0) - close(fildes[ifile - 1]); + unlink(pfilname); - if (local_flag == PASSED) - tst_resm(TPASS, "Test passed."); - else - tst_resm(TFAIL, "Test failed."); + for (i = 0; i < min + 5; i++) { + if (fildes[i] != 0 && fildes[i] != -1) + close(fildes[i]); + fildes[i] = 0; + } } + + cleanup(); tst_exit(); +} +static void setup(void) +{ + tst_tmpdir(); +} + +static void cleanup(void) +{ + tst_rmdir(); } diff --git a/testcases/kernel/syscalls/dup/dup07.c b/testcases/kernel/syscalls/dup/dup07.c index c9ddaf0..03b0ba4 100644 --- a/testcases/kernel/syscalls/dup/dup07.c +++ b/testcases/kernel/syscalls/dup/dup07.c @@ -1,6 +1,8 @@ /* * * Copyright (c) International Business Machines Corp., 2002 + * ported from SPIE, section2/iosuite/dup3.c, by Airong Zhang + * Copyright (c) 2013 Cyril Hrubis <ch...@su...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,20 +19,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* Pored from SPIE, section2/iosuite/dup3.c, by Airong Zhang */ - - /*dup3.c */ -/*====================================================================== - =================== TESTPLAN SEGMENT =================== ->KEYS: < dup() ->WHAT: < Is the access mode the same for both file descriptors? - < 0: read only? - < 1: write only? - < 2: read/write? ->HOW: < Creat a file with each access mode; dup each file descriptor; - < stat each file descriptor and compare mode of each pair ->BUGS: < -======================================================================*/ +/* + WHAT: Is the access mode the same for both file descriptors? + 0: read only? + 1: write only? + 2: read/write? + HOW: Creat a file with each access mode; dup each file descriptor; + stat each file descriptor and compare mode of each pair +*/ #include <stdio.h> #include <fcntl.h> @@ -42,15 +38,13 @@ #include "usctest.h" char *TCID = "dup07"; -int TST_TOTAL = 1; -int local_flag; +int TST_TOTAL = 3; -#define PASSED 1 -#define FAILED 0 +static const char *testfile = "dup07"; -char testfile[40] = ""; +static void setup(void); +static void cleanup(void); -/*--------------------------------------------------------------------*/ int main(int ac, char **av) { struct stat retbuf; @@ -58,107 +52,87 @@ int main(int ac, char **av) int rdoret, wroret, rdwret; int duprdo, dupwro, duprdwr; -/*--------------------------------------------------------------------*/ - int lc; char *msg; - /* - * parse standard options - */ - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { - tst_resm(TBROK, "OPTION PARSING ERROR - %s", msg); - tst_exit(); - } + if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - local_flag = PASSED; + setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { - sprintf(testfile, "dup07.%d", getpid()); if ((rdoret = creat(testfile, 0444)) == -1) { tst_resm(TFAIL, "Unable to creat file '%s'", testfile); - local_flag = FAILED; } else { if ((duprdo = dup(rdoret)) == -1) { tst_resm(TFAIL, "Unable to dup '%s'", testfile); - local_flag = FAILED; } else { fstat(rdoret, &retbuf); fstat(duprdo, &dupbuf); if (retbuf.st_mode != dupbuf.st_mode) { tst_resm(TFAIL, "rdonly and dup do not match"); - local_flag = FAILED; + } else { + tst_resm(TPASS, + "Passed in read mode."); } } } - if (local_flag == PASSED) { - tst_resm(TPASS, "Test passed in read mode."); - } else { - tst_resm(TFAIL, "Test failed in read mode."); - } - -/*--------------------------------------------------------------------*/ unlink(testfile); + if ((wroret = creat(testfile, 0222)) == -1) { tst_resm(TFAIL, "Unable to creat file '%s'", testfile); - local_flag = FAILED; } else { if ((dupwro = dup(wroret)) == -1) { tst_resm(TFAIL, "Unable to dup '%s'", testfile); - local_flag = FAILED; } else { fstat(wroret, &retbuf); fstat(dupwro, &dupbuf); if (retbuf.st_mode != dupbuf.st_mode) { tst_resm(TFAIL, "wronly and dup do not match"); - local_flag = FAILED; + } else { + tst_resm(TPASS, + "Passed in write mode."); } } } - if (local_flag == PASSED) { - tst_resm(TPASS, "Test passed in write mode."); - } else { - tst_resm(TFAIL, "Test failed in write mode."); - } -/*--------------------------------------------------------------------*/ unlink(testfile); + if ((rdwret = creat(testfile, 0666)) == -1) { tst_resm(TFAIL, "Unable to creat file '%s'", testfile); - local_flag = FAILED; } else { if ((duprdwr = dup(rdwret)) == -1) { tst_resm(TFAIL, "Unable to dup '%s'", testfile); - local_flag = FAILED; } else { fstat(rdwret, &retbuf); fstat(duprdwr, &dupbuf); if (retbuf.st_mode != dupbuf.st_mode) { tst_resm(TFAIL, "rdwr and dup do not match"); - local_flag = FAILED; + } else { + tst_resm(TPASS, + "Passed in read/write mode."); } } } - if (local_flag == PASSED) { - tst_resm(TPASS, "Test passed in read/write mode."); - } else { - tst_resm(TFAIL, "Test failed in read/write mode."); - } -/*--------------------------------------------------------------------*/ + unlink(testfile); + } - if (local_flag == PASSED) { - tst_resm(TPASS, "Test passed"); - } else { - tst_resm(TFAIL, "Test failed"); - } - - tst_exit(); - } /* end for */ + cleanup(); tst_exit(); } + +static void setup(void) +{ + tst_tmpdir(); +} + +static void cleanup(void) +{ + tst_rmdir(); +} hooks/post-receive -- ltp |