File indexing completed on 2025-05-11 08:24:40
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 #include <pmacros.h>
0034 #include <unistd.h>
0035 #include <errno.h>
0036 #include <tmacros.h>
0037
0038 #include <fcntl.h> /* For O_* constants */
0039 #include <sys/stat.h> /* For mode constants */
0040 #include <mqueue.h>
0041
0042 #include "test_support.h"
0043
0044 const char rtems_test_name[] = "PSXMSGQ 4";
0045
0046
0047 void *POSIX_Init(void *argument);
0048
0049 void *POSIX_Init(
0050 void *argument
0051 )
0052 {
0053 struct mq_attr attr;
0054 mqd_t Queue, second_Queue;
0055 int sc;
0056 Heap_Information_block start;
0057 size_t to_alloc;
0058 void *alloced;
0059 bool sb;
0060 const char *name;
0061
0062 TEST_BEGIN();
0063
0064 attr.mq_maxmsg = 1;
0065 attr.mq_msgsize = sizeof(int);
0066
0067 puts( "Init - Open message queue instance 1" );
0068 Queue = mq_open( "Queue", O_CREAT | O_RDWR, 0x777, &attr );
0069 if ( Queue == (-1) )
0070 perror( "mq_open failed" );
0071 rtems_test_assert( Queue != (-1) );
0072
0073 puts( "Init - Open message queue instance 2 - FAIL - ENFILE " );
0074 second_Queue = mq_open( "Queue2", O_CREAT | O_RDWR, 0x777, &attr );
0075 if ( second_Queue != (-1) )
0076 puts( "mq_open did not failed" );
0077 rtems_test_assert( second_Queue == (-1) );
0078 rtems_test_assert( errno == ENFILE );
0079
0080 puts( "Init - Unlink message queue instance 1" );
0081 sc = mq_unlink( "Queue" );
0082 if ( sc != 0 )
0083 perror( "mq_unlink failed" );
0084 rtems_test_assert( sc == 0 );
0085
0086 puts( "Init - Close message queue instance 1" );
0087 sc = mq_close( Queue );
0088 if ( sc != 0 )
0089 perror( "mq_close failed" );
0090 rtems_test_assert( sc == 0 );
0091
0092 sb = rtems_workspace_get_information( &start );
0093 rtems_test_assert( start.Free.number == 1 );
0094 to_alloc = start.Free.largest;
0095
0096
0097 while ( 1 ) {
0098 sb = rtems_workspace_allocate( to_alloc, &alloced );
0099 if ( sb )
0100 break;
0101 to_alloc -= 4;
0102 }
0103
0104 rtems_workspace_free( alloced );
0105
0106
0107
0108
0109 puts( "Init - Memory allocation error test" );
0110
0111 name = Get_Longest_Name();
0112 do {
0113 sb = rtems_workspace_allocate( to_alloc, &alloced );
0114 rtems_test_assert( sb );
0115
0116 second_Queue = mq_open(name,O_CREAT | O_RDWR, 0x777, &attr );
0117
0118
0119 rtems_workspace_free( alloced );
0120
0121 to_alloc -= 4;
0122 } while ( second_Queue == -1 );
0123
0124 puts( "Init - Message Queue created" );
0125
0126 puts( "Init - Unlink message queue" );
0127 sc = mq_unlink( name );
0128 if ( sc != 0 )
0129 perror( "mq_unlink failed" );
0130 rtems_test_assert( sc == 0 );
0131
0132 puts( "Init - Close message queue" );
0133 sc = mq_close( second_Queue );
0134 if ( sc != 0 )
0135 perror( "mq_close failed" );
0136 rtems_test_assert( sc == 0 );
0137
0138 TEST_END();
0139 rtems_test_exit( 0 );
0140
0141 return NULL;
0142 }
0143
0144
0145
0146 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0147 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0148
0149 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0150
0151
0152 #define CONFIGURE_MESSAGE_BUFFER_MEMORY \
0153 (2 * CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(1, sizeof(int)))
0154
0155 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0156
0157 #define CONFIGURE_MAXIMUM_POSIX_THREADS 1
0158 #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 1
0159
0160 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0161
0162 #define CONFIGURE_INIT
0163 #include <rtems/confdefs.h>