Index: testsuites/psxtests/ChangeLog
===================================================================
--- testsuites/psxtests/ChangeLog	(revision 5f92568509ef5c922ea10eb346f9775ddf8d2163)
+++ testsuites/psxtests/ChangeLog	(revision a14b982755d43c8b1b6795996625dce357a28714)
@@ -1,2 +1,6 @@
+2010-11-01	Alin Rus <alin.codejunkie@gmail.com>
+
+	* psxaio01/init.c, psxaio02/init.c: Improve coverage.
+
 2010-10-21	Joel Sherrill <joel.sherrill@oarcorp.com>
 
Index: testsuites/psxtests/psxaio01/init.c
===================================================================
--- testsuites/psxtests/psxaio01/init.c	(revision 5f92568509ef5c922ea10eb346f9775ddf8d2163)
+++ testsuites/psxtests/psxaio01/init.c	(revision a14b982755d43c8b1b6795996625dce357a28714)
@@ -25,5 +25,5 @@
 
 struct aiocb *
-create_aiocb (void)
+create_aiocb (int fd)
 {
   struct aiocb *aiocbp;
@@ -35,5 +35,5 @@
   aiocbp->aio_offset = 0;
   aiocbp->aio_reqprio = 0;
-  aiocbp->aio_fildes = open ("aio_fildes", O_RDWR | O_CREAT);
+  aiocbp->aio_fildes = fd;
 
   return aiocbp;
@@ -50,39 +50,23 @@
 POSIX_Init (void *argument)
 {
-  int result, policy;
+  int result, fd;
   struct aiocb *aiocbp;
-  rtems_status_code status;
-  struct sched_param param;
+  int status;
+
+  rtems_aio_init ();
+
+  status = mkdir ("/tmp", S_IRWXU);
+  rtems_test_assert (!status);
+  
+  fd = open ("/tmp/aio_fildes", O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
+  rtems_test_assert ( fd != -1);
 
   puts ("\n\n*** POSIX AIO TEST 01 ***");
 
-  puts ("\n*** POSIX aio_write() test ***");
+  puts (" Init: EBADF TESTS ");
 
-  /* Request canceled */
-  puts ("Init: aio_write - ECANCELED");
-
-  aiocbp = create_aiocb ();
-  aio_write (aiocbp);
-  aio_cancel (aiocbp->aio_fildes, aiocbp);
-  result = aio_return (aiocbp);
-  rtems_test_assert (result != -1);
-  status = aio_error (aiocbp);
-  rtems_test_assert (status != ECANCELED);
-  free_aiocb (aiocbp);
-
-  /* Successfull added request to queue */
-  puts ("Init: aio_write - SUCCESSFUL");
-  aiocbp = create_aiocb ();
-  aiocbp->aio_fildes = WRONG_FD;
+  aiocbp = create_aiocb (WRONG_FD);
   status = aio_write (aiocbp);
-  rtems_test_assert (!status);
-
-  pthread_getschedparam (pthread_self (), &policy, &param);
-  policy = SCHED_RR;
-  param.sched_priority = 30;
-  pthread_setschedparam (pthread_self (), policy, &param);
-  sleep (1);
-
-  while (aio_error (aiocbp) == EINPROGRESS);
+  rtems_test_assert (status == -1);
 
   /* Bad file descriptor */
@@ -90,7 +74,41 @@
 
   result = aio_return (aiocbp);
-  rtems_test_assert (result != -1);
+  rtems_test_assert (result == -1);
   status = aio_error (aiocbp);
-  rtems_test_assert (status != EBADF);
+  rtems_test_assert (status == EBADF);
+
+  status = aio_read (aiocbp);
+  rtems_test_assert (status == -1);
+
+  /* Bad file descriptor */
+  puts ("Init: aio_read() - EBADF ");
+
+  result = aio_return (aiocbp);
+  rtems_test_assert (result == -1);
+  status = aio_error (aiocbp);
+  rtems_test_assert (status == EBADF);
+
+  status = aio_cancel (WRONG_FD, NULL);
+  rtems_test_assert (status == -1);
+
+  /* Bad file descriptor */
+  puts ("Init: aio_cancel() - EBADF ");
+  
+  result = aio_return (aiocbp);
+  rtems_test_assert (result == -1);
+  status = aio_error (aiocbp);
+  rtems_test_assert (status == EBADF);
+
+  status = aio_fsync (O_SYNC, aiocbp);
+  rtems_test_assert (status == -1);
+  
+  /* Bad file descriptor */
+  puts ("Init: aio_fsync() - EBADF ");
+
+  result = aio_return (aiocbp);
+  rtems_test_assert (result == -1);
+  status = aio_error (aiocbp);
+  rtems_test_assert (status == EBADF);
+  
   free_aiocb (aiocbp);
 
@@ -98,15 +116,25 @@
   puts ("Init: aio_write() - EINVAL [aio_offset]");
 
-  aiocbp = create_aiocb ();
+  aiocbp = create_aiocb (fd);
   aiocbp->aio_offset = -1;
-  aio_write (aiocbp);
-  sleep (1);
-
-  while (aio_error (aiocbp) == EINPROGRESS);
+  status = aio_write (aiocbp);
+  rtems_test_assert (status == -1);
 
   result = aio_return (aiocbp);
-  rtems_test_assert (result != -1);
+  rtems_test_assert (result == -1);
   status = aio_error (aiocbp);
-  rtems_test_assert (status != EINVAL);
+  rtems_test_assert (status == EINVAL);
+
+    /* Invalid offset */
+  puts ("Init: aio_read() - EINVAL [aio_offset]");
+
+  status = aio_read (aiocbp);
+  rtems_test_assert (status == -1);
+
+  result = aio_return (aiocbp);
+  rtems_test_assert (result == -1);
+  status = aio_error (aiocbp);
+  rtems_test_assert (status == EINVAL);
+
   free_aiocb (aiocbp);
 
@@ -114,35 +142,51 @@
   puts ("Init: aio_write() - EINVAL [aio_reqprio]");
 
-  aiocbp = create_aiocb ();
+  aiocbp = create_aiocb (fd);
   aiocbp->aio_reqprio = AIO_PRIO_DELTA_MAX + 1;
-  aio_write (aiocbp);
-  sleep (1);
-
-  while (aio_error (aiocbp) == EINPROGRESS);
+  status = aio_write (aiocbp);
+  rtems_test_assert (status == -1);
 
   result = aio_return (aiocbp);
-  rtems_test_assert (result != -1);
+  rtems_test_assert (result == -1);
   status = aio_error (aiocbp);
-  rtems_test_assert (status != EINVAL);
-  free_aiocb (aiocbp);
+  rtems_test_assert (status == EINVAL);
 
-  /* aio_nbytes > 0 and aio_offset >= SEEK_END */
-  puts ("Init: aio_write() - EFBIG");
-  aiocbp = create_aiocb ();
-  aiocbp->aio_nbytes = 1;
-  aiocbp->aio_offset = lseek (aiocbp->aio_fildes, 0, SEEK_END) + 1;
-  aio_write (aiocbp);
-  sleep (1);
+   /* Invalid request priority */
+  puts ("Init: aio_read() - EINVAL [aio_reqprio]");
 
-  while (aio_error (aiocbp) == EINPROGRESS);
+  status = aio_read (aiocbp);
+  rtems_test_assert (status == -1);
 
   result = aio_return (aiocbp);
-  rtems_test_assert (result != -1);
+  rtems_test_assert (result == -1);
   status = aio_error (aiocbp);
-  rtems_test_assert (status != EFBIG);
+  rtems_test_assert (status == EINVAL);
+
+  /* Invalid request aio_cancel */
+  puts ("Init: aio_cancel() - EINVAL ");
+
+  status = aio_cancel (WRONG_FD, aiocbp);
+  rtems_test_assert (status == -1);
+
+  result = aio_return (aiocbp);
+  rtems_test_assert (result == -1);
+  status = aio_error (aiocbp);
+  rtems_test_assert (status == EINVAL);
+
+  /* Invalid operation to aio_fsync */
+  puts ("Init: aio_fsync() - EINVAL ");
+  status = aio_fsync (-1, aiocbp);
+  rtems_test_assert (status == -1);
+
+  result = aio_return (aiocbp);
+  rtems_test_assert (result == -1);
+  status = aio_error (aiocbp);
+  rtems_test_assert (status == EINVAL);
+
   free_aiocb (aiocbp);
 
   puts ("*** END OF POSIX AIO TEST 01 ***");
 
+  close (fd);
   rtems_test_exit (0);
 
Index: testsuites/psxtests/psxaio02/init.c
===================================================================
--- testsuites/psxtests/psxaio02/init.c	(revision 5f92568509ef5c922ea10eb346f9775ddf8d2163)
+++ testsuites/psxtests/psxaio02/init.c	(revision a14b982755d43c8b1b6795996625dce357a28714)
@@ -20,10 +20,11 @@
 #include <sched.h>
 #include <fcntl.h>
+#include <rtems/chain.h>
 
-#define BUFSIZE 512
-#define WRONG_FD 404
+#define BUFSIZE 32
+#define MAX 7
 
 struct aiocb *
-create_aiocb (void)
+create_aiocb (int fd)
 {
   struct aiocb *aiocbp;
@@ -35,5 +36,5 @@
   aiocbp->aio_offset = 0;
   aiocbp->aio_reqprio = 0;
-  aiocbp->aio_fildes = open ("aio_fildes", O_RDWR | O_CREAT);
+  aiocbp->aio_fildes = fd;
 
   return aiocbp;
@@ -50,99 +51,82 @@
 POSIX_Init (void *argument)
 {
-  int result, policy;
-  struct aiocb *aiocbp;
-  rtems_status_code status;
-  struct sched_param param;
+  int fd[MAX];
+  struct aiocb *aiocbp[MAX+2];
+  int status, i;
+  char filename[BUFSIZE];
+
+  status = rtems_aio_init ();
+  rtems_test_assert (status == 0);
+ 
+  status = mkdir ("/tmp", S_IRWXU);
+  rtems_test_assert (!status);
+  
+  puts ("\n\n*** POSIX AIO TEST 02 ***");
+  
+  puts (" Init: Open files ");
+
+  for (i=0; i<MAX; i++)
+    {
+      sprintf (filename, "/tmp/aio_fildes%d",i);
+      fd[i] = open (filename, O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
+      rtems_test_assert ( fd[i] != -1);
+    }
+  
+  puts (" Init: [WQ] aio_write on 1st file ");
+  aiocbp[0] = create_aiocb (fd[0]);
+  status = aio_write (aiocbp[0]);
+  rtems_test_assert (status != -1);
+
+  puts (" Init: [WQ] aio_write on 2nd file ");
+  aiocbp[1] = create_aiocb (fd[1]);
+  status = aio_write (aiocbp[1]);
+  rtems_test_assert (status != -1);
+  
+  puts (" Init: [WQ] aio_read on 2nd file add by priority ");
+  aiocbp[2] = create_aiocb (fd[1]);
+  status = aio_read (aiocbp[2]);
+  rtems_test_assert (status != -1);
+  
+  puts (" Init: [WQ] aio_write on 3rd file "); 
+  aiocbp[3] = create_aiocb (fd[2]);
+  status = aio_write (aiocbp[3]);
+  rtems_test_assert (status != -1);
+  
+  puts (" Init: [WQ] aio_write on 4th file ");
+  aiocbp[4] = create_aiocb (fd[3]);
+  status = aio_write (aiocbp[4]);
+  rtems_test_assert (status != -1);
+  
+  puts (" Init: [WQ] aio_write on 5th file  -- [WQ] full ");
+  aiocbp[5] = create_aiocb (fd[4]);
+  status = aio_write (aiocbp[5]);
+  rtems_test_assert (status != -1);
+  
+  puts (" Init: [IQ] aio_write on 6th file ");
+  aiocbp[6] = create_aiocb (fd[5]);
+  status = aio_write (aiocbp[6]);
+  rtems_test_assert (status != -1);
+  
+  puts (" Init: [IQ] aio_write on 7th file ");
+  aiocbp[7] = create_aiocb (fd[6]);
+  status = aio_write (aiocbp[7]);
+  rtems_test_assert (status != -1);
+
+  puts (" Init: [IQ] aio_read on 7th file add by priority ");
+  aiocbp[8] = create_aiocb (fd[6]);
+  status = aio_read (aiocbp[8]);
+  rtems_test_assert (status != -1);
 
   puts ("\n\n*** POSIX AIO TEST 02 ***");
 
-  puts ("\n*** POSIX aio_read() test ***");
-
-  /* Request canceled */
-  puts ("Init: aio_read - ECANCELED");
-
-  aiocbp = create_aiocb ();
-  aio_read (aiocbp);
-  aio_cancel (aiocbp->aio_fildes, aiocbp);
-  result = aio_return (aiocbp);
-  rtems_test_assert (result != -1);
-  status = aio_error (aiocbp);
-  rtems_test_assert (status != ECANCELED);
-  free_aiocb (aiocbp);
-
-  /* Successfull added request to queue */
-  puts ("Init: aio_read - SUCCESSFUL");
-  aiocbp = create_aiocb ();
-  aiocbp->aio_fildes = WRONG_FD;
-  status = aio_read (aiocbp);
-  rtems_test_assert (!status);
-
-  pthread_getschedparam (pthread_self (), &policy, &param);
-  policy = SCHED_RR;
-  param.sched_priority = 30;
-  pthread_setschedparam (pthread_self (), policy, &param);
-  sleep (1);
-
-  while (aio_error (aiocbp) == EINPROGRESS);
-
-  /* Bad file descriptor */
-  puts ("Init: aio_read() - EBADF ");
-
-  result = aio_return (aiocbp);
-  rtems_test_assert (result != -1);
-  status = aio_error (aiocbp);
-  rtems_test_assert (status != EBADF);
-  free_aiocb (aiocbp);
-
-  /* Invalid offset */
-  puts ("Init: aio_read() - EINVAL [aio_offset]");
-
-  aiocbp = create_aiocb ();
-  aiocbp->aio_offset = -1;
-  aio_read (aiocbp);
-  sleep (1);
-
-  while (aio_error (aiocbp) == EINPROGRESS);
-
-  result = aio_return (aiocbp);
-  rtems_test_assert (result != -1);
-  status = aio_error (aiocbp);
-  rtems_test_assert (status != EINVAL);
-  free_aiocb (aiocbp);
-
-  /* Invalid request priority */
-  puts ("Init: aio_read() - EINVAL [aio_reqprio]");
-
-  aiocbp = create_aiocb ();
-  aiocbp->aio_reqprio = AIO_PRIO_DELTA_MAX + 1;
-  aio_read (aiocbp);
-  sleep (1);
-
-  while (aio_error (aiocbp) == EINPROGRESS);
-
-  result = aio_return (aiocbp);
-  rtems_test_assert (result != -1);
-  status = aio_error (aiocbp);
-  rtems_test_assert (status != EINVAL);
-  free_aiocb (aiocbp);
-
-  /* aio_nbytes > 0 && aio_nbytes + aio_offset > max offset of aio_fildes */
-  puts ("Init: aio_read() - OVERFLOW");
-  aiocbp = create_aiocb ();
-  aiocbp->aio_nbytes = 10;
-  aiocbp->aio_offset = lseek (aiocbp->aio_fildes, 0, SEEK_END);
-  aio_read (aiocbp);
-  sleep (1);
-
-  while (aio_error (aiocbp) == EINPROGRESS);
-
-  result = aio_return (aiocbp);
-  rtems_test_assert (result != -1);
-  status = aio_error (aiocbp);
-  rtems_test_assert (status != EFBIG);
-  free_aiocb (aiocbp);
-
   puts ("*** END OF POSIX AIO TEST 01 ***");
 
+  for (i = 0; i < MAX; i++)
+    {
+      close (fd[i]);
+      free_aiocb (aiocbp[i]);      
+    }
+  free_aiocb (aiocbp[i]);
+  free_aiocb (aiocbp[i+1]);
   rtems_test_exit (0);
 
