robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2002 |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 4 | * Copyright (c) Cyril Hrubis chrubis@suse.cz 2009 |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 14 | * the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * NAME |
| 23 | * ftest03.c -- test file I/O with readv and writev (ported from SPIE section2/filesuite/ftest4.c, by Airong Zhang) |
| 24 | * |
| 25 | * CALLS |
| 26 | * lseek, readv, writev, |
| 27 | * truncate, ftruncate, fsync, sync, fstat |
| 28 | * |
| 29 | * ALGORITHM |
| 30 | * A bitmap is used to map pieces of a file. |
| 31 | * Loop: pick a random piece of the file |
| 32 | * if we haven't seen it before make sure it is zero, |
| 33 | * write pattern |
| 34 | * if we have seen it before make sure correct pattern. |
| 35 | * |
| 36 | * This was originally written by rbk - was program tfio.c |
| 37 | * Modified by dale to integrate with test suites. |
| 38 | * Modified by G. Stevens to use readv and writev. |
| 39 | * Modofied by K. Hakim to integrate with SPIES. |
| 40 | * |
| 41 | * RESTRICTIONS |
| 42 | * 1. Runs a long time with default args - can take others on input |
| 43 | * line. Use with "term mode". |
| 44 | * If run on vax the ftruncate will not be random - will always go to |
| 45 | * start of file. NOTE: produces a very high load average!! |
| 46 | * |
| 47 | * 2. The "csize" argument must be evenly divisible by MAXIOVCNT. |
| 48 | * |
| 49 | * CAUTION!! |
| 50 | * If a file is supplied to this program with the "-f" option |
| 51 | * it will be removed with a system("rm -rf filename") call. |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 52 | * |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 53 | */ |
| 54 | |
| 55 | #define _XOPEN_SOURCE 500 |
| 56 | #include <sys/types.h> |
| 57 | #include <sys/param.h> |
| 58 | #include <sys/wait.h> |
| 59 | #include <sys/stat.h> |
vapier | f81795e | 2006-02-15 06:28:58 +0000 | [diff] [blame] | 60 | #include <errno.h> |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 61 | #include <sys/uio.h> |
| 62 | #include <fcntl.h> |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 63 | #include <signal.h> |
| 64 | #include <stdio.h> |
| 65 | #include <inttypes.h> |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 66 | #include "test.h" |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 67 | #include "libftest.h" |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 68 | |
| 69 | char *TCID = "ftest03"; |
| 70 | int TST_TOTAL = 1; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 71 | |
| 72 | #define PASSED 1 |
| 73 | #define FAILED 0 |
| 74 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 75 | static void setup(void); |
| 76 | static void runtest(void); |
| 77 | static void dotest(int, int, int); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 78 | static void domisc(int, int, char *); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 79 | static void term(int sig); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 80 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 81 | #define MAXCHILD 25 |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 82 | #define K_1 1024 |
| 83 | #define K_2 2048 |
| 84 | #define K_4 4096 |
| 85 | #define MAXIOVCNT 16 |
| 86 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 87 | static int csize; /* chunk size */ |
| 88 | static int iterations; /* # total iterations */ |
| 89 | static int max_size; /* max file size */ |
| 90 | static int misc_intvl; /* for doing misc things; 0 ==> no */ |
| 91 | static int nchild; /* how many children */ |
| 92 | static int fd; /* file descriptor used by child */ |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 93 | static int parent_pid; |
| 94 | static int pidlist[MAXCHILD]; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 95 | static char test_name[2]; /* childs test directory name */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 96 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 97 | static char fuss[MAXPATHLEN]; /* directory to do this in */ |
| 98 | static char homedir[MAXPATHLEN]; /* where we started */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 99 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 100 | static int local_flag; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 101 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 102 | int main(int ac, char *av[]) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 103 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 104 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 105 | const char *msg; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 106 | |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 107 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 7a73eab | 2010-11-09 22:45:42 -0800 | [diff] [blame] | 108 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 109 | |
| 110 | setup(); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 111 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 112 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 113 | |
| 114 | local_flag = PASSED; |
| 115 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 116 | runtest(); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 117 | |
| 118 | if (local_flag == PASSED) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 119 | tst_resm(TPASS, "Test passed."); |
| 120 | } else { |
| 121 | tst_resm(TFAIL, "Test failed."); |
| 122 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 123 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 124 | tst_rmdir(); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 125 | /* ??? so we are doing only one loop here ??? */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 126 | tst_exit(); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 129 | tst_exit(); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 130 | } |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 131 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 132 | static void setup(void) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 133 | { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 134 | char wdbuf[MAXPATHLEN]; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | * Make a directory to do this in; ignore error if already exists. |
| 138 | * Save starting directory. |
| 139 | */ |
| 140 | tst_tmpdir(); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 141 | |
| 142 | if (getcwd(homedir, sizeof(homedir)) == NULL) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 143 | tst_brkm(TBROK | TERRNO, NULL, "getcwd() failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | parent_pid = getpid(); |
| 147 | |
| 148 | if (!fuss[0]) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 149 | sprintf(fuss, "%s/ftest03.%d", getcwd(wdbuf, sizeof(wdbuf)), |
| 150 | getpid()); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 151 | |
| 152 | mkdir(fuss, 0755); |
| 153 | |
| 154 | if (chdir(fuss) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 155 | tst_brkm(TBROK, NULL, "\tCan't chdir(%s), error %d.", fuss, |
| 156 | errno); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 157 | } |
| 158 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 159 | /* |
| 160 | * Default values for run conditions. |
| 161 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 162 | iterations = 10; |
| 163 | nchild = 5; |
| 164 | csize = K_2; /* should run with 1, 2, and 4 K sizes */ |
| 165 | max_size = K_1 * K_1; |
| 166 | misc_intvl = 10; |
| 167 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 168 | if (sigset(SIGTERM, term) == SIG_ERR) { |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 169 | perror("sigset failed"); |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 170 | tst_brkm(TBROK, NULL, " sigset failed: signo = 15"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 171 | } |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 172 | } |
| 173 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 174 | static void runtest(void) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 175 | { |
Garrett Cooper | 7a73eab | 2010-11-09 22:45:42 -0800 | [diff] [blame] | 176 | pid_t pid; |
| 177 | int child, count, i, nwait, status; |
| 178 | |
| 179 | nwait = 0; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 180 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 181 | for (i = 0; i < nchild; i++) { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 182 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 183 | test_name[0] = 'a' + i; |
| 184 | test_name[1] = '\0'; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 185 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 186 | fd = open(test_name, O_RDWR | O_CREAT | O_TRUNC, 0666); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 187 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 188 | if (fd < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 189 | tst_brkm(TBROK, NULL, "\tError %d creating %s/%s.", |
| 190 | errno, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 191 | fuss, test_name); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 192 | } |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 193 | |
| 194 | if ((child = fork()) == 0) { |
| 195 | dotest(nchild, i, fd); |
| 196 | tst_exit(); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | close(fd); |
| 200 | |
| 201 | if (child < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 202 | tst_brkm(TBROK | TERRNO, NULL, "fork failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 203 | } else { |
| 204 | pidlist[i] = child; |
| 205 | nwait++; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * Wait for children to finish. |
| 211 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 212 | count = 0; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 213 | |
| 214 | while (1) { |
| 215 | if ((child = wait(&status)) >= 0) { |
| 216 | //tst_resm(TINFO, "\tTest{%d} exited status = 0x%x", child, status); |
| 217 | if (status) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 218 | tst_resm(TFAIL, |
| 219 | "\tTest{%d} failed, expected 0 exit.", |
| 220 | child); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 221 | local_flag = FAILED; |
| 222 | } |
| 223 | ++count; |
| 224 | } else { |
| 225 | if (errno != EINTR) |
| 226 | break; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 227 | } |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /* |
| 231 | * Should have collected all children. |
| 232 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 233 | if (count != nwait) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 234 | tst_resm(TFAIL, "\tWrong # children waited on, count = %d", |
| 235 | count); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 236 | local_flag = FAILED; |
| 237 | } |
| 238 | |
| 239 | chdir(homedir); |
| 240 | |
| 241 | pid = fork(); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 242 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 243 | if (pid < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 244 | tst_brkm(TBROK | TERRNO, sync, "fork failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 245 | tst_exit(); |
| 246 | } |
| 247 | |
| 248 | if (pid == 0) { |
robbiew | 7fdd514 | 2005-02-07 19:39:54 +0000 | [diff] [blame] | 249 | execl("/bin/rm", "rm", "-rf", fuss, NULL); |
Garrett Cooper | 7a73eab | 2010-11-09 22:45:42 -0800 | [diff] [blame] | 250 | exit(1); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 251 | } else |
| 252 | wait(&status); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 253 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 254 | if (status) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 255 | tst_resm(TINFO, "CAUTION - ftest03, '%s' may not be removed", |
| 256 | fuss); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 257 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 258 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 259 | sync(); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /* |
| 263 | * dotest() |
| 264 | * Children execute this. |
| 265 | * |
| 266 | * Randomly read/mod/write chunks with known pattern and check. |
| 267 | * When fill sectors, iterate. |
| 268 | */ |
| 269 | |
| 270 | #define NMISC 4 |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 271 | enum m_type { m_fsync, m_trunc, m_fstat }; |
| 272 | char *m_str[] = { |
| 273 | "fsync", "trunc", "sync", "fstat" |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 274 | }; |
| 275 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 276 | int misc_cnt[NMISC]; /* counts # of each kind of misc */ |
| 277 | int file_max; /* file-max size */ |
| 278 | int nchunks; |
| 279 | int last_trunc = -1; |
| 280 | int tr_flag; |
| 281 | enum m_type type = m_fsync; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 282 | |
| 283 | #define CHUNK(i) ((i) * csize) |
| 284 | #define NEXTMISC ((rand() % misc_intvl) + 5) |
| 285 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 286 | static void dotest(int testers, int me, int fd) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 287 | { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 288 | char *bits, *hold_bits; |
| 289 | char val; |
| 290 | int chunk, whenmisc, xfr, count, collide, i; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 291 | |
| 292 | /* Stuff for the readv call */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 293 | struct iovec r_iovec[MAXIOVCNT]; |
| 294 | int r_ioveclen; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 295 | |
| 296 | /* Stuff for the writev call */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 297 | struct iovec val_iovec[MAXIOVCNT]; |
| 298 | struct iovec zero_iovec[MAXIOVCNT]; |
| 299 | int w_ioveclen; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 300 | |
| 301 | nchunks = max_size / csize; |
Garrett Cooper | f01306b | 2010-11-05 11:14:08 -0700 | [diff] [blame] | 302 | whenmisc = 0; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 303 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 304 | if ((bits = malloc((nchunks + 7) / 8)) == 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 305 | tst_brkm(TBROK, NULL, "\tmalloc failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 308 | if ((hold_bits = malloc((nchunks + 7) / 8)) == 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 309 | tst_brkm(TBROK, NULL, "\tmalloc failed"); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 312 | /*Allocate memory for the iovec buffers and init the iovec arrays */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 313 | r_ioveclen = w_ioveclen = csize / MAXIOVCNT; |
| 314 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 315 | /* Please note that the above statement implies that csize |
| 316 | * be evenly divisible by MAXIOVCNT. |
| 317 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 318 | for (i = 0; i < MAXIOVCNT; i++) { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 319 | if ((r_iovec[i].iov_base = calloc(r_ioveclen, 1)) == 0) { |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 320 | tst_brkm(TBROK, NULL, "\tmalloc failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 321 | /* tst_exit(); */ |
| 322 | } |
| 323 | r_iovec[i].iov_len = r_ioveclen; |
| 324 | |
| 325 | /* Allocate unused memory areas between all the buffers to |
| 326 | * make things more diffult for the OS. |
| 327 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 328 | if (malloc((i + 1) * 8) == NULL) { |
| 329 | tst_brkm(TBROK, NULL, "\tmalloc failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 330 | } |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 331 | |
| 332 | if ((val_iovec[i].iov_base = calloc(w_ioveclen, 1)) == 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 333 | tst_brkm(TBROK, NULL, "\tmalloc failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 334 | } |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 335 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 336 | val_iovec[i].iov_len = w_ioveclen; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 337 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 338 | if (malloc((i + 1) * 8) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 339 | tst_brkm(TBROK, NULL, "\tmalloc failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 340 | } |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 341 | |
| 342 | if ((zero_iovec[i].iov_base = calloc(w_ioveclen, 1)) == 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 343 | tst_brkm(TBROK, NULL, "\tmalloc failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 344 | } |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 345 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 346 | zero_iovec[i].iov_len = w_ioveclen; |
| 347 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 348 | if (malloc((i + 1) * 8) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 349 | tst_brkm(TBROK, NULL, "\tmalloc failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | /* |
| 353 | * No init sectors; allow file to be sparse. |
| 354 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 355 | val = (64 / testers) * me + 1; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 356 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 357 | /* |
| 358 | * For each iteration: |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 359 | * zap bits array |
| 360 | * loop |
| 361 | * pick random chunk, read it. |
| 362 | * if corresponding bit off { |
| 363 | * verify = 0. (sparse file) |
| 364 | * ++count; |
| 365 | * } else |
| 366 | * verify = val. |
| 367 | * write "val" on it. |
| 368 | * repeat unitl count = nchunks. |
| 369 | * ++val. |
| 370 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 371 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 372 | srand(getpid()); |
| 373 | |
| 374 | if (misc_intvl) |
| 375 | whenmisc = NEXTMISC; |
| 376 | |
| 377 | while (iterations-- > 0) { |
| 378 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 379 | for (i = 0; i < NMISC; i++) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 380 | misc_cnt[i] = 0; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 381 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 382 | ftruncate(fd, 0); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 383 | file_max = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 384 | memset(bits, 0, (nchunks + 7) / 8); |
| 385 | memset(hold_bits, 0, (nchunks + 7) / 8); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 386 | |
| 387 | /* Have to fill the val and zero iov buffers in a different manner |
| 388 | */ |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 389 | for (i = 0; i < MAXIOVCNT; i++) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 390 | memset(val_iovec[i].iov_base, val, |
| 391 | val_iovec[i].iov_len); |
| 392 | memset(zero_iovec[i].iov_base, 0, |
| 393 | zero_iovec[i].iov_len); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 394 | |
| 395 | } |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 396 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 397 | count = 0; |
| 398 | collide = 0; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 399 | |
| 400 | while (count < nchunks) { |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 401 | chunk = rand() % nchunks; |
| 402 | /* |
| 403 | * Read it. |
| 404 | */ |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 405 | if (lseek(fd, CHUNK(chunk), 0) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 406 | tst_brkm(TFAIL, |
| 407 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 408 | "\tTest[%d]: lseek(0) fail at %x, errno = %d.", |
| 409 | me, CHUNK(chunk), errno); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 410 | } |
| 411 | if ((xfr = readv(fd, &r_iovec[0], MAXIOVCNT)) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 412 | tst_brkm(TFAIL, |
| 413 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 414 | "\tTest[%d]: readv fail at %x, errno = %d.", |
| 415 | me, CHUNK(chunk), errno); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 416 | } |
| 417 | /* |
| 418 | * If chunk beyond EOF just write on it. |
| 419 | * Else if bit off, haven't seen it yet. |
| 420 | * Else, have. Verify values. |
| 421 | */ |
| 422 | if (CHUNK(chunk) >= file_max) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 423 | bits[chunk / 8] |= (1 << (chunk % 8)); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 424 | ++count; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 425 | } else if ((bits[chunk / 8] & (1 << (chunk % 8))) == 0) { |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 426 | if (xfr != csize) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 427 | tst_brkm(TFAIL, |
| 428 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 429 | "\tTest[%d]: xfr=%d != %d, zero read.", |
| 430 | me, xfr, csize); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 431 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 432 | for (i = 0; i < MAXIOVCNT; i++) { |
| 433 | if (memcmp |
| 434 | (r_iovec[i].iov_base, |
| 435 | zero_iovec[i].iov_base, |
| 436 | r_iovec[i].iov_len)) { |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 437 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 438 | "\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d file_max 0x%x, should be 0.", |
| 439 | me, CHUNK(chunk), val, |
| 440 | count, xfr, file_max); |
| 441 | tst_resm(TINFO, |
| 442 | "\tTest[%d]: last_trunc = 0x%x.", |
| 443 | me, last_trunc); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 444 | sync(); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 445 | ft_dumpiov(&r_iovec[i]); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 446 | ft_dumpbits(bits, |
| 447 | (nchunks + 7) / 8); |
| 448 | ft_orbits(hold_bits, bits, |
| 449 | (nchunks + 7) / 8); |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 450 | tst_resm(TINFO, "\tHold "); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 451 | ft_dumpbits(hold_bits, |
| 452 | (nchunks + 7) / 8); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 453 | tst_exit(); |
| 454 | } |
| 455 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 456 | bits[chunk / 8] |= (1 << (chunk % 8)); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 457 | ++count; |
| 458 | } else { |
| 459 | if (xfr != csize) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 460 | tst_brkm(TFAIL, |
| 461 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 462 | "\tTest[%d]: xfr=%d != %d, val read.", |
| 463 | me, xfr, csize); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 464 | } |
| 465 | ++collide; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 466 | for (i = 0; i < MAXIOVCNT; i++) { |
| 467 | if (memcmp |
| 468 | (r_iovec[i].iov_base, |
| 469 | val_iovec[i].iov_base, |
| 470 | r_iovec[i].iov_len)) { |
| 471 | tst_resm(TFAIL, |
| 472 | "\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d file_max 0x%x.", |
| 473 | me, CHUNK(chunk), val, |
| 474 | count, xfr, file_max); |
| 475 | tst_resm(TINFO, |
| 476 | "\tTest[%d]: last_trunc = 0x%x.", |
| 477 | me, last_trunc); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 478 | sync(); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 479 | ft_dumpiov(&r_iovec[i]); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 480 | ft_dumpbits(bits, |
| 481 | (nchunks + 7) / 8); |
| 482 | ft_orbits(hold_bits, bits, |
| 483 | (nchunks + 7) / 8); |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 484 | tst_resm(TINFO, "\tHold "); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 485 | ft_dumpbits(hold_bits, |
| 486 | (nchunks + 7) / 8); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 487 | tst_exit(); |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | /* |
| 492 | * Writev it. |
| 493 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 494 | if (lseek(fd, -xfr, 1) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 495 | tst_brkm(TFAIL, |
| 496 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 497 | "\tTest[%d]: lseek(1) fail at %x, errno = %d.", |
| 498 | me, CHUNK(chunk), errno); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 499 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 500 | if ((xfr = |
| 501 | writev(fd, &val_iovec[0], MAXIOVCNT)) < csize) { |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 502 | if (errno == ENOSPC) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 503 | tst_resm(TFAIL, |
| 504 | "\tTest[%d]: no space, exiting.", |
| 505 | me); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 506 | fsync(fd); |
| 507 | tst_exit(); |
| 508 | } |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 509 | tst_brkm(TFAIL, |
| 510 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 511 | "\tTest[%d]: writev fail at %x xfr %d, errno = %d.", |
| 512 | me, CHUNK(chunk), xfr, errno); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 513 | } |
| 514 | if (CHUNK(chunk) + csize > file_max) |
| 515 | file_max = CHUNK(chunk) + csize; |
| 516 | /* |
| 517 | * If hit "misc" interval, do it. |
| 518 | */ |
| 519 | if (misc_intvl && --whenmisc <= 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 520 | ft_orbits(hold_bits, bits, (nchunks + 7) / 8); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 521 | domisc(me, fd, bits); |
| 522 | whenmisc = NEXTMISC; |
| 523 | } |
| 524 | if (count + collide > 2 * nchunks) |
| 525 | break; |
| 526 | } |
| 527 | |
| 528 | /* |
| 529 | * End of iteration, maybe before doing all chunks. |
| 530 | */ |
| 531 | |
| 532 | fsync(fd); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 533 | ++misc_cnt[m_fsync]; |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 534 | //tst_resm(TINFO, "\tTest{%d} val %d done, count = %d, collide = {%d}", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 535 | // me, val, count, collide); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 536 | //for (i = 0; i < NMISC; i++) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 537 | // tst_resm(TINFO, "\t\tTest{%d}: {%d} %s's.", me, misc_cnt[i], m_str[i]); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 538 | ++val; |
| 539 | } |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /* |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 543 | * Inject misc syscalls into the thing. |
| 544 | */ |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 545 | static void domisc(int me, int fd, char *bits) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 546 | { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 547 | int chunk; |
| 548 | struct stat sb; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 549 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 550 | if (type > m_fstat) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 551 | type = m_fsync; |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 552 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 553 | switch (type) { |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 554 | case m_fsync: |
| 555 | if (fsync(fd) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 556 | tst_brkm(TFAIL, NULL, "\tTest[%d]: fsync error %d.", |
| 557 | me, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 558 | errno); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 559 | } |
| 560 | break; |
| 561 | case m_trunc: |
| 562 | chunk = rand() % (file_max / csize); |
| 563 | file_max = CHUNK(chunk); |
| 564 | last_trunc = file_max; |
| 565 | if (tr_flag) { |
| 566 | if (ftruncate(fd, file_max) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 567 | tst_brkm(TFAIL, |
| 568 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 569 | "\tTest[%d]: ftruncate error %d @ 0x%x.", |
| 570 | me, errno, file_max); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 571 | } |
| 572 | tr_flag = 0; |
| 573 | } else { |
| 574 | if (truncate(test_name, file_max) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 575 | tst_brkm(TFAIL, |
| 576 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 577 | "\tTest[%d]: truncate error %d @ 0x%x.", |
| 578 | me, errno, file_max); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 579 | } |
| 580 | tr_flag = 1; |
| 581 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 582 | for (; chunk % 8 != 0; chunk++) |
| 583 | bits[chunk / 8] &= ~(1 << (chunk % 8)); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 584 | for (; chunk < nchunks; chunk += 8) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 585 | bits[chunk / 8] = 0; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 586 | break; |
| 587 | case m_fstat: |
| 588 | if (fstat(fd, &sb) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 589 | tst_brkm(TFAIL, NULL, "\tTest[%d]: fstat() error %d.", |
| 590 | me, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 591 | errno); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 592 | } |
| 593 | if (sb.st_size != file_max) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 594 | tst_brkm(TFAIL, |
| 595 | NULL, "\tTest[%d]: fstat() mismatch; st_size=%" |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 596 | PRIx64 ",file_max=%x.", me, |
| 597 | (int64_t) sb.st_size, file_max); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 598 | } |
| 599 | break; |
| 600 | } |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 601 | |
| 602 | ++misc_cnt[type]; |
| 603 | ++type; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 604 | } |
| 605 | |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 606 | /* |
| 607 | * SIGTERM signal handler. |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 608 | */ |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 609 | static void term(int sig LTP_ATTRIBUTE_UNUSED) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 610 | { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 611 | int i; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 612 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 613 | tst_resm(TINFO, "\tterm -[%d]- got sig term.", getpid()); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 614 | |
| 615 | /* |
| 616 | * If run by hand we like to have the parent send the signal to |
| 617 | * the child processes. This makes life easy. |
| 618 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 619 | if (parent_pid == getpid()) { |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 620 | for (i = 0; i < nchild; i++) |
| 621 | if (pidlist[i]) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 622 | kill(pidlist[i], SIGTERM); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 623 | return; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 624 | } |
| 625 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 626 | tst_resm(TINFO, "\tunlinking '%s'", test_name); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 627 | |
| 628 | close(fd); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 629 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 630 | if (unlink(test_name)) |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 631 | tst_resm(TBROK, "Unlink of '%s' failed, errno = %d.", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 632 | test_name, errno); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 633 | else |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 634 | tst_resm(TBROK, "Unlink of '%s' successful.", test_name); |
subrata_modak | f17ac84 | 2009-09-07 09:06:31 +0000 | [diff] [blame] | 635 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 636 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 637 | } |