Deleted Added
full compact
aio_test.c (253526) aio_test.c (280893)
1/*-
2 * Copyright (c) 2004 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2004 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/tools/regression/aio/aiotest/aiotest.c 253526 2013-07-21 19:21:18Z kib $
26 * $FreeBSD: head/tools/regression/aio/aiotest/aiotest.c 280893 2015-03-31 06:43:55Z ngie $
27 */
28
29/*
30 * Regression test to do some very basic AIO exercising on several types of
31 * file descriptors. Currently, the tests consist of initializing a fixed
32 * size buffer with pseudo-random data, writing it to one fd using AIO, then
33 * reading it from a second descriptor using AIO. For some targets, the same
34 * fd is used for write and read (i.e., file, md device), but for others the
35 * operation is performed on a peer (pty, socket, fifo, etc). A timeout is
36 * initiated to detect undo blocking. This test does not attempt to exercise
37 * error cases or more subtle asynchronous behavior, just make sure that the
38 * basic operations work on some basic object types.
39 */
40
27 */
28
29/*
30 * Regression test to do some very basic AIO exercising on several types of
31 * file descriptors. Currently, the tests consist of initializing a fixed
32 * size buffer with pseudo-random data, writing it to one fd using AIO, then
33 * reading it from a second descriptor using AIO. For some targets, the same
34 * fd is used for write and read (i.e., file, md device), but for others the
35 * operation is performed on a peer (pty, socket, fifo, etc). A timeout is
36 * initiated to detect undo blocking. This test does not attempt to exercise
37 * error cases or more subtle asynchronous behavior, just make sure that the
38 * basic operations work on some basic object types.
39 */
40
41#include <sys/types.h>
41#include <sys/param.h>
42#include <sys/module.h>
42#include <sys/socket.h>
43#include <sys/stat.h>
44#include <sys/mdioctl.h>
45
46#include <aio.h>
47#include <err.h>
48#include <errno.h>
49#include <fcntl.h>

--- 24 unchanged lines hidden (view full) ---

74 char ac_buffer[GLOBAL_MAX];
75 int ac_buflen;
76 int ac_seconds;
77 void (*ac_cleanup)(void *arg);
78 void *ac_cleanup_arg;
79};
80
81static int aio_timedout;
43#include <sys/socket.h>
44#include <sys/stat.h>
45#include <sys/mdioctl.h>
46
47#include <aio.h>
48#include <err.h>
49#include <errno.h>
50#include <fcntl.h>

--- 24 unchanged lines hidden (view full) ---

75 char ac_buffer[GLOBAL_MAX];
76 int ac_buflen;
77 int ac_seconds;
78 void (*ac_cleanup)(void *arg);
79 void *ac_cleanup_arg;
80};
81
82static int aio_timedout;
82static int aio_notpresent;
83
83
84/*
85 * Attempt to provide a cleaner failure mode in the event AIO support is not
86 * present by catching and reporting SIGSYS.
87 */
88static void
84static void
89aio_sigsys(int sig)
85aio_available(void)
90{
91
86{
87
92 aio_notpresent = 1;
88 if (modfind("aio") == -1)
89 errx(0,
90 "aio support not available in the kernel; skipping "
91 "testcases");
93}
94
92}
93
95static void
96aio_sigsys_setup(void)
97{
98
99 if (signal(SIGSYS, aio_sigsys) == SIG_ERR)
100 errx(-1, "FAIL: signal(SIGSYS): %s", strerror(errno));
101}
102
103/*
104 * Each test run specifies a timeout in seconds. Use the somewhat obsoleted
105 * signal(3) and alarm(3) APIs to set this up.
106 */
107static void
94/*
95 * Each test run specifies a timeout in seconds. Use the somewhat obsoleted
96 * signal(3) and alarm(3) APIs to set this up.
97 */
98static void
108aio_timeout_signal(int sig)
99aio_timeout_signal(int sig __unused)
109{
110
111 aio_timedout = 1;
112}
113
114static void
115aio_timeout_start(const char *string1, const char *string2, int seconds)
116{
117
118 aio_timedout = 0;
119 if (signal(SIGALRM, aio_timeout_signal) == SIG_ERR)
100{
101
102 aio_timedout = 1;
103}
104
105static void
106aio_timeout_start(const char *string1, const char *string2, int seconds)
107{
108
109 aio_timedout = 0;
110 if (signal(SIGALRM, aio_timeout_signal) == SIG_ERR)
120 errx(-1, "FAIL: %s: %s: aio_timeout_set: signal(SIGALRM): %s",
111 errx(1, "FAIL: %s: %s: aio_timeout_set: signal(SIGALRM): %s",
121 string1, string2, strerror(errno));
122 alarm(seconds);
123}
124
125static void
126aio_timeout_stop(const char *string1, const char *string2)
127{
128
129 if (signal(SIGALRM, NULL) == SIG_ERR)
112 string1, string2, strerror(errno));
113 alarm(seconds);
114}
115
116static void
117aio_timeout_stop(const char *string1, const char *string2)
118{
119
120 if (signal(SIGALRM, NULL) == SIG_ERR)
130 errx(-1, "FAIL: %s: %s: aio_timeout_stop: signal(NULL): %s",
121 errx(1, "FAIL: %s: %s: aio_timeout_stop: signal(NULL): %s",
131 string1, string2, strerror(errno));
132 alarm(0);
133}
134
135/*
136 * Fill a buffer given a seed that can be fed into srandom() to initialize
137 * the PRNG in a repeatable manner.
138 */

--- 35 unchanged lines hidden (view full) ---

174 */
175static void
176aio_context_init(struct aio_context *ac, const char *test, int read_fd,
177 int write_fd, int buflen, int seconds, void (*cleanup)(void *),
178 void *cleanup_arg)
179{
180
181 if (buflen > BUFFER_MAX)
122 string1, string2, strerror(errno));
123 alarm(0);
124}
125
126/*
127 * Fill a buffer given a seed that can be fed into srandom() to initialize
128 * the PRNG in a repeatable manner.
129 */

--- 35 unchanged lines hidden (view full) ---

165 */
166static void
167aio_context_init(struct aio_context *ac, const char *test, int read_fd,
168 int write_fd, int buflen, int seconds, void (*cleanup)(void *),
169 void *cleanup_arg)
170{
171
172 if (buflen > BUFFER_MAX)
182 errx(-1, "FAIL: %s: aio_context_init: buffer too large",
173 errx(1, "FAIL: %s: aio_context_init: buffer too large",
183 test);
184 bzero(ac, sizeof(*ac));
185 ac->ac_test = test;
186 ac->ac_read_fd = read_fd;
187 ac->ac_write_fd = write_fd;
188 ac->ac_buflen = buflen;
189 srandomdev();
190 ac->ac_seed = random();
191 aio_fill_buffer(ac->ac_buffer, buflen, ac->ac_seed);
192 if (aio_test_buffer(ac->ac_buffer, buflen, ac->ac_seed) == 0)
174 test);
175 bzero(ac, sizeof(*ac));
176 ac->ac_test = test;
177 ac->ac_read_fd = read_fd;
178 ac->ac_write_fd = write_fd;
179 ac->ac_buflen = buflen;
180 srandomdev();
181 ac->ac_seed = random();
182 aio_fill_buffer(ac->ac_buffer, buflen, ac->ac_seed);
183 if (aio_test_buffer(ac->ac_buffer, buflen, ac->ac_seed) == 0)
193 errx(-1, "%s: aio_context_init: aio_test_buffer: internal "
184 errx(1, "%s: aio_context_init: aio_test_buffer: internal "
194 "error", test);
195 ac->ac_seconds = seconds;
196 ac->ac_cleanup = cleanup;
197 ac->ac_cleanup_arg = cleanup_arg;
198}
199
200/*
201 * Each tester can register a callback to clean up in the event the test

--- 16 unchanged lines hidden (view full) ---

218 * Perform a simple write test of our initialized data buffer to the provided
219 * file descriptor.
220 */
221static void
222aio_write_test(struct aio_context *ac)
223{
224 struct aiocb aio, *aiop;
225 ssize_t len;
185 "error", test);
186 ac->ac_seconds = seconds;
187 ac->ac_cleanup = cleanup;
188 ac->ac_cleanup_arg = cleanup_arg;
189}
190
191/*
192 * Each tester can register a callback to clean up in the event the test

--- 16 unchanged lines hidden (view full) ---

209 * Perform a simple write test of our initialized data buffer to the provided
210 * file descriptor.
211 */
212static void
213aio_write_test(struct aio_context *ac)
214{
215 struct aiocb aio, *aiop;
216 ssize_t len;
226 int error;
227
217
218 aio_available();
219
228 bzero(&aio, sizeof(aio));
229 aio.aio_buf = ac->ac_buffer;
230 aio.aio_nbytes = ac->ac_buflen;
231 aio.aio_fildes = ac->ac_write_fd;
232 aio.aio_offset = 0;
233
234 aio_timeout_start(ac->ac_test, "aio_write_test", ac->ac_seconds);
235
236 if (aio_write(&aio) < 0) {
237 if (errno == EINTR) {
220 bzero(&aio, sizeof(aio));
221 aio.aio_buf = ac->ac_buffer;
222 aio.aio_nbytes = ac->ac_buflen;
223 aio.aio_fildes = ac->ac_write_fd;
224 aio.aio_offset = 0;
225
226 aio_timeout_start(ac->ac_test, "aio_write_test", ac->ac_seconds);
227
228 if (aio_write(&aio) < 0) {
229 if (errno == EINTR) {
238 if (aio_notpresent)
239 errno = EOPNOTSUPP;
240 if (aio_timedout) {
241 aio_cleanup(ac);
230 if (aio_timedout) {
231 aio_cleanup(ac);
242 errx(-1, "FAIL: %s: aio_write_test: "
232 errx(1, "FAIL: %s: aio_write_test: "
243 "aio_write: timed out", ac->ac_test);
244 }
245 }
246 aio_cleanup(ac);
233 "aio_write: timed out", ac->ac_test);
234 }
235 }
236 aio_cleanup(ac);
247 errx(-1, "FAIL: %s: aio_write_test: aio_write: %s",
237 errx(1, "FAIL: %s: aio_write_test: aio_write: %s",
248 ac->ac_test, strerror(errno));
249 }
250
251 len = aio_waitcomplete(&aiop, NULL);
252 if (len < 0) {
253 if (errno == EINTR) {
238 ac->ac_test, strerror(errno));
239 }
240
241 len = aio_waitcomplete(&aiop, NULL);
242 if (len < 0) {
243 if (errno == EINTR) {
254 if (aio_notpresent)
255 errno = EOPNOTSUPP;
256 if (aio_timedout) {
257 aio_cleanup(ac);
244 if (aio_timedout) {
245 aio_cleanup(ac);
258 errx(-1, "FAIL: %s: aio_write_test: "
246 errx(1, "FAIL: %s: aio_write_test: "
259 "aio_waitcomplete: timed out",
260 ac->ac_test);
261 }
262 }
263 aio_cleanup(ac);
247 "aio_waitcomplete: timed out",
248 ac->ac_test);
249 }
250 }
251 aio_cleanup(ac);
264 errx(-1, "FAIL: %s: aio_write_test: aio_waitcomplete: %s",
252 errx(1, "FAIL: %s: aio_write_test: aio_waitcomplete: %s",
265 ac->ac_test, strerror(errno));
266 }
267
268 aio_timeout_stop(ac->ac_test, "aio_write_test");
269
270 if (len != ac->ac_buflen) {
271 aio_cleanup(ac);
253 ac->ac_test, strerror(errno));
254 }
255
256 aio_timeout_stop(ac->ac_test, "aio_write_test");
257
258 if (len != ac->ac_buflen) {
259 aio_cleanup(ac);
272 errx(-1, "FAIL: %s: aio_write_test: aio_waitcomplete: short "
260 errx(1, "FAIL: %s: aio_write_test: aio_waitcomplete: short "
273 "write (%jd)", ac->ac_test, (intmax_t)len);
274 }
275}
276
277/*
278 * Perform a simple read test of our initialized data buffer from the
279 * provided file descriptor.
280 */
281static void
282aio_read_test(struct aio_context *ac)
283{
284 struct aiocb aio, *aiop;
285 ssize_t len;
286
261 "write (%jd)", ac->ac_test, (intmax_t)len);
262 }
263}
264
265/*
266 * Perform a simple read test of our initialized data buffer from the
267 * provided file descriptor.
268 */
269static void
270aio_read_test(struct aio_context *ac)
271{
272 struct aiocb aio, *aiop;
273 ssize_t len;
274
275 aio_available();
276
287 bzero(ac->ac_buffer, ac->ac_buflen);
288 bzero(&aio, sizeof(aio));
289 aio.aio_buf = ac->ac_buffer;
290 aio.aio_nbytes = ac->ac_buflen;
291 aio.aio_fildes = ac->ac_read_fd;
292 aio.aio_offset = 0;
293
294 aio_timeout_start(ac->ac_test, "aio_read_test", ac->ac_seconds);
295
296 if (aio_read(&aio) < 0) {
297 if (errno == EINTR) {
277 bzero(ac->ac_buffer, ac->ac_buflen);
278 bzero(&aio, sizeof(aio));
279 aio.aio_buf = ac->ac_buffer;
280 aio.aio_nbytes = ac->ac_buflen;
281 aio.aio_fildes = ac->ac_read_fd;
282 aio.aio_offset = 0;
283
284 aio_timeout_start(ac->ac_test, "aio_read_test", ac->ac_seconds);
285
286 if (aio_read(&aio) < 0) {
287 if (errno == EINTR) {
298 if (aio_notpresent)
299 errno = EOPNOTSUPP;
300 if (aio_timedout) {
301 aio_cleanup(ac);
288 if (aio_timedout) {
289 aio_cleanup(ac);
302 errx(-1, "FAIL: %s: aio_read_test: "
290 errx(1, "FAIL: %s: aio_read_test: "
303 "aio_read: timed out", ac->ac_test);
304 }
305 }
306 aio_cleanup(ac);
291 "aio_read: timed out", ac->ac_test);
292 }
293 }
294 aio_cleanup(ac);
307 errx(-1, "FAIL: %s: aio_read_test: aio_read %s", ac->ac_test,
295 errx(1, "FAIL: %s: aio_read_test: aio_read %s", ac->ac_test,
308 strerror(errno));
309 }
310
311 len = aio_waitcomplete(&aiop, NULL);
312 if (len < 0) {
313 if (errno == EINTR) {
296 strerror(errno));
297 }
298
299 len = aio_waitcomplete(&aiop, NULL);
300 if (len < 0) {
301 if (errno == EINTR) {
314 if (aio_notpresent)
315 errno = EOPNOTSUPP;
316 if (aio_timedout) {
317 aio_cleanup(ac);
302 if (aio_timedout) {
303 aio_cleanup(ac);
318 errx(-1, "FAIL: %s: aio_read_test: "
304 errx(1, "FAIL: %s: aio_read_test: "
319 "aio_waitcomplete: timed out",
320 ac->ac_test);
321 }
322 }
323 aio_cleanup(ac);
305 "aio_waitcomplete: timed out",
306 ac->ac_test);
307 }
308 }
309 aio_cleanup(ac);
324 errx(-1, "FAIL: %s: aio_read_test: aio_waitcomplete: %s",
310 errx(1, "FAIL: %s: aio_read_test: aio_waitcomplete: %s",
325 ac->ac_test, strerror(errno));
326 }
327
328 aio_timeout_stop(ac->ac_test, "aio_read_test");
329
330 if (len != ac->ac_buflen) {
331 aio_cleanup(ac);
311 ac->ac_test, strerror(errno));
312 }
313
314 aio_timeout_stop(ac->ac_test, "aio_read_test");
315
316 if (len != ac->ac_buflen) {
317 aio_cleanup(ac);
332 errx(-1, "FAIL: %s: aio_read_test: aio_waitcomplete: short "
318 errx(1, "FAIL: %s: aio_read_test: aio_waitcomplete: short "
333 "read (%jd)", ac->ac_test, (intmax_t)len);
334 }
335
336 if (aio_test_buffer(ac->ac_buffer, ac->ac_buflen, ac->ac_seed) == 0) {
337 aio_cleanup(ac);
319 "read (%jd)", ac->ac_test, (intmax_t)len);
320 }
321
322 if (aio_test_buffer(ac->ac_buffer, ac->ac_buflen, ac->ac_seed) == 0) {
323 aio_cleanup(ac);
338 errx(-1, "FAIL: %s: aio_read_test: buffer mismatch",
324 errx(1, "FAIL: %s: aio_read_test: buffer mismatch",
339 ac->ac_test);
340 }
341}
342
343/*
344 * Series of type-specific tests for AIO. For now, we just make sure we can
345 * issue a write and then a read to each type. We assume that once a write
346 * is issued, a read can follow.

--- 23 unchanged lines hidden (view full) ---

370static void
371aio_file_test(void)
372{
373 char pathname[PATH_MAX];
374 struct aio_file_arg arg;
375 struct aio_context ac;
376 int fd;
377
325 ac->ac_test);
326 }
327}
328
329/*
330 * Series of type-specific tests for AIO. For now, we just make sure we can
331 * issue a write and then a read to each type. We assume that once a write
332 * is issued, a read can follow.

--- 23 unchanged lines hidden (view full) ---

356static void
357aio_file_test(void)
358{
359 char pathname[PATH_MAX];
360 struct aio_file_arg arg;
361 struct aio_context ac;
362 int fd;
363
364 aio_available();
365
378 strcpy(pathname, PATH_TEMPLATE);
379 fd = mkstemp(pathname);
380 if (fd == -1)
366 strcpy(pathname, PATH_TEMPLATE);
367 fd = mkstemp(pathname);
368 if (fd == -1)
381 errx(-1, "FAIL: aio_file_test: mkstemp: %s",
369 errx(1, "FAIL: aio_file_test: mkstemp: %s",
382 strerror(errno));
383
384 arg.afa_fd = fd;
385 arg.afa_pathname = pathname;
386
387 aio_context_init(&ac, "aio_file_test", fd, fd, FILE_LEN,
388 FILE_TIMEOUT, aio_file_cleanup, &arg);
389 aio_write_test(&ac);

--- 28 unchanged lines hidden (view full) ---

418static void
419aio_fifo_test(void)
420{
421 int error, read_fd = -1, write_fd = -1;
422 struct aio_fifo_arg arg;
423 char pathname[PATH_MAX];
424 struct aio_context ac;
425
370 strerror(errno));
371
372 arg.afa_fd = fd;
373 arg.afa_pathname = pathname;
374
375 aio_context_init(&ac, "aio_file_test", fd, fd, FILE_LEN,
376 FILE_TIMEOUT, aio_file_cleanup, &arg);
377 aio_write_test(&ac);

--- 28 unchanged lines hidden (view full) ---

406static void
407aio_fifo_test(void)
408{
409 int error, read_fd = -1, write_fd = -1;
410 struct aio_fifo_arg arg;
411 char pathname[PATH_MAX];
412 struct aio_context ac;
413
414 aio_available();
415
426 /*
416 /*
427 * In theory, mktemp() can return a name that is then collided with.
417 * In theory, mkstemp() can return a name that is then collided with.
428 * Because this is a regression test, we treat that as a test failure
429 * rather than retrying.
430 */
431 strcpy(pathname, PATH_TEMPLATE);
418 * Because this is a regression test, we treat that as a test failure
419 * rather than retrying.
420 */
421 strcpy(pathname, PATH_TEMPLATE);
432 mktemp(pathname);
422 if (mkstemp(pathname) == -1)
423 err(1, "FAIL: aio_fifo_test: mkstemp failed");
424 if (unlink(pathname) == -1)
425 err(1, "FAIL: aio_fifo_test: unlink failed");
433 if (mkfifo(pathname, 0600) == -1)
426 if (mkfifo(pathname, 0600) == -1)
434 errx(-1, "FAIL: aio_fifo_test: mkfifo: %s", strerror(errno));
427 errx(1, "FAIL: aio_fifo_test: mkfifo: %s", strerror(errno));
435 arg.afa_pathname = pathname;
436 arg.afa_read_fd = -1;
437 arg.afa_write_fd = -1;
438
439 read_fd = open(pathname, O_RDONLY | O_NONBLOCK);
440 if (read_fd == -1) {
441 error = errno;
442 aio_fifo_cleanup(&arg);
443 errno = error;
428 arg.afa_pathname = pathname;
429 arg.afa_read_fd = -1;
430 arg.afa_write_fd = -1;
431
432 read_fd = open(pathname, O_RDONLY | O_NONBLOCK);
433 if (read_fd == -1) {
434 error = errno;
435 aio_fifo_cleanup(&arg);
436 errno = error;
444 errx(-1, "FAIL: aio_fifo_test: read_fd open: %s",
437 errx(1, "FAIL: aio_fifo_test: read_fd open: %s",
445 strerror(errno));
446 }
447 arg.afa_read_fd = read_fd;
448
449 write_fd = open(pathname, O_WRONLY);
450 if (write_fd == -1) {
451 error = errno;
452 aio_fifo_cleanup(&arg);
453 errno = error;
438 strerror(errno));
439 }
440 arg.afa_read_fd = read_fd;
441
442 write_fd = open(pathname, O_WRONLY);
443 if (write_fd == -1) {
444 error = errno;
445 aio_fifo_cleanup(&arg);
446 errno = error;
454 errx(-1, "FAIL: aio_fifo_test: write_fd open: %s",
447 errx(1, "FAIL: aio_fifo_test: write_fd open: %s",
455 strerror(errno));
456 }
457 arg.afa_write_fd = write_fd;
458
459 aio_context_init(&ac, "aio_fifo_test", read_fd, write_fd, FIFO_LEN,
460 FIFO_TIMEOUT, aio_fifo_cleanup, &arg);
461 aio_write_test(&ac);
462 aio_read_test(&ac);

--- 21 unchanged lines hidden (view full) ---

484#define UNIX_SOCKETPAIR_TIMEOUT 30
485static void
486aio_unix_socketpair_test(void)
487{
488 struct aio_unix_socketpair_arg arg;
489 struct aio_context ac;
490 int sockets[2];
491
448 strerror(errno));
449 }
450 arg.afa_write_fd = write_fd;
451
452 aio_context_init(&ac, "aio_fifo_test", read_fd, write_fd, FIFO_LEN,
453 FIFO_TIMEOUT, aio_fifo_cleanup, &arg);
454 aio_write_test(&ac);
455 aio_read_test(&ac);

--- 21 unchanged lines hidden (view full) ---

477#define UNIX_SOCKETPAIR_TIMEOUT 30
478static void
479aio_unix_socketpair_test(void)
480{
481 struct aio_unix_socketpair_arg arg;
482 struct aio_context ac;
483 int sockets[2];
484
485 aio_available();
486
492 if (socketpair(PF_UNIX, SOCK_STREAM, 0, sockets) < 0)
487 if (socketpair(PF_UNIX, SOCK_STREAM, 0, sockets) < 0)
493 errx(-1, "FAIL: aio_socketpair_test: socketpair: %s",
488 errx(1, "FAIL: aio_socketpair_test: socketpair: %s",
494 strerror(errno));
495
496 arg.asa_sockets[0] = sockets[0];
497 arg.asa_sockets[1] = sockets[1];
498 aio_context_init(&ac, "aio_unix_socketpair_test", sockets[0],
499 sockets[1], UNIX_SOCKETPAIR_LEN, UNIX_SOCKETPAIR_TIMEOUT,
500 aio_unix_socketpair_cleanup, &arg);
501 aio_write_test(&ac);

--- 25 unchanged lines hidden (view full) ---

527aio_pty_test(void)
528{
529 struct aio_pty_arg arg;
530 struct aio_context ac;
531 int read_fd, write_fd;
532 struct termios ts;
533 int error;
534
489 strerror(errno));
490
491 arg.asa_sockets[0] = sockets[0];
492 arg.asa_sockets[1] = sockets[1];
493 aio_context_init(&ac, "aio_unix_socketpair_test", sockets[0],
494 sockets[1], UNIX_SOCKETPAIR_LEN, UNIX_SOCKETPAIR_TIMEOUT,
495 aio_unix_socketpair_cleanup, &arg);
496 aio_write_test(&ac);

--- 25 unchanged lines hidden (view full) ---

522aio_pty_test(void)
523{
524 struct aio_pty_arg arg;
525 struct aio_context ac;
526 int read_fd, write_fd;
527 struct termios ts;
528 int error;
529
530 aio_available();
531
535 if (openpty(&read_fd, &write_fd, NULL, NULL, NULL) < 0)
532 if (openpty(&read_fd, &write_fd, NULL, NULL, NULL) < 0)
536 errx(-1, "FAIL: aio_pty_test: openpty: %s", strerror(errno));
533 errx(1, "FAIL: aio_pty_test: openpty: %s", strerror(errno));
537
538 arg.apa_read_fd = read_fd;
539 arg.apa_write_fd = write_fd;
540
541 if (tcgetattr(write_fd, &ts) < 0) {
542 error = errno;
543 aio_pty_cleanup(&arg);
544 errno = error;
534
535 arg.apa_read_fd = read_fd;
536 arg.apa_write_fd = write_fd;
537
538 if (tcgetattr(write_fd, &ts) < 0) {
539 error = errno;
540 aio_pty_cleanup(&arg);
541 errno = error;
545 errx(-1, "FAIL: aio_pty_test: tcgetattr: %s",
542 errx(1, "FAIL: aio_pty_test: tcgetattr: %s",
546 strerror(errno));
547 }
548 cfmakeraw(&ts);
549 if (tcsetattr(write_fd, TCSANOW, &ts) < 0) {
550 error = errno;
551 aio_pty_cleanup(&arg);
552 errno = error;
543 strerror(errno));
544 }
545 cfmakeraw(&ts);
546 if (tcsetattr(write_fd, TCSANOW, &ts) < 0) {
547 error = errno;
548 aio_pty_cleanup(&arg);
549 errno = error;
553 errx(-1, "FAIL: aio_pty_test: tcsetattr: %s",
550 errx(1, "FAIL: aio_pty_test: tcsetattr: %s",
554 strerror(errno));
555 }
556
557 aio_context_init(&ac, "aio_pty_test", read_fd, write_fd, PTY_LEN,
558 PTY_TIMEOUT, aio_pty_cleanup, &arg);
559 aio_write_test(&ac);
560 aio_read_test(&ac);
561

--- 14 unchanged lines hidden (view full) ---

576#define PIPE_LEN 256
577#define PIPE_TIMEOUT 30
578static void
579aio_pipe_test(void)
580{
581 struct aio_context ac;
582 int pipes[2];
583
551 strerror(errno));
552 }
553
554 aio_context_init(&ac, "aio_pty_test", read_fd, write_fd, PTY_LEN,
555 PTY_TIMEOUT, aio_pty_cleanup, &arg);
556 aio_write_test(&ac);
557 aio_read_test(&ac);
558

--- 14 unchanged lines hidden (view full) ---

573#define PIPE_LEN 256
574#define PIPE_TIMEOUT 30
575static void
576aio_pipe_test(void)
577{
578 struct aio_context ac;
579 int pipes[2];
580
581 aio_available();
582
584 if (pipe(pipes) < 0)
583 if (pipe(pipes) < 0)
585 errx(-1, "FAIL: aio_pipe_test: pipe: %s", strerror(errno));
584 errx(1, "FAIL: aio_pipe_test: pipe: %s", strerror(errno));
586
587 aio_context_init(&ac, "aio_file_test", pipes[0], pipes[1], PIPE_LEN,
588 PIPE_TIMEOUT, aio_pipe_cleanup, pipes);
589 aio_write_test(&ac);
590 aio_read_test(&ac);
591
592 aio_pipe_cleanup(pipes);
593

--- 34 unchanged lines hidden (view full) ---

628 close(ama->ama_mdctl_fd);
629}
630
631#define MD_LEN GLOBAL_MAX
632#define MD_TIMEOUT 30
633static void
634aio_md_test(void)
635{
585
586 aio_context_init(&ac, "aio_file_test", pipes[0], pipes[1], PIPE_LEN,
587 PIPE_TIMEOUT, aio_pipe_cleanup, pipes);
588 aio_write_test(&ac);
589 aio_read_test(&ac);
590
591 aio_pipe_cleanup(pipes);
592

--- 34 unchanged lines hidden (view full) ---

627 close(ama->ama_mdctl_fd);
628}
629
630#define MD_LEN GLOBAL_MAX
631#define MD_TIMEOUT 30
632static void
633aio_md_test(void)
634{
636 int error, fd, i, mdctl_fd, unit;
635 int error, fd, mdctl_fd, unit;
637 char pathname[PATH_MAX];
638 struct aio_md_arg arg;
639 struct aio_context ac;
640 struct md_ioctl mdio;
641
636 char pathname[PATH_MAX];
637 struct aio_md_arg arg;
638 struct aio_context ac;
639 struct md_ioctl mdio;
640
641 aio_available();
642
643 if (geteuid() != 0) {
644 fprintf(stderr, "WARNING: aio_md_test: skipped as euid "
645 "!= 0\n");
646 return;
647 }
648
642 mdctl_fd = open("/dev/" MDCTL_NAME, O_RDWR, 0);
643 if (mdctl_fd < 0)
649 mdctl_fd = open("/dev/" MDCTL_NAME, O_RDWR, 0);
650 if (mdctl_fd < 0)
644 errx(-1, "FAIL: aio_md_test: open(/dev/%s): %s", MDCTL_NAME,
651 errx(1, "FAIL: aio_md_test: open(/dev/%s): %s", MDCTL_NAME,
645 strerror(errno));
646
647 bzero(&mdio, sizeof(mdio));
648 mdio.md_version = MDIOVERSION;
649 mdio.md_type = MD_MALLOC;
650 mdio.md_options = MD_AUTOUNIT | MD_COMPRESS;
651 mdio.md_mediasize = GLOBAL_MAX;
652 mdio.md_sectorsize = 512;
653
654 arg.ama_mdctl_fd = mdctl_fd;
655 arg.ama_unit = -1;
656 arg.ama_fd = -1;
657 if (ioctl(mdctl_fd, MDIOCATTACH, &mdio) < 0) {
658 error = errno;
659 aio_md_cleanup(&arg);
660 errno = error;
652 strerror(errno));
653
654 bzero(&mdio, sizeof(mdio));
655 mdio.md_version = MDIOVERSION;
656 mdio.md_type = MD_MALLOC;
657 mdio.md_options = MD_AUTOUNIT | MD_COMPRESS;
658 mdio.md_mediasize = GLOBAL_MAX;
659 mdio.md_sectorsize = 512;
660
661 arg.ama_mdctl_fd = mdctl_fd;
662 arg.ama_unit = -1;
663 arg.ama_fd = -1;
664 if (ioctl(mdctl_fd, MDIOCATTACH, &mdio) < 0) {
665 error = errno;
666 aio_md_cleanup(&arg);
667 errno = error;
661 errx(-1, "FAIL: aio_md_test: MDIOCATTACH: %s",
668 errx(1, "FAIL: aio_md_test: MDIOCATTACH: %s",
662 strerror(errno));
663 }
664
665 arg.ama_unit = unit = mdio.md_unit;
666 snprintf(pathname, PATH_MAX, "/dev/md%d", unit);
667 fd = open(pathname, O_RDWR);
668 if (fd < 0) {
669 error = errno;
670 aio_md_cleanup(&arg);
671 errno = error;
669 strerror(errno));
670 }
671
672 arg.ama_unit = unit = mdio.md_unit;
673 snprintf(pathname, PATH_MAX, "/dev/md%d", unit);
674 fd = open(pathname, O_RDWR);
675 if (fd < 0) {
676 error = errno;
677 aio_md_cleanup(&arg);
678 errno = error;
672 errx(-1, "FAIL: aio_md_test: open(%s): %s", pathname,
679 errx(1, "FAIL: aio_md_test: open(%s): %s", pathname,
673 strerror(errno));
674 }
675 arg.ama_fd = fd;
676
677 aio_context_init(&ac, "aio_md_test", fd, fd, MD_LEN, MD_TIMEOUT,
678 aio_md_cleanup, &arg);
679 aio_write_test(&ac);
680 aio_read_test(&ac);
681
682 aio_md_cleanup(&arg);
683
684 fprintf(stderr, "PASS: aio_md_test\n");
685}
686
687int
680 strerror(errno));
681 }
682 arg.ama_fd = fd;
683
684 aio_context_init(&ac, "aio_md_test", fd, fd, MD_LEN, MD_TIMEOUT,
685 aio_md_cleanup, &arg);
686 aio_write_test(&ac);
687 aio_read_test(&ac);
688
689 aio_md_cleanup(&arg);
690
691 fprintf(stderr, "PASS: aio_md_test\n");
692}
693
694int
688main(int argc, char *argv[])
695main(void)
689{
690
696{
697
691 aio_sigsys_setup();
692 aio_file_test();
693 aio_fifo_test();
694 aio_unix_socketpair_test();
695 aio_pty_test();
696 aio_pipe_test();
698 aio_file_test();
699 aio_fifo_test();
700 aio_unix_socketpair_test();
701 aio_pty_test();
702 aio_pipe_test();
697 if (geteuid() == 0)
698 aio_md_test();
699 else
700 fprintf(stderr, "WARNING: aio_md_test: skipped as euid "
701 "!= 0\n");
703 aio_md_test();
704
705 return (0);
702}
706}