rtems_task Init( rtems_task_argument argument ) { void *p1; bool retbool; Heap_Information_block info; puts( "\n\n*** TEST WORKSPACE CLASSIC API ***" ); puts( "rtems_workspace_get_information - null pointer" ); retbool = rtems_workspace_get_information( NULL ); rtems_test_assert( retbool == false ); puts( "rtems_workspace_get_information - OK" ); retbool = rtems_workspace_get_information( &info ); rtems_test_assert( retbool == true ); puts( "rtems_workspace_allocate - null pointer" ); retbool = rtems_workspace_allocate( 42, NULL ); rtems_test_assert( retbool == false ); puts( "rtems_workspace_allocate - 0 bytes" ); retbool = rtems_workspace_allocate( 0, &p1 ); rtems_test_assert( retbool == false ); puts( "rtems_workspace_allocate - too many bytes" ); retbool = rtems_workspace_allocate( info.Free.largest * 2, &p1 ); rtems_test_assert( retbool == false ); puts( "rtems_workspace_allocate - 42 bytes" ); retbool = rtems_workspace_allocate( 42, &p1 ); rtems_test_assert( retbool == true ); rtems_test_assert( p1 != NULL ); puts( "rtems_workspace_free - NULL" ); retbool = rtems_workspace_free( NULL ); rtems_test_assert( retbool == false ); puts( "rtems_workspace_free - previous pointer to 42 bytes" ); retbool = rtems_workspace_free( p1 ); rtems_test_assert( retbool == true ); puts( "*** END OF TEST WORKSPACE CLASSIC API ***" ); rtems_test_exit( 0 ); }
void *POSIX_Init( void *ignored ) { pthread_key_t key; int sc; bool sb; Heap_Information_block start; Heap_Information_block info; size_t to_alloc; void *alloced; puts( "\n\n*** TEST KEY 02 ***" ); puts( "Init - rtems_workspace_get_information - OK" ); sb = rtems_workspace_get_information( &start ); rtems_test_assert( sb ); #if 0 printf( "Init - workspace free = %d\n", start.Free.largest ); printf( "Init - workspace free blocks = %d\n", start.Free.number ); #endif 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 ); #if 0 printf( "Init - start with to_alloc of = %d\n", to_alloc ); #endif /* * Verify heap is still in same shape if we couldn't allocate a task */ sb = rtems_workspace_get_information( &info ); rtems_test_assert( sb ); rtems_test_assert( info.Free.largest == start.Free.largest ); rtems_test_assert( info.Free.number == start.Free.number ); puts( "Init - pthread_key_create - ENOMEM" ); while (1) { sb = rtems_workspace_allocate( to_alloc, &alloced ); rtems_test_assert( sb ); sc = pthread_key_create( &key, NULL ); /* free the memory we snagged, then check the status */ rtems_workspace_free( alloced ); if ( !sc ) break; if ( sc != ENOMEM ) { printf( "key create returned %s\n", strerror(sc) ); rtems_test_exit(0); } /* * Verify heap is still in same shape if we couldn't allocate a task */ sb = rtems_workspace_get_information( &info ); #if 0 printf( "Init - workspace free/blocks = %d/%d\n", info.Free.largest, info.Free.number ); #endif rtems_test_assert( sb ); rtems_test_assert( info.Free.largest == start.Free.largest ); rtems_test_assert( info.Free.number == start.Free.number ); to_alloc -= 8; if ( to_alloc == 0 ) break; } if ( sc ) rtems_test_exit(0); /* * Verify heap is still in same shape after we free the task */ puts( "Init - pthread_key_delete - OK" ); sc = pthread_key_delete( key ); rtems_test_assert( sc == 0 ); puts( "Init - verify workspace has same memory" ); sb = rtems_workspace_get_information( &info ); #if 0 printf( "Init - workspace free/blocks = %d/%d\n", info.Free.largest, info.Free.number ); #endif rtems_test_assert( sb ); rtems_test_assert( info.Free.largest == start.Free.largest ); rtems_test_assert( info.Free.number == start.Free.number ); puts( "*** END OF TEST KEY 02 ***" ); rtems_test_exit(0); }
rtems_task Init( rtems_task_argument ignored ) { rtems_id region1; rtems_id region2; rtems_status_code sc; bool sb; Heap_Information_block start; Heap_Information_block info; size_t to_alloc; void *alloced; puts( "\n\n*** TEST 64 ***" ); puts( "Allocate one region -- so second auto extends" ); sc = rtems_region_create( rtems_build_name( 'R', 'N', '1', ' ' ), Area1, sizeof(Area1), 8, RTEMS_DEFAULT_ATTRIBUTES, ®ion1 ); directive_failed( sc, "rtems_region_create of RN1" ); puts( "Init - rtems_workspace_get_information - OK" ); sb = rtems_workspace_get_information( &start ); rtems_test_assert( sb ); #if 0 printf( "Init - workspace free = %d\n", start.Free.largest ); printf( "Init - workspace free blocks = %d\n", start.Free.number ); #endif 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 ); #if 0 printf( "Init - start with to_alloc of = %d\n", to_alloc ); #endif /* * Verify heap is still in same shape if we couldn't allocate a region */ sb = rtems_workspace_get_information( &info ); rtems_test_assert( sb ); rtems_test_assert( info.Free.largest == start.Free.largest ); rtems_test_assert( info.Free.number == start.Free.number ); puts( "Init - rtems_region_create - auto-extend - RTEMS_UNSATISFIED" ); while (1) { sb = rtems_workspace_allocate( to_alloc, &alloced ); rtems_test_assert( sb ); sc = rtems_region_create( rtems_build_name( 'R', 'N', '2', ' ' ), Area2, sizeof(Area2), 8, RTEMS_DEFAULT_ATTRIBUTES, ®ion2 ); /* free the memory we snagged, then check the status */ rtems_workspace_free( alloced ); if ( sc == RTEMS_SUCCESSFUL ) break; if ( sc != RTEMS_TOO_MANY ) { printf( "region create returned %d or %s\n", sc, rtems_status_text(sc) ); rtems_test_exit(0); } /* * Verify heap is still in same shape if we couldn't allocate a region */ sb = rtems_workspace_get_information( &info ); #if 0 printf( "Init - workspace free/blocks = %d/%d\n", info.Free.largest, info.Free.number ); #endif rtems_test_assert( sb ); rtems_test_assert( info.Free.largest == start.Free.largest ); rtems_test_assert( info.Free.number == start.Free.number ); to_alloc -= 8; if ( to_alloc == 0 ) break; } if ( sc ) rtems_test_exit(0); /* * Verify heap is still in same shape after we free the region */ puts( "Init - rtems_region_delete - OK" ); sc = rtems_region_delete( region2 ); rtems_test_assert( sc == 0 ); /* * Although it is intuitive that after deleting the region the * object space would shrink and go back to its original shape, * we could end up with fragmentation which prevents a simple * check from verifying this. */ #if 0 puts( "Init - verify workspace has same memory" ); sb = rtems_workspace_get_information( &info ); #if 0 printf( "Init - workspace free/blocks = %d/%d\n", info.Free.largest, info.Free.number ); #endif rtems_test_assert( sb ); rtems_test_assert( info.Free.largest == start.Free.largest ); rtems_test_assert( info.Free.number == start.Free.number ); #endif puts( "*** END OF TEST 64 ***" ); rtems_test_exit(0); }
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 */ }
rtems_task Init( rtems_task_argument ignored ) { rtems_id region1; rtems_id region2; rtems_status_code sc; bool ok; uintptr_t to_alloc; void *alloced; rtems_resource_snapshot snapshot; void *greedy; TEST_BEGIN(); puts( "Allocate one region -- so second auto extends" ); sc = rtems_region_create( rtems_build_name( 'R', 'N', '1', ' ' ), Area1, sizeof(Area1), 8, RTEMS_DEFAULT_ATTRIBUTES, ®ion1 ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); greedy = rtems_workspace_greedy_allocate_all_except_largest( &to_alloc ); rtems_resource_snapshot_take( &snapshot ); puts( "Init - rtems_region_create - auto-extend - RTEMS_UNSATISFIED" ); while ( to_alloc > 8 ) { ok = rtems_workspace_allocate( to_alloc, &alloced ); rtems_test_assert( ok ); sc = rtems_region_create( rtems_build_name( 'R', 'N', '2', ' ' ), Area2, sizeof(Area2), 8, RTEMS_DEFAULT_ATTRIBUTES, ®ion2 ); rtems_workspace_free( alloced ); if ( sc == RTEMS_SUCCESSFUL ) break; rtems_test_assert( sc == RTEMS_TOO_MANY ); /* * Verify heap is still in same shape if we couldn't allocate a region */ ok = rtems_resource_snapshot_check( &snapshot ); rtems_test_assert( ok ); to_alloc -= 8; } rtems_test_assert( sc == RTEMS_SUCCESSFUL ); /* * Verify heap is still in same shape after we free the region */ puts( "Init - rtems_region_delete - OK" ); sc = rtems_region_delete( region2 ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); puts( "Init - verify workspace has same memory" ); ok = rtems_resource_snapshot_check( &snapshot ); rtems_test_assert( ok ); rtems_workspace_greedy_free( greedy ); TEST_END(); rtems_test_exit(0); }