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