commit 74c9729d10fcf866eff93ae830005fb13b464e16 Author: Jiri Palecek Date: Thu Sep 24 13:18:25 2009 +0200 Remove fuss from ftest testcases The testcases contained logic for creating their temporary directories. IMHO, this was superseded with the introduction of tst_tmpdir, and the code might invoke buffer overflow errors, so it's better deleted. diff --git a/testcases/kernel/fs/ftest/ftest01.c b/testcases/kernel/fs/ftest/ftest01.c index 8bbbdce..ecdc0ab 100644 --- a/testcases/kernel/fs/ftest/ftest01.c +++ b/testcases/kernel/fs/ftest/ftest01.c @@ -95,9 +95,6 @@ int pidlist[MAXCHILD]; char test_name[2]; /* childs test directory name */ char *prog; -char fuss[40] = ""; /* directory to do this in */ -char homedir[200]= ""; /* where we started */ - int local_flag; /*--------------------------------------------------------------*/ @@ -143,18 +140,8 @@ setup() * Save starting directory. */ tst_tmpdir(); - getcwd(homedir, sizeof( homedir)); parent_pid = getpid(); - if (!fuss[0]) - sprintf(fuss, "./ftest1.%d", getpid()); - - mkdir(fuss, 0755); - - if (chdir(fuss) < 0) { - tst_brkm(TBROK,0,"Can't chdir(%s): %s", fuss, strerror(errno)); - } - /* * Default values for run conditions. */ @@ -166,8 +153,7 @@ setup() misc_intvl = 10; if ((sigset(SIGTERM, (void (*)())term)) == SIG_ERR) { - tst_resm(TBROK,"sigset failed: %s", strerror(errno)); - tst_exit(); + tst_brkm(TBROK, cleanup, "sigset failed: %s", strerror(errno)); } local_flag = PASSED; @@ -189,7 +175,7 @@ int runtest() test_name[1] = '\0'; fd = open(test_name, O_RDWR|O_CREAT|O_TRUNC, 0666); if (fd < 0) { - tst_brkm(TBROK,0, "Can't creating %s/%s: %s", fuss, test_name, strerror(errno)); + tst_brkm(TBROK,0, "Can't creating %s: %s", test_name, strerror(errno)); } if ((child = fork()) == 0) { /* child */ dotest(nchild, i, fd); /* do it! */ @@ -216,7 +202,7 @@ int runtest() { if ((child = wait(&status)) >= 0) { if (status) { - tst_resm(TFAIL,0, "Test{%d} failed, expected 0 exit", child); + tst_resm(TFAIL, "Test{%d} failed, expected 0 exit", child); local_flag = FAILED; } ++count; @@ -243,27 +229,6 @@ int runtest() tst_resm(TFAIL, "Test failed in fork and wait."); } - chdir(homedir); - pid = fork(); - if (pid < 0) { - - tst_resm(TINFO, "System resource may be too low, fork() malloc()" - " etc are likely to fail."); - - tst_resm(TBROK, "Can not remove '%s' due to inability of fork.",fuss); - sync(); - tst_exit(); - } - if (pid == 0) { - execl("/bin/rm", "rm", "-rf", fuss, NULL); - tst_exit(); - } - - wait(&status); - if (status) { - tst_resm(TINFO, "CAUTION - ftest1, '%s' may not be removed", fuss); - } - sync(); /* safeness */ return 0; } diff --git a/testcases/kernel/fs/ftest/ftest03.c b/testcases/kernel/fs/ftest/ftest03.c index 35d4328..a031f72 100644 --- a/testcases/kernel/fs/ftest/ftest03.c +++ b/testcases/kernel/fs/ftest/ftest03.c @@ -72,6 +72,7 @@ extern int Tst_count; #define FAILED 0 void setup(); +static void cleanup(void); int runtest(); int dotest(int, int, int); int domisc(int, int, char*); @@ -98,10 +99,7 @@ int fd; /* file descriptor used by child */ int parent_pid; int pidlist[MAXCHILD]; char test_name[2]; /* childs test directory name */ -char *prog, *getcwd() ; - -char fuss[40] = ""; /* directory to do this in */ -char homedir[200]= ""; /* where we started */ +char *prog; int local_flag; /*--------------------------------------------------------------*/ @@ -135,9 +133,8 @@ int main (ac, av) tst_resm(TFAIL, "Test failed."); } - tst_rmdir(); - tst_exit(); } /* end for */ + cleanup(); return 0; } /*--------------------------------------------------------------*/ @@ -153,24 +150,8 @@ setup() * Save starting directory. */ tst_tmpdir(); - if ( (cwd = getcwd(homedir, sizeof( homedir))) == NULL ) { - tst_resm(TBROK, "pwd") ; - tst_exit() ; - } - parent_pid = getpid(); - if (!fuss[0]) - sprintf(fuss, "%s/ftest03.%d", getcwd(wdbuf, sizeof( wdbuf)), getpid()); - - mkdir(fuss, 0755); - - if (chdir(fuss) < 0) { - tst_resm(TBROK,"\tCan't chdir(%s), error %d.", fuss, errno); - tst_exit() ; - } - - /* * Default values for run conditions. */ @@ -182,13 +163,16 @@ setup() misc_intvl = 10; if (sigset(SIGTERM, (void (*)())term) == SIG_ERR) { - perror("sigset failed"); - tst_resm(TBROK, " sigset failed: signo = 15") ; - tst_exit() ; + tst_brkm(TBROK|TERRNO, cleanup, " sigset failed: signo = 15") ; } } +static void cleanup(void) +{ + tst_rmdir(); + tst_exit(); +} int runtest() { @@ -205,8 +189,7 @@ int runtest() test_name[1] = '\0'; fd = open(test_name, O_RDWR|O_CREAT|O_TRUNC, 0666); if (fd < 0) { - tst_resm(TBROK, "\tError %d creating %s/%s.", errno, fuss, test_name); - tst_exit(); + tst_brkm(TBROK, cleanup, "\tError %d creating %s.", errno, test_name); } if ((child = fork()) == 0) { /* child */ dotest(nchild, i, fd); /* do it! */ @@ -258,28 +241,6 @@ int runtest() local_flag = FAILED; } - chdir(homedir); - - pid = fork(); - if (pid < 0) { - tst_resm(TINFO, "System resource may be too low, fork() malloc()" - " etc are likely to fail."); - tst_resm(TBROK, "Test broken due to inability of fork."); - sync(); /* safeness */ - tst_exit(); - } - - if (pid == 0) { - execl("/bin/rm", "rm", "-rf", fuss, NULL); - tst_exit(); - } else - wait(&status); - if (status) { - tst_resm(TINFO, "CAUTION - ftest03, '%s' may not be removed", fuss); - tst_resm(TINFO, "CAUTION - ftest03, '%s' may not be removed", - fuss); - } - sync(); /* safeness */ return 0; } diff --git a/testcases/kernel/fs/ftest/ftest05.c b/testcases/kernel/fs/ftest/ftest05.c index 24fac1d..5fe16ad 100644 --- a/testcases/kernel/fs/ftest/ftest05.c +++ b/testcases/kernel/fs/ftest/ftest05.c @@ -98,9 +98,6 @@ int pidlist[MAXCHILD]; char test_name[2]; /* childs test directory name */ char *prog; -char fuss[40] = ""; /* directory to do this in */ -char homedir[200]= ""; /* where we started */ - int local_flag; /*--------------------------------------------------------------*/ @@ -147,20 +144,8 @@ setup() * Save starting directory. */ tst_tmpdir(); - getcwd(homedir, sizeof( homedir)); parent_pid = getpid(); - if (!fuss[0]) - sprintf(fuss, "./ftest05.%d", getpid()); - - mkdir(fuss, 0755); - - if (chdir(fuss) < 0) { - tst_resm(TBROK,"\tCan't chdir(%s), error %d.", fuss, errno); - tst_exit(); - } - - /* * Default values for run conditions. */ @@ -195,8 +180,7 @@ int runtest() test_name[1] = '\0'; fd = open(test_name, O_RDWR|O_CREAT|O_TRUNC, 0666); if (fd < 0) { - tst_resm(TBROK, "\tError %d creating %s/%s.", errno, fuss, test_name); - tst_exit(); + tst_brkm(TBROK|TERRNO, cleanup, "Error creating %s.", test_name); } if ((child = fork()) == 0) { /* child */ dotest(nchild, i, fd); /* do it! */ @@ -206,8 +190,7 @@ int runtest() if (child < 0) { tst_resm(TINFO, "System resource may be too low, fork() malloc()" " etc are likely to fail."); - tst_resm(TBROK, "Test broken due to inability of fork."); - tst_exit(); + tst_brkm(TBROK, cleanup, "Test broken due to inability of fork."); } else { pidlist[i] = child; nwait++; @@ -245,26 +228,6 @@ int runtest() local_flag = FAILED; } - - chdir(homedir); - pid = fork(); - if (pid < 0) { - tst_resm(TINFO, "System resource may be too low, fork() malloc()" - " etc are likely to fail."); - tst_resm(TBROK, "Test broken due to inability of fork."); - sync(); - tst_exit(); - } - if (pid == 0) { - execl("/bin/rm", "rm", "-rf", fuss, NULL); - tst_exit(); - } - - wait(&status); - if (status) { - tst_resm(TINFO,"CAUTION - ftest05, '%s' may not be removed", fuss); - } - sync(); /* safeness */ return 0; } diff --git a/testcases/kernel/fs/ftest/ftest07.c b/testcases/kernel/fs/ftest/ftest07.c index 2b2aa7c..e1d22c5 100644 --- a/testcases/kernel/fs/ftest/ftest07.c +++ b/testcases/kernel/fs/ftest/ftest07.c @@ -84,6 +84,7 @@ extern int Tst_count; #define MAXIOVCNT 16 void setup(); +static void cleanup(void); int runtest(); int dotest(int, int, int); int domisc(int, int, char*); @@ -103,10 +104,7 @@ int fd; /* file descriptor used by child */ int parent_pid; int pidlist[MAXCHILD]; char test_name[2]; /* childs test directory name */ -char *prog, *getcwd() ; - -char fuss[40] = ""; /* directory to do this in */ -char homedir[200]= ""; /* where we started */ +char *prog; int local_flag; @@ -141,10 +139,8 @@ int main (ac, av) tst_resm(TFAIL, "Test failed."); } - tst_rmdir(); - tst_exit(); - } /* end for */ + cleanup(); return 0; } /*--------------------------------------------------------------*/ @@ -154,27 +150,8 @@ void setup() char wdbuf[MAXPATHLEN], *cwd ; int term(); - /* - * Make a directory to do this in; ignore error if already exists. - * Save starting directory. - */ - - if ( (cwd = getcwd(homedir, sizeof( homedir))) == NULL ) { - tst_resm(TBROK,"Failed to get corrent directory") ; - tst_exit() ; - } - parent_pid = getpid(); tst_tmpdir(); - if (!fuss[0]) - sprintf(fuss, "%s/ftest07.%d", getcwd(wdbuf, sizeof( wdbuf)), getpid()); - - mkdir(fuss, 0755); - - if (chdir(fuss) < 0) { - tst_resm(TBROK,"\tCan't chdir(%s), error %d.", fuss, errno); - tst_exit() ; - } /* * Default values for run conditions. @@ -187,12 +164,17 @@ void setup() misc_intvl = 10; if (sigset(SIGTERM, (void (*)())term) == SIG_ERR) { - tst_resm(TBROK, " sigset failed: signo = 15") ; - tst_exit() ; + tst_brkm(TBROK, cleanup, " sigset failed: signo = 15") ; } } +static void cleanup(void) +{ + tst_rmdir(); + tst_exit(); +} + int runtest() { register int i; @@ -259,25 +241,6 @@ int runtest() local_flag = FAILED; } - chdir(homedir); - - pid = fork(); - if (pid < 0) { - tst_resm(TINFO, "System resource may be too low, fork() malloc()" - " etc are likely to fail."); - tst_resm(TBROK, "Test broken due to inability of fork."); - tst_exit(); - } - - if (pid == 0) { - execl("/bin/rm", "rm", "-rf", fuss, NULL); - exit(1); - } else - wait(&status); - if (status) { - tst_resm(TINFO, "CAUTION - ftest07, '%s' may not be removed", fuss); - } - sync(); /* safeness */ return 0; }