[9688b8fd] | 1 | /* |
---|
| 2 | * COPYRIGHT (c) 1989-2011. |
---|
| 3 | * On-Line Applications Research Corporation (OAR). |
---|
| 4 | * |
---|
| 5 | * The license and distribution terms for this file may be |
---|
| 6 | * found in the file LICENSE in this distribution or at |
---|
| 7 | * http://www.rtems.com/license/LICENSE. |
---|
| 8 | * |
---|
| 9 | * $Id$ |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | #include <errno.h> |
---|
| 13 | #include <fcntl.h> |
---|
| 14 | #include <semaphore.h> |
---|
| 15 | #include <tmacros.h> |
---|
| 16 | #include <timesys.h> |
---|
| 17 | #include <rtems/timerdrv.h> |
---|
| 18 | #include "test_support.h" |
---|
| 19 | #include <pthread.h> |
---|
| 20 | #include <sched.h> |
---|
| 21 | |
---|
| 22 | #define MAX_SEMS 2 |
---|
| 23 | |
---|
| 24 | sem_t sem1; |
---|
| 25 | |
---|
| 26 | void *Low( |
---|
| 27 | void *argument |
---|
| 28 | ) |
---|
| 29 | { |
---|
| 30 | long end_time; |
---|
| 31 | |
---|
| 32 | /* |
---|
| 33 | * Now we have finished the thread startup overhead, |
---|
| 34 | * so let other threads run. When we return, we can |
---|
| 35 | * finish the benchmark. |
---|
| 36 | */ |
---|
| 37 | sched_yield(); |
---|
| 38 | /* let other threads run */ |
---|
| 39 | |
---|
| 40 | end_time = benchmark_timer_read(); |
---|
| 41 | |
---|
| 42 | put_time( |
---|
| 43 | "sem_wait - not available, block", |
---|
| 44 | end_time, |
---|
| 45 | OPERATION_COUNT, |
---|
| 46 | 0, |
---|
| 47 | 0 |
---|
| 48 | ); |
---|
| 49 | |
---|
| 50 | puts( "*** END OF POSIX TIME TEST PSXTMSEM03 ***" ); |
---|
| 51 | |
---|
| 52 | rtems_test_exit( 0 ); |
---|
| 53 | return NULL; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | void *Middle( |
---|
| 57 | void *argument |
---|
| 58 | ) |
---|
| 59 | { |
---|
| 60 | /* |
---|
| 61 | * Now we have finished the thread startup overhead, |
---|
| 62 | * so let other threads run. When we return, we can |
---|
| 63 | * finish the benchmark. |
---|
| 64 | */ |
---|
| 65 | sched_yield(); |
---|
| 66 | /* let other threads run */ |
---|
| 67 | |
---|
| 68 | (void) sem_wait( &sem1 ); |
---|
| 69 | rtems_test_assert( FALSE ); |
---|
| 70 | return NULL; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void *POSIX_Init( |
---|
| 74 | void *argument |
---|
| 75 | ) |
---|
| 76 | { |
---|
| 77 | int i; |
---|
| 78 | int status; |
---|
| 79 | pthread_t threadId; |
---|
| 80 | |
---|
| 81 | puts( "\n\n*** POSIX TIME TEST PSXTMSEM03 ***" ); |
---|
| 82 | |
---|
| 83 | for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) { |
---|
| 84 | status = pthread_create( &threadId, NULL, Middle, NULL ); |
---|
| 85 | rtems_test_assert( status == 0 ); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | status = pthread_create( &threadId, NULL, Low, NULL ); |
---|
| 89 | rtems_test_assert( status == 0 ); |
---|
| 90 | |
---|
| 91 | /* |
---|
| 92 | * Deliberately create the semaphore after the threads. This way if the |
---|
| 93 | * threads do run before we intend, they will get an error. |
---|
| 94 | */ |
---|
| 95 | status = sem_init( &sem1, 0, 1 ); |
---|
| 96 | rtems_test_assert( status == 0 ); |
---|
| 97 | |
---|
| 98 | /* |
---|
| 99 | * Let the other threads start so the thread startup overhead, |
---|
| 100 | * is accounted for. When we return, we can start the benchmark. |
---|
| 101 | */ |
---|
| 102 | sched_yield(); |
---|
| 103 | /* let other threads run */ |
---|
| 104 | |
---|
| 105 | /* start the timer and switch through all the other tasks */ |
---|
| 106 | benchmark_timer_initialize(); |
---|
| 107 | status = sem_wait(&sem1); |
---|
| 108 | rtems_test_assert( status == 0 ); |
---|
| 109 | return NULL; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | /* configuration information */ |
---|
| 113 | |
---|
| 114 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 115 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
| 116 | |
---|
| 117 | #define CONFIGURE_MAXIMUM_POSIX_THREADS OPERATION_COUNT + 2 |
---|
| 118 | #define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES MAX_SEMS |
---|
| 119 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
| 120 | |
---|
| 121 | #define CONFIGURE_INIT |
---|
| 122 | |
---|
| 123 | #include <rtems/confdefs.h> |
---|
| 124 | /* end of file */ |
---|