rtems_task Init(rtems_task_argument ignored) { pthread_key_t key1; pthread_key_t key2; int eno; bool ok; rtems_resource_snapshot snapshot; void *greedy; void *value; TEST_BEGIN(); greedy = rtems_workspace_greedy_allocate( NULL, 0 ); rtems_resource_snapshot_take( &snapshot ); puts( "Init - pthread_key_create - OK" ); eno = pthread_key_create( &key1, NULL ); rtems_test_assert( eno == 0 ); eno = pthread_setspecific( key1, (void *) 1 ); rtems_test_assert( eno == 0 ); value = pthread_getspecific( key1 ); rtems_test_assert( value == (void *) 1 ); eno = pthread_setspecific( key1, NULL ); rtems_test_assert( eno == 0 ); value = pthread_getspecific( key1 ); rtems_test_assert( value == NULL ); eno = pthread_setspecific( key1, NULL ); rtems_test_assert( eno == 0 ); value = pthread_getspecific( key1 ); rtems_test_assert( value == NULL ); puts( "Init - pthread_key_create - EAGAIN" ); eno = pthread_key_create( &key2, NULL ); rtems_test_assert( eno == EAGAIN ); puts( "Init - pthread_key_delete - OK" ); eno = pthread_key_delete( key1 ); rtems_test_assert( eno == 0 ); 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); }
static void no_mem_task(rtems_task_argument arg) { const no_mem_test *self = (const no_mem_test *) arg; rtems_status_code sc; void *greedy; assert(rtems_configuration_get_unified_work_area()); greedy = rtems_workspace_greedy_allocate(NULL, 0); (*self->body)(self->fd); rtems_workspace_greedy_free(greedy); sc = rtems_event_transient_send(self->master_task); assert(sc == RTEMS_SUCCESSFUL); sc = rtems_task_suspend(RTEMS_SELF); assert(sc == RTEMS_SUCCESSFUL); }
rtems_task Init( rtems_task_argument argument ) { rtems_status_code sc; void *opaque; rtems_id current_task_id; rtems_id task_id; rtems_name another_task_name; Heap_Information_block Info; puts( "\n\n*** TEST USER ENVIRONMENT ROUTINE - 01 ***" ); puts( "Init - allocating most of heap -- OK" ); opaque = rtems_heap_greedy_allocate( 0 ); puts( "Init - attempt to reset env - expect RTEMS_NO_MEMORY" ); sc = rtems_libio_set_private_env(); rtems_test_assert( sc == RTEMS_NO_MEMORY ); puts( "Init - freeing the allocated memory" ); rtems_heap_greedy_free( opaque ); puts( "Init - allocating most of workspace memory" ); opaque = rtems_workspace_greedy_allocate( 0 ); puts( "Init - attempt to reset env - expect RTEMS_TOO_MANY" ); sc = rtems_libio_set_private_env(); rtems_test_assert( sc == RTEMS_TOO_MANY ); puts( "Init - freeing the workspace memory" ); rtems_workspace_greedy_free( opaque ); puts( "Init - creating a task name and a task -- OK" ); another_task_name = rtems_build_name( 'T','S','K','D' ); sc = rtems_task_create( another_task_name, 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_INTERRUPT_LEVEL(31), RTEMS_DEFAULT_ATTRIBUTES, &task_id ); puts( "Init - starting the task_routine, to set its private environment" ); sc = rtems_task_start( task_id, task_routine, 0); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); puts( "Init - attempt to share the env with another task -- Expect error" ); sc = rtems_libio_share_private_env( task_id ); rtems_test_assert( sc == RTEMS_UNSATISFIED ); sleep( 1 ); puts( "Init - attempt to share the env with another task -- OK" ); sc = rtems_libio_share_private_env( task_id ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); rtems_test_assert( rtems_current_user_env->task_id == task_id ); puts( "Init - Get current task id" ); current_task_id = rtems_task_self(); puts( "Init - Attempt to reset current task's environment" ); sc = rtems_libio_set_private_env(); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); rtems_test_assert( rtems_current_user_env->task_id == current_task_id ); puts( "Init - attempt to share the env with another task -- OK" ); sc = rtems_libio_share_private_env( task_id ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); rtems_test_assert( rtems_current_user_env->task_id == task_id ); puts( "Init - attempt to share with self -- OK" ); sc = rtems_libio_share_private_env( task_id ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); puts( "*** END OF TEST USER ENVIRONMENT ROUTINE - 01 ***" ); rtems_test_exit(0); }
rtems_task Init(rtems_task_argument argument) { rtems_status_code rc; int sc; struct timespec delay_request; uintptr_t max_free_size = 13 * RTEMS_MINIMUM_STACK_SIZE; void *greedy; all_thread_created = 0; TEST_BEGIN(); puts( "Init - Mutex 1 create - OK" ); sc = pthread_mutex_init( &mutex1, NULL ); rtems_test_assert( !sc ); puts( "Init - Mutex 2 create - OK" ); sc = pthread_mutex_init( &mutex2, NULL ); rtems_test_assert( !sc ); puts( "Init - Condition variable 1 create - OK" ); sc = pthread_cond_init( &create_condition_var, NULL ); rtems_test_assert( !sc ); puts( "Init - Condition variable 2 create - OK" ); sc = pthread_cond_init( &set_condition_var, NULL ); rtems_test_assert( !sc ); puts( "Init - pthread Key create - OK" ); sc = pthread_key_create( &Key, NULL ); rtems_test_assert( !sc ); /* Reduce workspace size if necessary to shorten test time */ greedy = rtems_workspace_greedy_allocate( &max_free_size, 1 ); for ( ; ; ) { rtems_id task_id; pthread_mutex_lock( &mutex1 ); rc = rtems_task_create( rtems_build_name( 'T', 'E', 'S', 'T' ), 1, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &task_id ); rtems_test_assert( ( rc == RTEMS_SUCCESSFUL ) || ( rc == RTEMS_UNSATISFIED ) || ( rc == RTEMS_TOO_MANY ) ); if ( rc == RTEMS_SUCCESSFUL ) { rc = rtems_task_start( task_id, Test_Thread, 0 ); rtems_test_assert( rc == RTEMS_SUCCESSFUL ); } /** * check if return is not successful, it means RTEMS Workspace RAM * have been exhausted. */ if ( rc != RTEMS_SUCCESSFUL ) { pthread_mutex_unlock( &mutex1 ); break; } ++created_thread_count; /** * wait for test thread set key, the while loop here is used to * avoid suprious wakeup. */ while( created_thread_count > setted_thread_count ) pthread_cond_wait( &set_condition_var, &mutex1 ); pthread_mutex_unlock( &mutex1 ); } rtems_workspace_greedy_free( greedy ); printf( "Init - %d pthreads have been created - OK\n" "Init - %d pthreads have been setted key data - OK\n", created_thread_count, setted_thread_count ); rtems_test_assert( created_thread_count == setted_thread_count ); /* unblock all created pthread to let them set key data.*/ pthread_mutex_lock( &mutex2 ); all_thread_created = 1; pthread_cond_broadcast( &create_condition_var ); pthread_mutex_unlock( &mutex2 ); puts( "Init - sleep - let threads run - OK" ); delay_request.tv_sec = 0; delay_request.tv_nsec = 8 * 100000000; sc = nanosleep( &delay_request, NULL ); rtems_test_assert( !sc ); printf( "Init - %d pthreads have been got key data - OK\n", got_thread_count ); rtems_test_assert( created_thread_count == got_thread_count ); puts( "Init - pthread Key delete - OK" ); sc = pthread_key_delete( Key ); rtems_test_assert( sc == 0 ); puts( "Init - Mutex1 delete - OK" ); sc = pthread_mutex_destroy( &mutex1 ); rtems_test_assert( !sc ); puts( "Init - Mutex2 delete - OK" ); sc = pthread_mutex_destroy( &mutex2 ); rtems_test_assert( !sc ); puts( "Init - Condition variable 1 delete - OK" ); sc = pthread_cond_destroy( &create_condition_var ); rtems_test_assert( !sc ); puts( "Init - Condition variable 2 delete - OK" ); sc = pthread_cond_destroy( &set_condition_var ); rtems_test_assert( !sc ); TEST_END(); rtems_test_exit(0); }
rtems_task Init(rtems_task_argument arg) { rtems_status_code status; int sc; uintptr_t max_free_size = 13 * RTEMS_MINIMUM_STACK_SIZE; void *greedy; all_thread_created = 0; TEST_BEGIN(); puts( "Init - Semaphore 1 create - OK" ); name1 = rtems_build_name('S', 'E', 'M', '1'); sc = rtems_semaphore_create( name1, 0, RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_FIFO, 0, &sema1 ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); puts( "Init - Semaphore 2 create - OK" ); name2 = rtems_build_name('S', 'E', 'M', '2'); sc = rtems_semaphore_create( name2, 0, RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_FIFO, 0, &sema2 ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); puts( "Init - pthread Key create - OK" ); sc = pthread_key_create( &Key, NULL ); rtems_test_assert( !sc ); /* Reduce workspace size if necessary to shorten test time */ greedy = rtems_workspace_greedy_allocate( &max_free_size, 1 ); for ( ; ; ) { rtems_id task_id; sc = rtems_task_create( rtems_build_name('T','A',created_task_count, ' '), 1, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &task_id ); rtems_test_assert( (sc == RTEMS_UNSATISFIED) || (sc == RTEMS_TOO_MANY) || (sc == RTEMS_SUCCESSFUL) ); /** * when return is RTEMS_TOO_MANY or RTEMS_UNSATISFIED, there is not * enough source to create task. */ if ( (sc == RTEMS_TOO_MANY) || (sc == RTEMS_UNSATISFIED) ) { break; } ++created_task_count; sc = rtems_task_start( task_id, test_task, 0 ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); sc = rtems_semaphore_obtain( sema1, RTEMS_WAIT, 0 ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); } rtems_workspace_greedy_free( greedy ); printf( "Init - %d tasks have been created - OK\n" "Init - %d tasks have been setted key data - OK\n", setted_task_count, created_task_count ); rtems_test_assert( created_task_count == setted_task_count ); /* unblock all created tasks to let them set key data.*/ puts( "Init - flush semaphore 2 - OK" ); sc = rtems_semaphore_flush( sema2 ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); puts( "Init - sleep to yield processor - OK" ); status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); directive_failed( status, "rtems_task_wake_after" ); printf( "Init - %d Tasks have been got key data - OK\n", got_task_count ); rtems_test_assert( created_task_count == got_task_count ); puts( "Init - pthread Key delete - OK" ); sc = pthread_key_delete( Key ); rtems_test_assert( sc == 0 ); puts( "Init - semaphore 1 delete - OK" ); sc = rtems_semaphore_delete( sema1 ); rtems_test_assert( !sc ); puts( "Init - semaphore 2 delete - OK" ); sc = rtems_semaphore_delete( sema2 ); rtems_test_assert( !sc ); TEST_END(); exit(0); }
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); }