1 /* Test for AIO POSIX compliance.
2 Copyright (C) 2001,02 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 /* We might wait for 3 seconds, so increase timeout to 10 seconds. */
32 #define TEST_FUNCTION do_test ()
39 /* Make a pipe that we will never write to, so we can block reading it. */
46 /* Test for aio_cancel() detecting invalid file descriptor. */
56 cb
.aio_sigevent
.sigev_notify
= SIGEV_NONE
;
60 /* Case one: invalid fds that match. */
61 if (aio_cancel (fd
, &cb
) != -1 || errno
!= EBADF
)
65 puts ("no aio support in this configuration");
69 puts ("aio_cancel( -1, {-1..} ) did not return -1 or errno != EBADF");
76 /* Case two: invalid fds that do not match; just print warning. */
77 if (aio_cancel (fd
, &cb
) != -1 || errno
!= EBADF
)
78 puts ("aio_cancel( -1, {-2..} ) did not return -1 or errno != EBADF");
81 /* Test for aio_fsync() detecting bad fd, and fd not open for writing. */
91 cb
.aio_sigevent
.sigev_notify
= SIGEV_NONE
;
95 /* Case one: invalid fd. */
96 if (aio_fsync (O_SYNC
, &cb
) != -1 || errno
!= EBADF
)
98 puts ("aio_fsync( op, {-1..} ) did not return -1 or errno != EBADF");
102 if ((fd
= open ("/dev/null", O_RDONLY
)) < 0)
103 error (1, errno
, "opening /dev/null");
108 /* Case two: valid fd but open for read only. */
109 if (aio_fsync (O_SYNC
, &cb
) != -1 || errno
!= EBADF
)
111 puts ("aio_fsync( op, {RO..} ) did not return -1 or errno != EBADF");
118 /* Test for aio_suspend() suspending even if completed elements in list. */
120 const int BYTES
= 8, ELEMS
= 2;
123 char name
[] = "/tmp/aio7.XXXXXX";
124 struct timespec timeout
;
125 struct aiocb cb0
, cb1
;
126 struct aiocb
*list
[ELEMS
];
130 error (1, errno
, "creating temp file");
133 error (1, errno
, "unlinking temp file");
135 if (write (fd
, "01234567", BYTES
) != BYTES
)
136 error (1, errno
, "writing to temp file");
141 cb0
.aio_nbytes
= BYTES
;
143 cb0
.aio_sigevent
.sigev_notify
= SIGEV_NONE
;
147 error (1, errno
, "reading from file");
149 while (aio_error (&(cb0
)) == EINPROGRESS
)
152 for (i
= 0; i
< BYTES
; i
++)
153 printf ("%c ", buff
[i
]);
156 /* At this point, the first read is completed, so start another one on
157 the read half of a pipe on which nothing will be written. */
158 cb1
.aio_fildes
= piped
[0];
161 cb1
.aio_nbytes
= BYTES
;
163 cb1
.aio_sigevent
.sigev_notify
= SIGEV_NONE
;
167 error (1, errno
, "reading from file");
169 /* Now call aio_suspend() with the two reads. It should return
170 * immediately according to the POSIX spec.
176 r
= aio_suspend ((const struct aiocb
* const *) list
, ELEMS
, &timeout
);
178 if (r
== -1 && errno
== EAGAIN
)
180 puts ("aio_suspend([done,blocked],2,3) suspended thread");
188 #include "../test-skeleton.c"