From a14b982755d43c8b1b6795996625dce357a28714 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 1 Nov 2010 17:33:08 +0000 Subject: 2010-11-01 Alin Rus * psxaio01/init.c, psxaio02/init.c: Improve coverage. --- testsuites/psxtests/ChangeLog | 4 + testsuites/psxtests/psxaio01/init.c | 148 ++++++++++++++++++++----------- testsuites/psxtests/psxaio02/init.c | 172 ++++++++++++++++-------------------- 3 files changed, 178 insertions(+), 146 deletions(-) (limited to 'testsuites') diff --git a/testsuites/psxtests/ChangeLog b/testsuites/psxtests/ChangeLog index f09ac1de62..a8e22cd71c 100644 --- a/testsuites/psxtests/ChangeLog +++ b/testsuites/psxtests/ChangeLog @@ -1,3 +1,7 @@ +2010-11-01 Alin Rus + + * psxaio01/init.c, psxaio02/init.c: Improve coverage. + 2010-10-21 Joel Sherrill * psx05/init.c: Check for correct status returned. diff --git a/testsuites/psxtests/psxaio01/init.c b/testsuites/psxtests/psxaio01/init.c index 7af884201f..d4e8e05803 100644 --- a/testsuites/psxtests/psxaio01/init.c +++ b/testsuites/psxtests/psxaio01/init.c @@ -24,7 +24,7 @@ #define WRONG_FD 404 struct aiocb * -create_aiocb (void) +create_aiocb (int fd) { struct aiocb *aiocbp; @@ -34,7 +34,7 @@ create_aiocb (void) aiocbp->aio_nbytes = BUFSIZE; aiocbp->aio_offset = 0; aiocbp->aio_reqprio = 0; - aiocbp->aio_fildes = open ("aio_fildes", O_RDWR | O_CREAT); + aiocbp->aio_fildes = fd; return aiocbp; } @@ -49,101 +49,145 @@ free_aiocb (struct aiocb *aiocbp) void * 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 (WRONG_FD); + status = aio_write (aiocbp); + rtems_test_assert (status == -1); + + /* Bad file descriptor */ + puts ("Init: aio_write() - EBADF "); - aiocbp = create_aiocb (); - aio_write (aiocbp); - aio_cancel (aiocbp->aio_fildes, aiocbp); result = aio_return (aiocbp); - rtems_test_assert (result != -1); + rtems_test_assert (result == -1); status = aio_error (aiocbp); - rtems_test_assert (status != ECANCELED); - free_aiocb (aiocbp); + rtems_test_assert (status == EBADF); - /* Successfull added request to queue */ - puts ("Init: aio_write - SUCCESSFUL"); - aiocbp = create_aiocb (); - aiocbp->aio_fildes = WRONG_FD; - status = aio_write (aiocbp); - rtems_test_assert (!status); + status = aio_read (aiocbp); + rtems_test_assert (status == -1); + + /* Bad file descriptor */ + puts ("Init: aio_read() - EBADF "); - pthread_getschedparam (pthread_self (), &policy, ¶m); - policy = SCHED_RR; - param.sched_priority = 30; - pthread_setschedparam (pthread_self (), policy, ¶m); - sleep (1); + result = aio_return (aiocbp); + rtems_test_assert (result == -1); + status = aio_error (aiocbp); + rtems_test_assert (status == EBADF); - while (aio_error (aiocbp) == EINPROGRESS); + status = aio_cancel (WRONG_FD, NULL); + rtems_test_assert (status == -1); /* Bad file descriptor */ - puts ("Init: aio_write() - EBADF "); + 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); + rtems_test_assert (result == -1); status = aio_error (aiocbp); - rtems_test_assert (status != EBADF); + rtems_test_assert (status == EBADF); + free_aiocb (aiocbp); /* Invalid offset */ puts ("Init: aio_write() - EINVAL [aio_offset]"); - aiocbp = create_aiocb (); + aiocbp = create_aiocb (fd); aiocbp->aio_offset = -1; - aio_write (aiocbp); - sleep (1); + status = aio_write (aiocbp); + rtems_test_assert (status == -1); + + result = aio_return (aiocbp); + rtems_test_assert (result == -1); + status = aio_error (aiocbp); + rtems_test_assert (status == EINVAL); - while (aio_error (aiocbp) == EINPROGRESS); + /* 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); + rtems_test_assert (result == -1); status = aio_error (aiocbp); - rtems_test_assert (status != EINVAL); + rtems_test_assert (status == EINVAL); + free_aiocb (aiocbp); /* Invalid request priority */ 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); + status = aio_write (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 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 != 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 aio_cancel */ + puts ("Init: aio_cancel() - EINVAL "); - while (aio_error (aiocbp) == EINPROGRESS); + status = aio_cancel (WRONG_FD, 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 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); return NULL; diff --git a/testsuites/psxtests/psxaio02/init.c b/testsuites/psxtests/psxaio02/init.c index 240dd30e4c..7a1882c852 100644 --- a/testsuites/psxtests/psxaio02/init.c +++ b/testsuites/psxtests/psxaio02/init.c @@ -19,12 +19,13 @@ #include #include #include +#include -#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; @@ -34,7 +35,7 @@ create_aiocb (void) aiocbp->aio_nbytes = BUFSIZE; aiocbp->aio_offset = 0; aiocbp->aio_reqprio = 0; - aiocbp->aio_fildes = open ("aio_fildes", O_RDWR | O_CREAT); + aiocbp->aio_fildes = fd; return aiocbp; } @@ -49,101 +50,84 @@ free_aiocb (struct aiocb *aiocbp) void * POSIX_Init (void *argument) { - int result, policy; - struct aiocb *aiocbp; - rtems_status_code status; - struct sched_param param; - - 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); + 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; iaio_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 ("\n\n*** POSIX AIO TEST 02 ***"); 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); return NULL; -- cgit v1.2.3