Fix struct timespec normalization (as used in many other places).
[platform/upstream/glibc.git] / rt / tst-aio7.c
index 1b3bdea..0de6088 100644 (file)
@@ -1,5 +1,5 @@
 /* Test for AIO POSIX compliance.
-   Copyright (C) 2001 Free Software Foundation, Inc.
+   Copyright (C) 2001-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <aio.h>
 #include <error.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -34,6 +34,14 @@ static int
 do_test (void)
 {
   int result = 0;
+  int piped[2];
+
+  /* Make a pipe that we will never write to, so we can block reading it.  */
+  if (pipe (piped) < 0)
+    {
+      perror ("pipe");
+      return 1;
+    }
 
   /* Test for aio_cancel() detecting invalid file descriptor.  */
   {
@@ -52,6 +60,12 @@ do_test (void)
     /* Case one: invalid fds that match.  */
     if (aio_cancel (fd, &cb) != -1 || errno != EBADF)
       {
+       if (errno == ENOSYS)
+         {
+           puts ("no aio support in this configuration");
+           return 0;
+         }
+
        puts ("aio_cancel( -1, {-1..} ) did not return -1 or errno != EBADF");
        ++result;
       }
@@ -103,12 +117,13 @@ do_test (void)
 
   /* Test for aio_suspend() suspending even if completed elements in list.  */
   {
-    const int BYTES = 8, ELEMS = 2;
+#define BYTES 8
+    const int ELEMS = 2;
     int i, r, fd;
-    char buff[BYTES];
+    static char buff[BYTES];
     char name[] = "/tmp/aio7.XXXXXX";
     struct timespec timeout;
-    struct aiocb cb0, cb1;
+    static struct aiocb cb0, cb1;
     struct aiocb *list[ELEMS];
 
     fd = mkstemp (name);
@@ -140,9 +155,8 @@ do_test (void)
     printf ("\n");
 
     /* At this point, the first read is completed, so start another one on
-     * stdin, which will not complete unless the user inputs something.
-     */
-    cb1.aio_fildes = 0;
+       the read half of a pipe on which nothing will be written.  */
+    cb1.aio_fildes = piped[0];
     cb1.aio_offset = 0;
     cb1.aio_buf = buff;
     cb1.aio_nbytes = BYTES;
@@ -167,6 +181,9 @@ do_test (void)
        puts ("aio_suspend([done,blocked],2,3) suspended thread");
        ++result;
       }
+
+    /* Note that CB1 is still pending, and so cannot be an auto variable.
+       Thus we also test that exiting with an outstanding request works.  */
   }
 
   return result;