void doTest(void) { rtems_status_code sc; int pass, i; sc = rtems_semaphore_create( rtems_build_name('S', 'E', 'M', 'F'), 0, TEST_SEMAPHORE_ATTRIBUTES, 0, &semaphore); directive_failed( sc, "semaphore create" ); for (i = 0 ; i < NTASK ; i++) flags[i] = 0; for (i = 0 ; i < NTASK ; i++) starttask(i); for (pass = 1 ; pass < 10 ; pass++) { rtems_task_wake_after(1); for (i = 0 ; i < NTASK ; i++) { if (flags[i] != pass) printf("flags[%d] = %d -- expected %d\n", i, flags[i], pass); } sc = rtems_semaphore_flush(semaphore); directive_failed( sc, "semaphore flush" ); } printf("Flushed all waiting tasks\n" ); }
static void graes_stop(struct graes_priv *pDev) { struct graes_regs *regs = pDev->regs; /* Disable the transmitter & Interrupts */ regs->dma_ctrl = 0; DBG("GRAES: STOPPED\n"); /* Flush semaphore in case a thread is stuck waiting for TX Interrupts */ rtems_semaphore_flush(pDev->sem_rx); }
static void grtm_stop(struct grtm_priv *pDev) { struct grtm_regs *regs = pDev->regs; /* Disable the transmitter & Interrupts */ WRITE_REG(pDev, ®s->dma_ctrl, 0); /* Clear any pending interrupt */ WRITE_REG(pDev, ®s->dma_status, GRTM_DMA_STS_ALL); DBG("GRTM: STOPPED\n"); /* Flush semaphore in case a thread is stuck waiting for TX Interrupts */ rtems_semaphore_flush(pDev->sem_tx); }
rtems_task Secondary_task( rtems_task_argument arg ) { if ( arg ) (void) rtems_semaphore_flush( Semaphore ); (void) rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT ); rtems_test_assert(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); }
void Screen5() { rtems_status_code status; /* invalid name */ status = rtems_semaphore_create( 0, 1, RTEMS_DEFAULT_ATTRIBUTES, RTEMS_NO_PRIORITY, &Junk_id ); fatal_directive_status( status, RTEMS_INVALID_NAME, "rtems_semaphore_create with illegal name" ); puts( "TA1 - rtems_semaphore_create - RTEMS_INVALID_NAME" ); /* NULL Id parameter */ status = rtems_semaphore_create( Semaphore_name[ 1 ], 1, RTEMS_DEFAULT_ATTRIBUTES, RTEMS_NO_PRIORITY, NULL ); fatal_directive_status( status, RTEMS_INVALID_ADDRESS, "rtems_semaphore_create with NULL param" ); puts( "TA1 - rtems_semaphore_create - RTEMS_INVALID_ADDRESS" ); /* OK */ status = rtems_semaphore_create( Semaphore_name[ 1 ], 1, RTEMS_DEFAULT_ATTRIBUTES, RTEMS_NO_PRIORITY, &Semaphore_id[ 1 ] ); directive_failed( status, "rtems_semaphore_create" ); puts( "TA1 - rtems_semaphore_create - 1 - RTEMS_SUCCESSFUL" ); status = rtems_semaphore_create( Semaphore_name[ 2 ], 1, RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY, RTEMS_NO_PRIORITY, &Semaphore_id[ 2 ] ); directive_failed( status, "rtems_semaphore_create" ); puts( "TA1 - rtems_semaphore_create - 2 - RTEMS_SUCCESSFUL" ); do { status = rtems_semaphore_create( Semaphore_name[ 3 ], 1, RTEMS_DEFAULT_ATTRIBUTES, RTEMS_NO_PRIORITY, &Junk_id ); } while (status == RTEMS_SUCCESSFUL); fatal_directive_status( status, RTEMS_TOO_MANY, "rtems_semaphore_create of too many" ); puts( "TA1 - rtems_semaphore_create - 3 - RTEMS_TOO_MANY" ); status = rtems_semaphore_create( Semaphore_name[ 1 ], 1, RTEMS_INHERIT_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_FIFO, RTEMS_NO_PRIORITY, &Junk_id ); fatal_directive_status( status, RTEMS_NOT_DEFINED, "rtems_semaphore_create of RTEMS_FIFO RTEMS_INHERIT_PRIORITY" ); puts( "TA1 - rtems_semaphore_create - FIFO and inherit - RTEMS_NOT_DEFINED" ); status = rtems_semaphore_create( Semaphore_name[ 1 ], 1, RTEMS_PRIORITY_CEILING | RTEMS_BINARY_SEMAPHORE | RTEMS_FIFO, RTEMS_NO_PRIORITY, &Junk_id ); fatal_directive_status( status, RTEMS_NOT_DEFINED, "rtems_semaphore_create of RTEMS_FIFO RTEMS_CEILING_PRIORITY" ); puts( "TA1 - rtems_semaphore_create - FIFO and ceiling - RTEMS_NOT_DEFINED" ); status = rtems_semaphore_create( Semaphore_name[ 1 ], 1, RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY_CEILING | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY, 10, &Junk_id ); fatal_directive_status( status, RTEMS_NOT_DEFINED, "rtems_semaphore_create of binary with ceiling and inherit" ); puts( "TA1 - rtems_semaphore_create - ceiling and inherit - RTEMS_NOT_DEFINED" ); status = rtems_semaphore_create( Semaphore_name[ 1 ], 1, RTEMS_INHERIT_PRIORITY | RTEMS_COUNTING_SEMAPHORE | RTEMS_PRIORITY, RTEMS_NO_PRIORITY, &Junk_id ); fatal_directive_status( status, RTEMS_NOT_DEFINED, "rtems_semaphore_create of RTEMS_COUNTING_SEMAPHORE RTEMS_INHERIT_PRIORITY" ); puts( "TA1 - rtems_semaphore_create - RTEMS_NOT_DEFINED" ); status = rtems_semaphore_create( Semaphore_name[ 1 ], 2, RTEMS_BINARY_SEMAPHORE, RTEMS_NO_PRIORITY, &Junk_id ); fatal_directive_status( status, RTEMS_INVALID_NUMBER, "rtems_semaphore_create of binary semaphore with count > 1" ); puts( "TA1 - rtems_semaphore_create - RTEMS_INVALID_NUMBER" ); /* * The check for an object being global is only made if * multiprocessing is enabled. */ #if defined(RTEMS_MULTIPROCESSING) status = rtems_semaphore_create( Semaphore_name[ 3 ], 1, RTEMS_GLOBAL, RTEMS_NO_PRIORITY, &Junk_id ); fatal_directive_status( status, RTEMS_MP_NOT_CONFIGURED, "rtems_semaphore_create of mp not configured" ); #endif puts( "TA1 - rtems_semaphore_create - RTEMS_MP_NOT_CONFIGURED" ); status = rtems_semaphore_delete( 100 ); fatal_directive_status( status, RTEMS_INVALID_ID, "rtems_semaphore_delete with illegal id" ); puts( "TA1 - rtems_semaphore_delete - RTEMS_INVALID_ID" ); status = rtems_semaphore_delete( rtems_build_id( 1, 0, 0, 0 ) ); fatal_directive_status( status, RTEMS_INVALID_ID, "rtems_semaphore_delete with local illegal id" ); puts( "TA1 - rtems_semaphore_delete - local RTEMS_INVALID_ID" ); status = rtems_semaphore_ident( 100, RTEMS_SEARCH_ALL_NODES, &Junk_id ); fatal_directive_status( status, RTEMS_INVALID_NAME, "rtems_semaphore_ident will illegal name (local)" ); puts( "TA1 - rtems_semaphore_ident - global RTEMS_INVALID_NAME" ); status = rtems_semaphore_ident( 100, 1, &Junk_id ); fatal_directive_status( status, RTEMS_INVALID_NAME, "rtems_semaphore_ident will illegal name (global)" ); puts( "TA1 - rtems_semaphore_ident - local RTEMS_INVALID_NAME" ); status = rtems_semaphore_release( 100 ); fatal_directive_status( status, RTEMS_INVALID_ID, "rtems_semaphore_release with illegal id" ); puts( "TA1 - rtems_semaphore_release - RTEMS_INVALID_ID" ); status = rtems_semaphore_flush( 100 ); fatal_directive_status( status, RTEMS_INVALID_ID, "rtems_semaphore_flush with illegal id" ); puts( "TA1 - rtems_semaphore_flush - RTEMS_INVALID_ID" ); }