[e049eea] | 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 |
---|
[c499856] | 7 | * http://www.rtems.org/license/LICENSE. |
---|
[e049eea] | 8 | */ |
---|
| 9 | |
---|
[ff33d076] | 10 | #ifdef HAVE_CONFIG_H |
---|
| 11 | #include "config.h" |
---|
| 12 | #endif |
---|
| 13 | |
---|
[e049eea] | 14 | #include <tmacros.h> |
---|
| 15 | #include "test_support.h" |
---|
| 16 | |
---|
[ad48ebb] | 17 | const char rtems_test_name[] = "SMP 7"; |
---|
| 18 | |
---|
[e049eea] | 19 | volatile bool TaskRan = false; |
---|
| 20 | volatile bool TSRFired = false; |
---|
[24d0ee57] | 21 | rtems_id Semaphore; |
---|
[e049eea] | 22 | |
---|
[6291e962] | 23 | rtems_task Init( |
---|
| 24 | rtems_task_argument argument |
---|
| 25 | ); |
---|
| 26 | |
---|
| 27 | rtems_task Test_task( |
---|
| 28 | rtems_task_argument argument |
---|
| 29 | ); |
---|
| 30 | |
---|
[57c88056] | 31 | static void success(void) |
---|
| 32 | { |
---|
[7b00c2fa] | 33 | TEST_END( ); |
---|
[57c88056] | 34 | rtems_test_exit( 0 ); |
---|
| 35 | } |
---|
| 36 | |
---|
[e049eea] | 37 | rtems_task Test_task( |
---|
| 38 | rtems_task_argument argument |
---|
| 39 | ) |
---|
| 40 | { |
---|
[39e51758] | 41 | uint32_t cpu_num; |
---|
[e049eea] | 42 | rtems_status_code sc; |
---|
| 43 | char name[5]; |
---|
| 44 | char *p; |
---|
| 45 | |
---|
| 46 | /* Get the task name */ |
---|
| 47 | p = rtems_object_get_name( RTEMS_SELF, 5, name ); |
---|
| 48 | rtems_test_assert( p != NULL ); |
---|
| 49 | |
---|
| 50 | /* Get the CPU Number */ |
---|
[03c9f24] | 51 | cpu_num = rtems_scheduler_get_processor(); |
---|
[e049eea] | 52 | |
---|
| 53 | /* Print that the task is up and running. */ |
---|
[39e51758] | 54 | locked_printf(" CPU %" PRIu32 " runnng Task %s and blocking\n", cpu_num, name); |
---|
[e049eea] | 55 | |
---|
| 56 | sc = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
---|
| 57 | directive_failed( sc,"obtain in test task"); |
---|
| 58 | |
---|
| 59 | if ( !TSRFired ) |
---|
| 60 | locked_printf( "*** ERROR TSR DID NOT FIRE BUT TEST TASK AWAKE***" ); |
---|
| 61 | |
---|
| 62 | TaskRan = true; |
---|
| 63 | |
---|
| 64 | /* Print that the task is up and running. */ |
---|
[cf288c38] | 65 | locked_printf( |
---|
[24d0ee57] | 66 | " CPU %" PRIu32 " running Task %s after semaphore release\n", |
---|
| 67 | cpu_num, |
---|
[cf288c38] | 68 | name |
---|
| 69 | ); |
---|
[e049eea] | 70 | |
---|
[51b3cbca] | 71 | rtems_task_exit(); |
---|
[e049eea] | 72 | } |
---|
| 73 | |
---|
| 74 | |
---|
[6291e962] | 75 | static rtems_timer_service_routine TimerMethod( |
---|
[e049eea] | 76 | rtems_id timer, |
---|
| 77 | void *arg |
---|
| 78 | ) |
---|
| 79 | { |
---|
| 80 | /* |
---|
| 81 | * Set flag and release the semaphore, allowing the blocked tasks to start. |
---|
| 82 | */ |
---|
| 83 | TSRFired = true; |
---|
| 84 | |
---|
| 85 | rtems_semaphore_release( Semaphore ); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | rtems_task Init( |
---|
| 89 | rtems_task_argument argument |
---|
| 90 | ) |
---|
| 91 | { |
---|
| 92 | int cpu_num; |
---|
| 93 | rtems_id id; |
---|
| 94 | rtems_status_code status; |
---|
| 95 | rtems_interval per_second; |
---|
| 96 | rtems_interval then; |
---|
| 97 | rtems_id Timer; |
---|
| 98 | |
---|
| 99 | locked_print_initialize(); |
---|
[7b00c2fa] | 100 | TEST_BEGIN(); |
---|
[e049eea] | 101 | |
---|
[4bc8d2e] | 102 | if ( rtems_get_processor_count() == 1 ) { |
---|
[57c88056] | 103 | success(); |
---|
| 104 | } |
---|
| 105 | |
---|
[e049eea] | 106 | /* Create/verify semaphore */ |
---|
| 107 | status = rtems_semaphore_create( |
---|
| 108 | rtems_build_name ('S', 'E', 'M', '1'), |
---|
[24d0ee57] | 109 | 1, |
---|
[e049eea] | 110 | RTEMS_LOCAL | |
---|
| 111 | RTEMS_SIMPLE_BINARY_SEMAPHORE | |
---|
| 112 | RTEMS_PRIORITY, |
---|
| 113 | 1, |
---|
| 114 | &Semaphore |
---|
| 115 | ); |
---|
| 116 | directive_failed( status, "rtems_semaphore_create" ); |
---|
| 117 | |
---|
| 118 | /* Lock semaphore */ |
---|
| 119 | status = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, 0); |
---|
| 120 | directive_failed( status,"rtems_semaphore_obtain of SEM1\n"); |
---|
| 121 | |
---|
| 122 | /* Create and Start test task. */ |
---|
| 123 | status = rtems_task_create( |
---|
| 124 | rtems_build_name( 'T', 'A', '1', ' ' ), |
---|
| 125 | 1, |
---|
| 126 | RTEMS_MINIMUM_STACK_SIZE, |
---|
| 127 | RTEMS_DEFAULT_MODES, |
---|
| 128 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
| 129 | &id |
---|
| 130 | ); |
---|
| 131 | directive_failed( status, "task create" ); |
---|
| 132 | |
---|
[03c9f24] | 133 | cpu_num = rtems_scheduler_get_processor(); |
---|
[e049eea] | 134 | locked_printf(" CPU %d start task TA1\n", cpu_num ); |
---|
| 135 | status = rtems_task_start( id, Test_task, 1 ); |
---|
| 136 | directive_failed( status, "task start" ); |
---|
| 137 | |
---|
| 138 | /* Create and start TSR */ |
---|
| 139 | locked_printf(" CPU %d create and start timer\n", cpu_num ); |
---|
| 140 | status = rtems_timer_create( rtems_build_name( 'T', 'M', 'R', '1' ), &Timer); |
---|
| 141 | directive_failed( status, "rtems_timer_create" ); |
---|
| 142 | |
---|
| 143 | per_second = rtems_clock_get_ticks_per_second(); |
---|
| 144 | status = rtems_timer_fire_after( Timer, 2 * per_second, TimerMethod, NULL ); |
---|
| 145 | directive_failed( status, "rtems_timer_fire_after"); |
---|
| 146 | |
---|
| 147 | /* |
---|
| 148 | * Wait long enough that TSR should have fired. |
---|
| 149 | * |
---|
| 150 | * Spin so CPU 0 is consumed. This forces task to run on CPU 1. |
---|
| 151 | */ |
---|
| 152 | then = rtems_clock_get_ticks_since_boot() + 4 * per_second; |
---|
| 153 | while (1) { |
---|
| 154 | if ( rtems_clock_get_ticks_since_boot() > then ) |
---|
| 155 | break; |
---|
| 156 | if ( TSRFired && TaskRan ) |
---|
| 157 | break; |
---|
| 158 | }; |
---|
[24d0ee57] | 159 | |
---|
[e049eea] | 160 | /* Validate the timer fired and that the task ran */ |
---|
| 161 | if ( !TSRFired ) |
---|
| 162 | locked_printf( "*** ERROR TSR DID NOT FIRE ***" ); |
---|
| 163 | |
---|
| 164 | if ( !TaskRan ) { |
---|
| 165 | locked_printf( "*** ERROR TASK DID NOT RUN ***" ); |
---|
| 166 | rtems_test_exit(0); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | /* End the program */ |
---|
[57c88056] | 170 | success(); |
---|
[e049eea] | 171 | } |
---|
| 172 | |
---|
| 173 | /* configuration information */ |
---|
| 174 | |
---|
[c4b8b147] | 175 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
[e049eea] | 176 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 177 | |
---|
[54835ae] | 178 | #define CONFIGURE_MAXIMUM_PROCESSORS 2 |
---|
[e049eea] | 179 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
| 180 | |
---|
| 181 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
[ad48ebb] | 182 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
| 183 | |
---|
[e049eea] | 184 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
[db0cede1] | 185 | #define CONFIGURE_MAXIMUM_SEMAPHORES 2 |
---|
[e049eea] | 186 | |
---|
| 187 | #define CONFIGURE_INIT |
---|
| 188 | |
---|
| 189 | #include <rtems/confdefs.h> |
---|
| 190 | /* end of file */ |
---|