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 #include <rtems/chain.h>
0044
0045 const char rtems_test_name[] = "PSXAIO 2";
0046
0047
0048 static struct aiocb *create_aiocb( int fd );
0049 static void free_aiocb( struct aiocb *aiocbp );
0050
0051 #define BUFSIZE 32
0052 #define FD_COUNT 10
0053 #define WRONG_FD 666
0054
0055 static struct aiocb *create_aiocb( int fd )
0056 {
0057 struct aiocb *aiocbp;
0058
0059 aiocbp = malloc( sizeof( struct aiocb ) );
0060 memset( aiocbp, 0, sizeof( struct aiocb ) );
0061 aiocbp->aio_buf = malloc( BUFSIZE * sizeof( char ) );
0062 aiocbp->aio_nbytes = BUFSIZE;
0063 aiocbp->aio_offset = 0;
0064 aiocbp->aio_reqprio = 0;
0065 aiocbp->aio_fildes = fd;
0066 aiocbp->aio_sigevent.sigev_notify = SIGEV_NONE;
0067 return aiocbp;
0068 }
0069
0070 static void free_aiocb( struct aiocb *aiocbp )
0071 {
0072 free( (void*) aiocbp->aio_buf );
0073 free( aiocbp );
0074 }
0075
0076 void *POSIX_Init( void *argument )
0077 {
0078 int fd[FD_COUNT];
0079 struct aiocb *aiocbp[FD_COUNT+1];
0080 int status, i, policy = SCHED_FIFO;
0081 char filename[BUFSIZE];
0082 struct sched_param param;
0083
0084 status = rtems_aio_init();
0085 rtems_test_assert( status == 0 );
0086
0087 param.sched_priority = 30;
0088 status = pthread_setschedparam(
0089 pthread_self(),
0090 policy, ¶m
0091 );
0092 rtems_test_assert( status == 0 );
0093
0094 status = mkdir( "/tmp", S_IRWXU );
0095 rtems_test_assert( !status );
0096
0097 TEST_BEGIN();
0098
0099 for( i=0; i<FD_COUNT; i++ )
0100 {
0101 sprintf( filename, "/tmp/aio_fildes%d", i );
0102 fd[i] = open(
0103 filename,
0104 O_RDWR|O_CREAT,
0105 S_IRWXU|S_IRWXG|S_IRWXO
0106 );
0107 rtems_test_assert( fd[i] != -1 );
0108 }
0109
0110 aiocbp[0] = create_aiocb( fd[0] );
0111 status = aio_write( aiocbp[0] );
0112 rtems_test_assert( status != -1 );
0113
0114 aiocbp[1] = create_aiocb( fd[1] );
0115 status = aio_write( aiocbp[1] );
0116 rtems_test_assert( status != -1 );
0117
0118 aiocbp[2] = create_aiocb( fd[1] );
0119 status = aio_read( aiocbp[2] );
0120 rtems_test_assert( status != -1 );
0121
0122 aiocbp[3] = create_aiocb( fd[2] );
0123 status = aio_write( aiocbp[3] );
0124 rtems_test_assert( status != -1 );
0125
0126 aiocbp[4] = create_aiocb( fd[3] );
0127 status = aio_write( aiocbp[4] );
0128 rtems_test_assert( status != -1 );
0129
0130 aiocbp[5] = create_aiocb( fd[4] );
0131 status = aio_write( aiocbp[5] );
0132 rtems_test_assert( status != -1 );
0133
0134 aiocbp[6] = create_aiocb( fd[5] );
0135 status = aio_write( aiocbp[6] );
0136 rtems_test_assert( status != -1 );
0137
0138 aiocbp[7] = create_aiocb( fd[6] );
0139 status = aio_write( aiocbp[7] );
0140 rtems_test_assert( status != -1 );
0141
0142 aiocbp[8] = create_aiocb( fd[6] );
0143 status = aio_read( aiocbp[8] );
0144 rtems_test_assert( status != -1 );
0145
0146 aiocbp[9] = create_aiocb( fd[0] );
0147 status = aio_fsync( O_SYNC, aiocbp[9] );
0148 rtems_test_assert( status != -1 );
0149
0150 aiocbp[9] = create_aiocb( fd[0] );
0151 status = aio_fsync( O_DSYNC, aiocbp[9] );
0152 rtems_test_assert( status != -1 );
0153
0154 status = aio_cancel( WRONG_FD, NULL );
0155 rtems_test_assert( status == -1 );
0156
0157 status = aio_cancel( fd[7], NULL );
0158 rtems_test_assert( status == AIO_ALLDONE );
0159
0160 status = aio_cancel( fd[1], NULL );
0161 rtems_test_assert( status == AIO_CANCELED );
0162
0163 status = aio_cancel( fd[6], NULL );
0164 rtems_test_assert( status == AIO_CANCELED );
0165
0166 status = aio_cancel( fd[4], aiocbp[4] );
0167 rtems_test_assert( status == -1 );
0168
0169 aiocbp[10] = create_aiocb( fd[9] );
0170 status = aio_cancel( fd[9], aiocbp[10] );
0171 rtems_test_assert( status == -1 );
0172
0173 status = aio_cancel( fd[5], aiocbp[6] );
0174 rtems_test_assert( status == AIO_CANCELED );
0175
0176
0177
0178 int result = aio_error( aiocbp[6] );
0179 rtems_test_assert( result == ECANCELED );
0180
0181 result = aio_return( aiocbp[6] );
0182 rtems_test_assert( result == -1 );
0183
0184 result = aio_return( aiocbp[6] );
0185 rtems_test_assert( result == -1 );
0186
0187 rtems_test_assert( errno == EINVAL );
0188 result = aio_error( aiocbp[6] );
0189 rtems_test_assert( result == -1 );
0190 rtems_test_assert( errno == EINVAL );
0191
0192 status = aio_cancel( fd[0], aiocbp[9] );
0193 rtems_test_assert( status == AIO_CANCELED );
0194
0195 status = aio_cancel( fd[5], aiocbp[6] );
0196 rtems_test_assert( status == AIO_ALLDONE );
0197
0198 TEST_END();
0199
0200 for ( i = 0; i < FD_COUNT; i++ )
0201 {
0202 close( fd[i] );
0203 free_aiocb( aiocbp[i] );
0204 }
0205 free_aiocb( aiocbp[i] );
0206 rtems_test_exit( 0 );
0207
0208 return NULL;
0209
0210 }