void *POSIX_Init( void *argument ) { struct mq_attr attr; mqd_t mq; puts( "\n\n*** POSIX MESSAGE QUEUE 02 TEST ***" ); /* set the time of day, and print our buffer in multiple ways */ set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 ); /* get id of this thread */ Init_id = pthread_self(); printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id ); Allocate_majority_of_workspace(NAME_MAX); attr.mq_maxmsg = MAXMSG; attr.mq_msgsize = MSGSIZE; puts("Init: mq_open - Workspace not available - ENOMEM"); mq = mq_open( Get_Longest_Name(), O_CREAT, 0x777, &attr ); fatal_posix_service_status_errno(mq, ENOMEM, "no workspace available"); puts( "*** END OF POSIX MESSAGE QUEUE 02 TEST ***" ); rtems_test_exit( 0 ); return NULL; /* just so the compiler thinks we returned something */ }
void *POSIX_Init( void *argument ) { struct mq_attr attr; mqd_t Queue, second_Queue; int sc; Heap_Information_block start; Heap_Information_block info; size_t to_alloc; void *alloced; bool sb; const char *name; puts( "\n\n*** POSIX MESSAGE QUEUE TEST 4 ***" ); attr.mq_maxmsg = 1; attr.mq_msgsize = sizeof(int); puts( "Init - Open message queue instance 1" ); Queue = mq_open( "Queue", O_CREAT | O_RDWR, 0x777, &attr ); if ( Queue == (-1) ) perror( "mq_open failed" ); rtems_test_assert( Queue != (-1) ); puts( "Init - Open message queue instance 2 - FAIL - ENFILE " ); second_Queue = mq_open( "Queue2", O_CREAT | O_RDWR, 0x777, &attr ); if ( second_Queue != (-1) ) puts( "mq_open did not failed" ); rtems_test_assert( second_Queue == (-1) ); rtems_test_assert( errno == ENFILE ); puts( "Init - Unlink message queue instance 1" ); sc = mq_unlink( "Queue" ); if ( sc != 0 ) perror( "mq_unlink failed" ); rtems_test_assert( sc == 0 ); puts( "Init - Close message queue instance 1" ); sc = mq_close( Queue ); if ( sc != 0 ) perror( "mq_close failed" ); rtems_test_assert( sc == 0 ); sb = rtems_workspace_get_information( &start ); rtems_test_assert( start.Free.number == 1 ); to_alloc = start.Free.largest; /* find the largest we can actually allocate */ while ( 1 ) { sb = rtems_workspace_allocate( to_alloc, &alloced ); if ( sb ) break; to_alloc -= 4; } rtems_workspace_free( alloced ); /* * Now do the test */ puts( "Init - Memory allocation error test" ); sb = rtems_workspace_get_information( &info ); attr.mq_maxmsg = 1; attr.mq_msgsize = 200; name = Get_Longest_Name(); while ( attr.mq_msgsize > 0 ) { sb = rtems_workspace_allocate( to_alloc, &alloced ); rtems_test_assert( sb ); second_Queue = mq_open(name,O_CREAT | O_RDWR, 0x777, &attr ); /* free the memory we snagged, then check the status */ rtems_workspace_free( alloced ); if ( second_Queue != (-1) ) break; /* attr.mq_msgsize -= 48; */ to_alloc -= 4; } if ( second_Queue == -1 ) rtems_test_exit(0); puts( "Init - Message Queue created" ); puts( "Init - Unlink message queue" ); sc = mq_unlink( name ); if ( sc != 0 ) perror( "mq_unlink failed" ); rtems_test_assert( sc == 0 ); puts( "Init - Close message queue" ); sc = mq_close( second_Queue ); if ( sc != 0 ) perror( "mq_close failed" ); rtems_test_assert( sc == 0 ); puts( "*** END OF POSIX MESSAGE QUEUE TEST 4 ***" ); rtems_test_exit( 0 ); return NULL; /* just so the compiler thinks we returned something */ }