File indexing completed on 2025-05-11 08:24:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032
0033 #define CONFIGURE_INIT
0034 #include "system.h"
0035 #include <rtems.h>
0036 #include "tmacros.h"
0037 #include <rtems/posix/aio_misc.h>
0038 #include <aio.h>
0039 #include <stdlib.h>
0040 #include <unistd.h>
0041 #include <sched.h>
0042 #include <fcntl.h>
0043
0044 const char rtems_test_name[] = "PSXAIO 1";
0045
0046 #define BUFSIZE 512
0047 #define WRONG_FD 404
0048
0049
0050 static struct aiocb *create_aiocb( int fd );
0051 static void free_aiocb( struct aiocb *aiocbp );
0052
0053 static struct aiocb *create_aiocb( int fd )
0054 {
0055 struct aiocb *aiocbp;
0056
0057 aiocbp = malloc( sizeof( struct aiocb ) );
0058 memset( aiocbp, 0, sizeof( struct aiocb ) );
0059 aiocbp->aio_buf = malloc( BUFSIZE * sizeof( char ) );
0060 aiocbp->aio_nbytes = BUFSIZE;
0061 aiocbp->aio_offset = 0;
0062 aiocbp->aio_reqprio = 0;
0063 aiocbp->aio_fildes = fd;
0064 aiocbp->aio_sigevent.sigev_notify = SIGEV_NONE;
0065 return aiocbp;
0066 }
0067
0068 static void free_aiocb( struct aiocb *aiocbp )
0069 {
0070 free( (void*) aiocbp->aio_buf );
0071 free( aiocbp );
0072 }
0073
0074 void *POSIX_Init( void *argument )
0075 {
0076 int result, fd;
0077 struct aiocb *aiocbp;
0078 int status;
0079
0080 rtems_aio_init();
0081
0082 status = mkdir( "/tmp", S_IRWXU );
0083 rtems_test_assert( !status );
0084
0085 fd = open( "/tmp/aio_fildes", O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO );
0086 rtems_test_assert( fd != -1 );
0087
0088 TEST_BEGIN();
0089
0090
0091
0092 result = aio_write( NULL );
0093 status = errno;
0094 rtems_test_assert( result == -1 );
0095 rtems_test_assert( status == EINVAL );
0096
0097
0098
0099 result = aio_read( NULL );
0100 status = errno;
0101 rtems_test_assert( result == -1 );
0102 rtems_test_assert( status == EINVAL );
0103
0104
0105
0106 result = aio_fsync( O_SYNC, NULL );
0107 status = errno;
0108 rtems_test_assert( result == -1 );
0109 rtems_test_assert( status == EINVAL );
0110
0111
0112
0113 result = aio_return( NULL );
0114 status = errno;
0115 rtems_test_assert( result == -1 );
0116 rtems_test_assert( status == ENOENT );
0117
0118
0119
0120 result = aio_error( NULL );
0121 status = errno;
0122 rtems_test_assert( result == -1 );
0123 rtems_test_assert( status == EINVAL );
0124
0125 aiocbp = create_aiocb( WRONG_FD );
0126
0127
0128
0129 result = aio_write( aiocbp );
0130 status = errno;
0131 rtems_test_assert( result == -1 );
0132 rtems_test_assert( status == EBADF );
0133
0134
0135
0136 result = aio_read( aiocbp );
0137 status = errno;
0138 rtems_test_assert( result == -1 );
0139 rtems_test_assert( status == EBADF );
0140
0141
0142
0143 result = aio_cancel( WRONG_FD, NULL );
0144 status = errno;
0145 rtems_test_assert( result == -1 );
0146 rtems_test_assert( status == EBADF );
0147
0148
0149
0150 result = aio_fsync( O_SYNC, aiocbp );
0151 status = errno;
0152 rtems_test_assert( result == -1 );
0153 rtems_test_assert( status == EBADF );
0154
0155 free_aiocb( aiocbp );
0156
0157 aiocbp = create_aiocb( fd );
0158 aiocbp->aio_offset = -1;
0159
0160
0161
0162 result = aio_write( aiocbp );
0163 status = errno;
0164 rtems_test_assert( result == -1 );
0165 rtems_test_assert( status == EINVAL );
0166
0167
0168
0169 result = aio_read( aiocbp );
0170 status = errno;
0171 rtems_test_assert( result == -1 );
0172 rtems_test_assert( status == EINVAL );
0173
0174 free_aiocb( aiocbp );
0175
0176 aiocbp = create_aiocb( fd );
0177 aiocbp->aio_reqprio = AIO_PRIO_DELTA_MAX + 1;
0178
0179
0180
0181 result = aio_write( aiocbp );
0182 status = errno;
0183 rtems_test_assert( result == -1 );
0184 rtems_test_assert( status == EINVAL );
0185
0186
0187
0188 result = aio_read( aiocbp );
0189 status = errno;
0190 rtems_test_assert( result == -1 );
0191 rtems_test_assert( status == EINVAL );
0192
0193
0194
0195 result = aio_fsync( -1, aiocbp );
0196 status = errno;
0197 rtems_test_assert( result == -1 );
0198 rtems_test_assert( status == EINVAL );
0199
0200
0201
0202 aiocbp->aio_fildes = WRONG_FD;
0203 result = aio_cancel( fd, aiocbp );
0204 status = errno;
0205 rtems_test_assert( result == -1 );
0206 rtems_test_assert( status == EINVAL );
0207 aiocbp->aio_fildes = fd;
0208
0209
0210
0211 aiocbp->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
0212 aiocbp->aio_sigevent.sigev_notify_function = NULL;
0213 result = aio_fsync( O_SYNC, aiocbp );
0214 status = errno;
0215 rtems_test_assert( result == -1 );
0216 rtems_test_assert( status == EINVAL );
0217
0218
0219
0220 aiocbp->aio_sigevent.sigev_notify = SIGEV_THREAD;
0221 aiocbp->aio_sigevent.sigev_signo = 0;
0222 result = aio_fsync( O_SYNC, aiocbp );
0223 status = errno;
0224 rtems_test_assert( result == -1 );
0225 rtems_test_assert( status == EINVAL );
0226
0227 free_aiocb( aiocbp );
0228
0229 TEST_END();
0230
0231 close( fd );
0232 rtems_test_exit( 0 );
0233
0234 return NULL;
0235 }