plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2003 |
| 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
| 22 | * aiotest1.c |
| 23 | * |
| 24 | * DESCRIPTION |
| 25 | * Perform aio read, write operations for given number of requests. |
| 26 | * Submit i/o for each request individually. |
| 27 | * Repeat the test for each of the following cases and measure time. |
| 28 | * Testblock1: Write one request at a time. |
| 29 | * Testblock2: Read one request at a time. |
| 30 | * Testblock3: Prepare, Write one request at a time. |
| 31 | * Testblock4: Prepare, Read one request at a time. |
| 32 | * Testblock5: Prepare, Write/Read one request at a time. |
| 33 | * Testblock6: Prepare, Write/Read/Verify one request at a time. |
| 34 | * |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 35 | * Author |
| 36 | * 08/24/2002 Narasimha Sharoff nsharoff@us.ibm.com |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | * History |
plars | 5be6259 | 2003-05-21 17:40:32 +0000 | [diff] [blame] | 41 | * 04/18/2003 nsharoff@us.ibm.com |
| 42 | * Updated |
| 43 | * 05/21/2003 Paul Larson plars@linuxtestproject.org |
| 44 | * Rewrote the test under LTP, using LTP test harness |
| 45 | * and other minor improvements and fixes |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 46 | */ |
| 47 | |
| 48 | #define _XOPEN_SOURCE 600 |
| 49 | |
subrata_modak | dd87629 | 2009-01-28 06:43:09 +0000 | [diff] [blame] | 50 | #include "test.h" |
subrata_modak | 030e753 | 2009-06-09 17:54:34 +0000 | [diff] [blame] | 51 | #include "config.h" |
subrata_modak | dd87629 | 2009-01-28 06:43:09 +0000 | [diff] [blame] | 52 | |
| 53 | char *TCID = "aio01"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 54 | int TST_TOTAL = 6; |
subrata_modak | dd87629 | 2009-01-28 06:43:09 +0000 | [diff] [blame] | 55 | |
| 56 | #ifdef HAVE_LIBAIO_H |
| 57 | |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 58 | #include <stdio.h> |
| 59 | #include <stdlib.h> |
| 60 | #include <unistd.h> |
| 61 | #include <fcntl.h> |
| 62 | #include <time.h> |
| 63 | #include <errno.h> |
| 64 | #include <libaio.h> |
| 65 | #include <sys/types.h> |
| 66 | #include <sys/stat.h> |
| 67 | #include <sys/time.h> |
| 68 | #include <sys/resource.h> |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 69 | |
subrata_modak | d1e1973 | 2009-08-30 17:04:40 +0000 | [diff] [blame] | 70 | static void help(void); |
| 71 | static void setup(void); |
| 72 | static void cleanup(void); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 73 | |
| 74 | #define mapsize (1 << 14) |
| 75 | |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 76 | int fd; |
| 77 | char *maddr; |
| 78 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 79 | size_t bufsize; /* Size of I/O, 8k default */ |
| 80 | io_context_t io_ctx; /* I/O Context */ |
| 81 | struct iocb **iocbs; /* I/O Control Blocks */ |
| 82 | char *srcbuf, *dstbuf; |
| 83 | char fname[128]; |
| 84 | char tbuf[80]; |
| 85 | int pos, nr; |
| 86 | struct stat s; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 87 | |
| 88 | struct test_case_t { |
| 89 | off_t newsize; |
| 90 | char *desc; |
| 91 | } TC[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 92 | { |
| 93 | mapsize - 8192, "ftruncate mmaped file to a smaller size"}, { |
| 94 | mapsize + 1024, "ftruncate mmaped file to a larger size"}, { |
| 95 | 0, "ftruncate mmaped file to 0 size"},}; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 96 | |
subrata_modak | d1e1973 | 2009-08-30 17:04:40 +0000 | [diff] [blame] | 97 | int main(int argc, char **argv) |
| 98 | { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 99 | int i, j, sec, usec; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 100 | int failflag = 0; |
| 101 | int bflag = 0, nflag = 0, Fflag = 0; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 102 | char *optb, *optn, *optF; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 103 | const char *msg; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 104 | struct io_event event; |
| 105 | static struct timespec ts; |
| 106 | struct timeval stv, etv; |
| 107 | |
| 108 | option_t options[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 109 | {"b:", &bflag, &optb}, |
| 110 | {"n:", &nflag, &optn}, |
| 111 | {"F:", &Fflag, &optF}, |
| 112 | {NULL, NULL, NULL} |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | msg = parse_opts(argc, argv, options, &help); |
Cyril Hrubis | cf0d626 | 2014-09-23 14:03:31 +0200 | [diff] [blame] | 116 | if (msg != NULL) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 117 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 118 | tst_exit(); |
| 119 | } |
| 120 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 121 | bufsize = (bflag ? atoi(optb) : 8192); |
| 122 | nr = (nflag ? atoi(optn) : 10); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 123 | if (Fflag) { |
| 124 | sprintf(fname, optF); |
| 125 | } else { |
| 126 | sprintf(fname, "aiofile"); |
| 127 | } |
| 128 | |
| 129 | setup(); |
| 130 | |
| 131 | /* TEST 1 */ |
| 132 | pos = 0; |
| 133 | gettimeofday(&stv, NULL); |
| 134 | io_prep_pwrite(iocbs[0], fd, srcbuf, bufsize, pos); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 135 | for (i = 0; i < nr; i++) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 136 | ts.tv_sec = 30; |
| 137 | ts.tv_nsec = 0; |
subrata_modak | 967caaf | 2008-07-12 21:31:07 +0000 | [diff] [blame] | 138 | do { |
| 139 | TEST(io_submit(io_ctx, 1, iocbs)); |
| 140 | } while (TEST_RETURN == -EAGAIN); |
| 141 | if (TEST_RETURN < 0) { |
Jan Stancek | 17ea0a9 | 2013-04-17 11:05:33 +0200 | [diff] [blame] | 142 | tst_resm(TFAIL, "Test 1: io_submit failed - retval=%ld" |
| 143 | ", errno=%d", TEST_RETURN, TEST_ERRNO); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 144 | failflag = 1; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 145 | continue; |
| 146 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 147 | while (io_getevents(io_ctx, 1, 1, &event, &ts) != 1) ; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 148 | gettimeofday(&etv, NULL); |
| 149 | } |
| 150 | if (!failflag) { |
| 151 | sec = etv.tv_sec - stv.tv_sec; |
| 152 | usec = etv.tv_usec - stv.tv_usec; |
| 153 | if (usec < 0) { |
| 154 | usec += 1000000; |
| 155 | sec--; |
| 156 | } |
| 157 | tst_resm(TPASS, "Test 1: %d writes in %3d.%06d sec", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 158 | nr, sec, usec); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /* TEST 2 */ |
| 162 | pos = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 163 | failflag = 0; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 164 | gettimeofday(&stv, NULL); |
| 165 | io_prep_pread(iocbs[0], fd, dstbuf, bufsize, pos); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 166 | for (i = 0; i < nr; i++) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 167 | ts.tv_sec = 30; |
| 168 | ts.tv_nsec = 0; |
subrata_modak | 967caaf | 2008-07-12 21:31:07 +0000 | [diff] [blame] | 169 | do { |
| 170 | TEST(io_submit(io_ctx, 1, iocbs)); |
| 171 | } while (TEST_RETURN == -EAGAIN); |
| 172 | if (TEST_RETURN < 0) { |
Jan Stancek | 17ea0a9 | 2013-04-17 11:05:33 +0200 | [diff] [blame] | 173 | tst_resm(TFAIL, "Test 2: io_submit failed - retval=%ld" |
| 174 | ", errno=%d", TEST_RETURN, TEST_ERRNO); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 175 | failflag = 1; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 176 | continue; |
| 177 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 178 | while (io_getevents(io_ctx, 1, 1, &event, &ts) != 1) ; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 179 | gettimeofday(&etv, NULL); |
| 180 | } |
| 181 | if (!failflag) { |
| 182 | sec = etv.tv_sec - stv.tv_sec; |
| 183 | usec = etv.tv_usec - stv.tv_usec; |
| 184 | if (usec < 0) { |
| 185 | usec += 1000000; |
| 186 | sec--; |
| 187 | } |
| 188 | tst_resm(TPASS, "Test 2: %d reads in %3d.%06d sec", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 189 | nr, sec, usec); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* TEST 3 */ |
| 193 | pos = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 194 | failflag = 0; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 195 | gettimeofday(&stv, NULL); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 196 | for (i = 0; i < nr; i++) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 197 | io_prep_pwrite(iocbs[0], fd, srcbuf, bufsize, pos); |
| 198 | ts.tv_sec = 30; |
| 199 | ts.tv_nsec = 0; |
subrata_modak | 967caaf | 2008-07-12 21:31:07 +0000 | [diff] [blame] | 200 | do { |
| 201 | TEST(io_submit(io_ctx, 1, iocbs)); |
| 202 | } while (TEST_RETURN == -EAGAIN); |
| 203 | if (TEST_RETURN < 0) { |
Jan Stancek | 17ea0a9 | 2013-04-17 11:05:33 +0200 | [diff] [blame] | 204 | tst_resm(TFAIL, "Test 3: io_submit failed - retval=%ld" |
| 205 | ", errno=%d", TEST_RETURN, TEST_ERRNO); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 206 | failflag = 1; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 207 | continue; |
| 208 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 209 | while (io_getevents(io_ctx, 1, 1, &event, &ts) != 1) ; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 210 | gettimeofday(&etv, NULL); |
| 211 | } |
| 212 | if (!failflag) { |
| 213 | sec = etv.tv_sec - stv.tv_sec; |
| 214 | usec = etv.tv_usec - stv.tv_usec; |
| 215 | if (usec < 0) { |
| 216 | usec += 1000000; |
| 217 | sec--; |
| 218 | } |
| 219 | tst_resm(TPASS, "Test 3: %d prep,writes in %3d.%06d sec", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 220 | nr, sec, usec); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /* TEST 4 */ |
| 224 | pos = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 225 | failflag = 0; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 226 | gettimeofday(&stv, NULL); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 227 | for (i = 0; i < nr; i++) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 228 | io_prep_pread(iocbs[0], fd, dstbuf, bufsize, pos); |
| 229 | ts.tv_sec = 30; |
| 230 | ts.tv_nsec = 0; |
subrata_modak | 967caaf | 2008-07-12 21:31:07 +0000 | [diff] [blame] | 231 | do { |
| 232 | TEST(io_submit(io_ctx, 1, iocbs)); |
| 233 | } while (TEST_RETURN == -EAGAIN); |
| 234 | if (TEST_RETURN < 0) { |
Jan Stancek | 17ea0a9 | 2013-04-17 11:05:33 +0200 | [diff] [blame] | 235 | tst_resm(TFAIL, "Test 4: io_submit failed - retval=%ld" |
| 236 | ", errno=%d", TEST_RETURN, TEST_ERRNO); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 237 | failflag = 1; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 238 | continue; |
| 239 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 240 | while (io_getevents(io_ctx, 1, 1, &event, &ts) != 1) ; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 241 | gettimeofday(&etv, NULL); |
| 242 | } |
| 243 | if (!failflag) { |
| 244 | sec = etv.tv_sec - stv.tv_sec; |
| 245 | usec = etv.tv_usec - stv.tv_usec; |
| 246 | if (usec < 0) { |
| 247 | usec += 1000000; |
| 248 | sec--; |
| 249 | } |
| 250 | tst_resm(TPASS, "Test 4: %d prep,reads in %3d.%06d sec", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 251 | nr, sec, usec); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* TEST 5 */ |
| 255 | pos = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 256 | failflag = 0; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 257 | gettimeofday(&stv, NULL); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 258 | for (i = 0; i < nr; i++) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 259 | io_prep_pwrite(iocbs[0], fd, srcbuf, bufsize, pos); |
| 260 | ts.tv_sec = 30; |
| 261 | ts.tv_nsec = 0; |
subrata_modak | 967caaf | 2008-07-12 21:31:07 +0000 | [diff] [blame] | 262 | do { |
| 263 | TEST(io_submit(io_ctx, 1, iocbs)); |
| 264 | } while (TEST_RETURN == -EAGAIN); |
| 265 | if (TEST_RETURN < 0) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 266 | tst_resm(TFAIL, "Test 5: write io_submit failed - " |
Jan Stancek | 17ea0a9 | 2013-04-17 11:05:33 +0200 | [diff] [blame] | 267 | "retval=%ld, errno=%d", TEST_RETURN, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 268 | TEST_ERRNO); |
| 269 | failflag = 1; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 270 | continue; |
| 271 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 272 | while (io_getevents(io_ctx, 1, 1, &event, &ts) != 1) ; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 273 | io_prep_pread(iocbs[0], fd, dstbuf, bufsize, pos); |
| 274 | ts.tv_sec = 30; |
| 275 | ts.tv_nsec = 0; |
subrata_modak | 967caaf | 2008-07-12 21:31:07 +0000 | [diff] [blame] | 276 | do { |
| 277 | TEST(io_submit(io_ctx, 1, iocbs)); |
| 278 | } while (TEST_RETURN == -EAGAIN); |
| 279 | if (TEST_RETURN < 0) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 280 | tst_resm(TFAIL, "Test 5: read io_submit failed - " |
Jan Stancek | 17ea0a9 | 2013-04-17 11:05:33 +0200 | [diff] [blame] | 281 | "retval=%ld, errno=%d", TEST_RETURN, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 282 | TEST_ERRNO); |
| 283 | failflag = 1; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 284 | continue; |
| 285 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 286 | while (io_getevents(io_ctx, 1, 1, &event, &ts) != 1) ; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 287 | gettimeofday(&etv, NULL); |
| 288 | } |
| 289 | if (!failflag) { |
| 290 | sec = etv.tv_sec - stv.tv_sec; |
| 291 | usec = etv.tv_usec - stv.tv_usec; |
| 292 | if (usec < 0) { |
| 293 | usec += 1000000; |
| 294 | sec--; |
| 295 | } |
| 296 | tst_resm(TPASS, "Test 5: %d reads and writes in %3d.%06d sec", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 297 | nr, sec, usec); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* TEST 6 */ |
| 301 | pos = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 302 | failflag = 0; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 303 | gettimeofday(&stv, NULL); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 304 | for (i = 0; i < nr; i++) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 305 | io_prep_pwrite(iocbs[0], fd, srcbuf, bufsize, pos); |
| 306 | ts.tv_sec = 30; |
| 307 | ts.tv_nsec = 0; |
subrata_modak | 967caaf | 2008-07-12 21:31:07 +0000 | [diff] [blame] | 308 | do { |
| 309 | TEST(io_submit(io_ctx, 1, iocbs)); |
| 310 | } while (TEST_RETURN == -EAGAIN); |
| 311 | if (TEST_RETURN < 0) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 312 | tst_resm(TFAIL, "Test 6: write io_submit failed - " |
Jan Stancek | 17ea0a9 | 2013-04-17 11:05:33 +0200 | [diff] [blame] | 313 | "retval=%ld, errno=%d", TEST_RETURN, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 314 | TEST_ERRNO); |
| 315 | failflag = 1; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 316 | continue; |
| 317 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 318 | while (io_getevents(io_ctx, 1, 1, &event, &ts) != 1) ; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 319 | io_prep_pread(iocbs[0], fd, dstbuf, bufsize, pos); |
| 320 | ts.tv_sec = 30; |
| 321 | ts.tv_nsec = 0; |
subrata_modak | 967caaf | 2008-07-12 21:31:07 +0000 | [diff] [blame] | 322 | do { |
| 323 | TEST(io_submit(io_ctx, 1, iocbs)); |
| 324 | } while (TEST_RETURN == -EAGAIN); |
| 325 | if (TEST_RETURN < 0) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 326 | tst_resm(TFAIL, "Test 6: read io_submit failed - " |
Jan Stancek | 17ea0a9 | 2013-04-17 11:05:33 +0200 | [diff] [blame] | 327 | "retval=%ld, errno=%d", TEST_RETURN, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 328 | TEST_ERRNO); |
| 329 | failflag = 1; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 330 | continue; |
| 331 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 332 | while (io_getevents(io_ctx, 1, 1, &event, &ts) != 1) ; |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 333 | for (j = 0; j < bufsize; j++) { |
Jan Stancek | c0e21fd | 2013-04-17 11:09:48 +0200 | [diff] [blame] | 334 | if (srcbuf[j] != dstbuf[j]) { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 335 | tst_resm(TFAIL, "Test 6: compare failed - " |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 336 | "read: %c, " "actual: %c", |
| 337 | dstbuf[j], srcbuf[j]); |
Jan Stancek | c0e21fd | 2013-04-17 11:09:48 +0200 | [diff] [blame] | 338 | break; |
| 339 | } |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 340 | } |
| 341 | gettimeofday(&etv, NULL); |
| 342 | } |
| 343 | if (!failflag) { |
| 344 | sec = etv.tv_sec - stv.tv_sec; |
| 345 | usec = etv.tv_usec - stv.tv_usec; |
| 346 | if (usec < 0) { |
| 347 | usec += 1000000; |
| 348 | sec--; |
| 349 | } |
| 350 | tst_resm(TPASS, "Test 6: %d read,write,verify in %d.%06d sec", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 351 | i, sec, usec); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 352 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 353 | |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 354 | cleanup(); |
| 355 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 356 | tst_exit(); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 357 | } |
| 358 | |
subrata_modak | d1e1973 | 2009-08-30 17:04:40 +0000 | [diff] [blame] | 359 | static void help(void) |
| 360 | { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 361 | printf(" -b n Buffersize\n"); |
| 362 | printf(" -n n Number of requests\n"); |
| 363 | printf(" -F s Filename to run the tests against\n"); |
| 364 | } |
| 365 | |
subrata_modak | d1e1973 | 2009-08-30 17:04:40 +0000 | [diff] [blame] | 366 | static void setup(void) |
| 367 | { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 368 | int ret; |
| 369 | |
| 370 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 371 | |
| 372 | /* Pause if option was specified */ |
| 373 | TEST_PAUSE; |
| 374 | |
| 375 | tst_tmpdir(); |
| 376 | |
| 377 | if ((fd = open(fname, O_RDWR | O_CREAT, 0600)) < 0) |
| 378 | tst_brkm(TFAIL, cleanup, "failed to open %s " |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 379 | "file, errno: %d", fname, errno); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 380 | stat(fname, &s); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 381 | if ((iocbs = malloc(sizeof(int) * nr)) == NULL) |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 382 | tst_brkm(TFAIL, cleanup, "malloc for iocbs failed - " |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 383 | "errno: %d", errno); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 384 | if ((iocbs[0] = malloc(sizeof(struct iocb))) == NULL) |
| 385 | tst_brkm(TFAIL, cleanup, "malloc for iocbs elements failed - " |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 386 | "errno: %d", errno); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 387 | if (S_ISCHR(s.st_mode)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 388 | if ((ret = |
| 389 | posix_memalign((void **)&srcbuf, bufsize, bufsize)) != 0) |
| 390 | tst_brkm(TFAIL, cleanup, |
| 391 | "posix_memalign for srcbuf " |
| 392 | "failed - errno: %d", errno); |
| 393 | if ((ret = |
| 394 | posix_memalign((void **)&dstbuf, bufsize, bufsize)) != 0) |
| 395 | tst_brkm(TFAIL, cleanup, |
| 396 | "posix_memalign for dstbuf " |
| 397 | "failed - errno: %d", errno); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 398 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 399 | if ((srcbuf = malloc(sizeof(char) * bufsize)) == NULL) |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 400 | tst_brkm(TFAIL, cleanup, "malloc for srcbuf " |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 401 | "failed - errno: %d", errno); |
| 402 | if ((dstbuf = malloc(sizeof(char) * bufsize)) == NULL) |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 403 | tst_brkm(TFAIL, cleanup, "malloc for dstbuf " |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 404 | "failed - errno: %d", errno); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 405 | } |
| 406 | memset((void *)srcbuf, 65, bufsize); |
| 407 | if ((ret = io_queue_init(1, &io_ctx)) != 0) |
| 408 | tst_brkm(TFAIL, cleanup, "io_queue_init failed: %s", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 409 | strerror(ret)); |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 412 | static void cleanup(void) |
| 413 | { |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 414 | free(dstbuf); |
| 415 | free(srcbuf); |
| 416 | free(iocbs[0]); |
| 417 | free(iocbs); |
| 418 | close(fd); |
| 419 | io_queue_release(io_ctx); |
| 420 | tst_rmdir(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 421 | |
plars | 99a68d0 | 2003-05-21 17:38:00 +0000 | [diff] [blame] | 422 | } |
subrata_modak | dd87629 | 2009-01-28 06:43:09 +0000 | [diff] [blame] | 423 | |
| 424 | #else |
| 425 | |
| 426 | int main(void) |
| 427 | { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 428 | tst_brkm(TCONF, NULL, "libaio missing"); |
subrata_modak | dd87629 | 2009-01-28 06:43:09 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 431 | #endif |