robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2002 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 20 | /* |
| 21 | * NAME |
| 22 | * ftest02.c -- test inode things (ported from SPIE section2, filesuite, by Airong Zhang) |
| 23 | * |
| 24 | * CALLS |
| 25 | * open, close, read, write, lseek, |
| 26 | * unlink, chdir |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 27 | * |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 28 | * |
| 29 | * ALGORITHM |
| 30 | * |
| 31 | * |
| 32 | * ftest02 [-f tmpdirname] nchild iterations [partition] |
| 33 | * |
| 34 | * This forks some child processes, they do some random operations |
| 35 | * which use lots of directory operations. |
| 36 | * |
| 37 | * RESTRICTIONS |
| 38 | * Runs a long time with default args - can take others on input |
| 39 | * line. Use with "term mode". |
| 40 | * If run on vax the ftruncate will not be random - will always go to |
| 41 | * start of file. NOTE: produces a very high load average!! |
| 42 | * |
| 43 | */ |
| 44 | |
| 45 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 46 | #include <stdio.h> |
| 47 | #include "test.h" |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 48 | #include "usctest.h" |
| 49 | #include <sys/types.h> |
| 50 | #include <sys/param.h> |
| 51 | #include <sys/wait.h> |
| 52 | #include <fcntl.h> |
| 53 | #include <sys/stat.h> |
vapier | f81795e | 2006-02-15 06:28:58 +0000 | [diff] [blame] | 54 | #include <errno.h> |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 55 | #include <sys/mount.h> |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 56 | #include <signal.h> |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 57 | #include <unistd.h> |
| 58 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 59 | #define MAXCHILD 25 |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 60 | #define K_1 1024 |
| 61 | #define K_2 2048 |
| 62 | #define K_4 4096 |
| 63 | |
| 64 | |
| 65 | char *TCID = "ftest02"; |
| 66 | int TST_TOTAL = 1; |
| 67 | extern int Tst_count; |
| 68 | |
| 69 | #define PASSED 1 |
| 70 | #define FAILED 0 |
| 71 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 72 | static void crfile(int, int); |
| 73 | static void unlfile(int, int); |
| 74 | static void fussdir(int, int); |
| 75 | static void dotest(int, int); |
| 76 | static void dowarn(int, char*, char*); |
| 77 | static void mkname(char*, int, int); |
| 78 | static void term(int sig); |
| 79 | static void cleanup(void); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 80 | |
| 81 | #define M (1024*1024) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 82 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 83 | int iterations; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 84 | int nchild; |
| 85 | int parent_pid; |
| 86 | int pidlist[MAXCHILD]; |
| 87 | |
| 88 | char homedir[MAXPATHLEN]; |
| 89 | char dirname[MAXPATHLEN]; |
| 90 | char tmpname[MAXPATHLEN]; |
| 91 | char *prog; |
| 92 | int dirlen; |
| 93 | int mnt = 0; |
| 94 | char startdir[MAXPATHLEN], mntpoint[MAXPATHLEN], newfsstring[90]; |
| 95 | char *partition; |
| 96 | char *cwd; |
| 97 | char *fstyp; |
| 98 | int local_flag; |
| 99 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 100 | int main(int ac, char *av[]) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 101 | { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 102 | int k, j, pid, child, status, count; |
| 103 | char name[128]; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 104 | |
| 105 | /* |
| 106 | * Default values for run conditions. |
| 107 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 108 | iterations = 50; |
| 109 | nchild = 5; |
| 110 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 111 | if (signal(SIGTERM, term) == SIG_ERR) { |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 112 | tst_resm(TFAIL, "first signal failed"); |
| 113 | tst_exit(); |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | * Make a directory to do this in; ignore error if already exists. |
| 118 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 119 | local_flag = PASSED; |
| 120 | parent_pid = getpid(); |
| 121 | tst_tmpdir(); |
| 122 | |
| 123 | if (!startdir[0]) { |
| 124 | if (getcwd(startdir, MAXPATHLEN) == NULL) { |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 125 | tst_resm(TBROK,"getcwd failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 126 | tst_exit(); |
| 127 | } |
| 128 | } |
| 129 | cwd = startdir; |
| 130 | strcat(dirname, cwd); |
| 131 | sprintf(tmpname, "/ftest02.%d", getpid()); |
| 132 | strcat(dirname, tmpname); |
| 133 | strcat(homedir, cwd); |
| 134 | sprintf(tmpname, "/ftest02h.%d", getpid()); |
| 135 | strcat(homedir, tmpname); |
| 136 | |
| 137 | mkdir(dirname, 0755); |
| 138 | mkdir(homedir, 0755); |
| 139 | if (chdir(dirname) < 0) { |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 140 | tst_resm(TBROK,"\tCan't chdir(%s), error %d.", dirname, errno); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 141 | cleanup(); |
| 142 | tst_exit(); |
| 143 | } |
| 144 | dirlen = strlen(dirname); |
| 145 | if (chdir(homedir) < 0) { |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 146 | tst_resm(TBROK,"\tCan't chdir(%s), error %d.", homedir, errno); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 147 | cleanup(); |
| 148 | tst_exit(); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | for(k = 0; k < nchild; k++) { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 153 | if ((child = fork()) == 0) { |
| 154 | dotest(k, iterations); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 155 | exit(0); |
| 156 | } |
| 157 | if (child < 0) { |
| 158 | tst_resm(TINFO, "System resource may be too low, fork() malloc()" |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 159 | " etc are likely to fail."); |
| 160 | tst_resm(TBROK, "Test broken due to inability of fork."); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 161 | cleanup(); |
| 162 | } |
| 163 | pidlist[k] = child; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 164 | } |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 165 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 166 | /* |
| 167 | * Wait for children to finish. |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 168 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 169 | count = 0; |
| 170 | while((child = wait(&status)) > 0) { |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 171 | //tst_resm(TINFO,"Test{%d} exited status = 0x%x", child, status); |
| 172 | //tst_resm(TINFO,"status is %d",status); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 173 | if (status) { |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 174 | tst_resm(TFAIL,"Test{%d} failed, expected 0 exit.", child); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 175 | local_flag = FAILED; |
| 176 | } |
| 177 | ++count; |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Should have collected all children. |
| 182 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 183 | if (count != nchild) { |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 184 | tst_resm(TFAIL,"Wrong # children waited on, count = %d", count); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 185 | local_flag = FAILED; |
| 186 | } |
| 187 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 188 | if (local_flag == FAILED) |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 189 | tst_resm(TFAIL, "Test failed in fork-wait part."); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 190 | else |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 191 | tst_resm(TPASS, "Test passed in fork-wait part."); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 192 | |
| 193 | if (iterations > 26) |
| 194 | iterations = 26; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 195 | |
| 196 | for (k = 0; k < nchild; k++) |
| 197 | for (j = 0; j < iterations + 1; j++) { |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 198 | mkname(name, k, j); |
| 199 | rmdir(name); |
| 200 | unlink(name); |
| 201 | } |
| 202 | |
| 203 | chdir(startdir); |
| 204 | |
| 205 | pid = fork(); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 206 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 207 | if (pid < 0) { |
| 208 | tst_resm(TINFO, "System resource may be too low, fork() malloc()" |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 209 | " etc are likely to fail."); |
| 210 | tst_resm(TBROK, "Test broken due to inability of fork."); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 211 | cleanup(); |
| 212 | } |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 213 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 214 | if (pid == 0) { |
robbiew | 7fdd514 | 2005-02-07 19:39:54 +0000 | [diff] [blame] | 215 | execl("/bin/rm", "rm", "-rf", homedir, NULL); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 216 | exit(1); |
| 217 | } else |
| 218 | wait(&status); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 219 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 220 | if (status) |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 221 | tst_resm(TINFO,"CAUTION - ftest02, '%s' may not have been removed.", |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 222 | homedir); |
| 223 | |
| 224 | pid = fork(); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 225 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 226 | if (pid < 0) { |
| 227 | tst_resm(TINFO, "System resource may be too low, fork() malloc()" |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 228 | " etc are likely to fail."); |
| 229 | tst_resm(TBROK, "Test broken due to inability of fork."); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 230 | cleanup(); |
| 231 | } |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 232 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 233 | if (pid == 0) { |
robbiew | 7fdd514 | 2005-02-07 19:39:54 +0000 | [diff] [blame] | 234 | execl("/bin/rm", "rm", "-rf", dirname, NULL); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 235 | exit(1); |
| 236 | } else |
| 237 | wait(&status); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 238 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 239 | if (status) { |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 240 | tst_resm(TINFO,"CAUTION - ftest02, '%s' may not have been removed.", |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 241 | dirname); |
| 242 | } |
| 243 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 244 | sync(); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 245 | |
| 246 | cleanup(); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 247 | tst_exit(); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 248 | } |
| 249 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 250 | #define warn(val,m1,m2) if ((val) < 0) dowarn(me,m1,m2) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 251 | |
| 252 | /* |
| 253 | * crfile() |
| 254 | * Create a file and write something into it. |
| 255 | */ |
| 256 | |
| 257 | char crmsg[] = "Gee, let's write something in the file!\n"; |
| 258 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 259 | static void crfile(int me, int count) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 260 | { |
| 261 | int fd; |
| 262 | int val; |
| 263 | char fname[128]; |
| 264 | char buf[128]; |
| 265 | |
| 266 | mkname(fname, me, count); |
| 267 | |
| 268 | fd = open(fname, O_RDWR|O_CREAT|O_TRUNC, 0666); |
| 269 | if (fd < 0 && errno == EISDIR) { |
| 270 | val = rmdir(fname); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 271 | warn(val, "rmdir", fname); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 272 | fd = open(fname, O_RDWR|O_CREAT|O_TRUNC, 0666); |
| 273 | } |
| 274 | warn(fd, "creating", fname); |
| 275 | |
| 276 | val = lseek(fd, (rand() % M), 0); |
| 277 | warn(val, "lseek", 0); |
| 278 | |
| 279 | val = write(fd, crmsg, sizeof(crmsg)-1); |
| 280 | warn(val, "write", 0); |
| 281 | |
| 282 | val = lseek(fd, -(sizeof(crmsg)-1), 1); |
| 283 | warn(val, "lseek", 0); |
| 284 | |
| 285 | val = read(fd, buf, sizeof(crmsg)-1); |
| 286 | warn(val, "read", 0); |
| 287 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 288 | if (strncmp(crmsg, buf, sizeof(crmsg)-1)) |
| 289 | dowarn(me, "compare", 0); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 290 | |
| 291 | val = close(fd); |
| 292 | warn(val, "close", 0); |
| 293 | } |
| 294 | |
| 295 | /* |
| 296 | * unlfile() |
| 297 | * Unlink some of the files. |
| 298 | */ |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 299 | static void unlfile(int me, int count) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 300 | { |
| 301 | int i; |
| 302 | int val; |
| 303 | char fname[128]; |
| 304 | |
| 305 | i = count - 10; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 306 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 307 | if (i < 0) |
| 308 | i = 0; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 309 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 310 | for(; i < count; i++) { |
| 311 | mkname(fname, me, i); |
| 312 | val = rmdir(fname); |
| 313 | if (val < 0 ) |
| 314 | val = unlink(fname); |
| 315 | if (val == 0 || errno == ENOENT) |
| 316 | continue; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 317 | dowarn(me, "unlink", fname); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * fussdir() |
| 323 | * Make a directory, put stuff in it, remove it, and remove directory. |
| 324 | * |
| 325 | * Randomly leave the directory there. |
| 326 | */ |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 327 | static void fussdir(int me, int count) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 328 | { |
| 329 | int val; |
| 330 | char dir[128]; |
| 331 | char fname[128]; |
| 332 | char savedir[128]; |
| 333 | |
| 334 | mkname(dir, me, count); |
| 335 | rmdir(dir); unlink(dir); /* insure not there */ |
| 336 | |
| 337 | val = mkdir(dir, 0755); |
| 338 | warn(val, "mkdir", dir); |
| 339 | |
| 340 | /* |
| 341 | * Arrange to create files in the directory. |
| 342 | */ |
| 343 | |
| 344 | strcpy(savedir, dirname); |
| 345 | strcpy(dirname, ""); |
| 346 | |
| 347 | val = chdir(dir); |
| 348 | warn(val, "chdir", dir); |
| 349 | |
| 350 | crfile(me, count); |
| 351 | crfile(me, count+1); |
| 352 | |
| 353 | val = chdir(".."); |
| 354 | warn(val, "chdir", ".."); |
| 355 | |
| 356 | val = rmdir(dir); |
| 357 | if (val >= 0) { |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 358 | tst_resm(TFAIL,"Test[%d]: rmdir of non-empty %s succeeds!", me, dir); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 359 | tst_exit(); |
| 360 | } |
| 361 | |
| 362 | val = chdir(dir); |
| 363 | warn(val, "chdir", dir); |
| 364 | |
| 365 | mkname(fname, me, count); |
| 366 | val = unlink(fname); |
| 367 | warn(val, "unlink", fname); |
| 368 | |
| 369 | mkname(fname, me, count+1); |
| 370 | val = unlink(fname); |
| 371 | warn(val, "unlink", fname); |
| 372 | |
| 373 | val = chdir(homedir); |
| 374 | warn(val, "chdir", homedir); |
| 375 | |
| 376 | if (rand() & 0x01) { |
| 377 | val = rmdir(dir); |
| 378 | warn(val, "rmdir", dir); |
| 379 | } |
| 380 | |
| 381 | strcpy(dirname, savedir); |
| 382 | } |
| 383 | |
| 384 | |
| 385 | /* |
| 386 | * dotest() |
| 387 | * Children execute this. |
| 388 | * |
| 389 | * Randomly do an inode thing; loop for # iterations. |
| 390 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 391 | #define THING(p) {p, "p"} |
| 392 | |
| 393 | struct ino_thing { |
| 394 | void (*it_proc)(); |
| 395 | char *it_name; |
| 396 | } ino_thing[] = { |
| 397 | THING(crfile), |
| 398 | THING(unlfile), |
| 399 | THING(fussdir), |
| 400 | THING(sync), |
| 401 | }; |
| 402 | |
| 403 | #define NTHING (sizeof(ino_thing) / sizeof(ino_thing[0])) |
| 404 | |
| 405 | int thing_cnt[NTHING]; |
| 406 | int thing_last[NTHING]; |
| 407 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 408 | static void dotest(int me, int count) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 409 | { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 410 | int i, thing; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 411 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 412 | //tst_resm(TINFO,"Test %d pid %d starting.", me, getpid()); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 413 | |
| 414 | srand(getpid()); |
| 415 | for(i = 0; i < count; i++) { |
| 416 | thing = (rand() >> 3) % NTHING; |
| 417 | (*ino_thing[thing].it_proc)(me, i, ino_thing[thing].it_name); |
| 418 | ++thing_cnt[thing]; |
| 419 | } |
| 420 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 421 | //tst_resm(TINFO,"Test %d pid %d exiting.", me, getpid()); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 425 | static void dowarn(int me, char *m1, char *m2) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 426 | { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 427 | int err = errno; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 428 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 429 | tst_resm(TBROK,"Test[%d]: error %d on %s %s", |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 430 | me, err, m1, (m2 ? m2 : "")); |
| 431 | tst_exit(); |
| 432 | } |
| 433 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 434 | static void mkname(char *name, int me, int idx) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 435 | { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 436 | int len; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 437 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 438 | strcpy(name, dirname); |
| 439 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 440 | if (name[0]) { |
| 441 | len = dirlen+1; |
| 442 | name[len-1] = '/'; |
| 443 | } else |
| 444 | len = 0; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 445 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 446 | name[len+0] = 'A' + (me % 26); |
| 447 | name[len+1] = 'a' + (idx % 26); |
| 448 | name[len+2] = '\0'; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 449 | } |
| 450 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 451 | /* |
| 452 | * SIGTERM signal handler. |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 453 | */ |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 454 | static void term(int sig) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 455 | { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 456 | int i; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 457 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 458 | if (parent_pid == getpid()) { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 459 | for (i = 0; i < nchild; i++) |
| 460 | if (pidlist[i]) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 461 | kill(pidlist[i], SIGTERM); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 462 | return; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 463 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 464 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 465 | tst_resm(TBROK, "Child process exiting."); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 466 | tst_exit(); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 467 | } |
| 468 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 469 | static void cleanup(void) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 470 | { |
| 471 | char mount_buffer[1024]; |
| 472 | |
| 473 | if (mnt == 1) { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 474 | |
| 475 | if (chdir(startdir) < 0) |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 476 | tst_resm(TBROK,"Could not change to %s ", startdir); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 477 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 478 | if (!strcmp(fstyp, "cfs")) { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 479 | |
| 480 | sprintf(mount_buffer, "/bin/umount %s", partition); |
| 481 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 482 | if (system(mount_buffer) != 0) { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 483 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 484 | tst_resm(TBROK,"Unable to unmount %s from %s ", partition, mntpoint); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 485 | |
| 486 | if (umount(partition)) |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 487 | tst_resm(TBROK,"Unable to unmount %s from %s ", partition, mntpoint); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 488 | else |
| 489 | tst_resm(TINFO, "Forced umount for %s, /etc/mtab now dirty", partition); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 490 | } |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 491 | |
| 492 | } else |
| 493 | if (umount(partition)) |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 494 | tst_resm(TBROK,"Unable to unmount %s from %s ", partition, mntpoint); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 495 | |
| 496 | if (rmdir(mntpoint) != 0) |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 497 | tst_resm(TBROK,"Unable to rmdir %s ", mntpoint); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 498 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 499 | } |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame^] | 500 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 501 | tst_rmdir(); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 502 | } |