[3c8eda7] | 1 | /* |
---|
[5bbc204] | 2 | * COPYRIGHT (c) 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. |
---|
[5bbc204] | 8 | */ |
---|
| 9 | |
---|
| 10 | #ifdef HAVE_CONFIG_H |
---|
| 11 | #include "config.h" |
---|
| 12 | #endif |
---|
| 13 | |
---|
| 14 | #include <tmacros.h> |
---|
| 15 | |
---|
[5618c37a] | 16 | #include <rtems/score/threadimpl.h> |
---|
| 17 | |
---|
[6c0301d] | 18 | const char rtems_test_name[] = "SPSIMPLESCHED 2"; |
---|
| 19 | |
---|
[3c8eda7] | 20 | /* forward declarations to avoid warnings */ |
---|
| 21 | rtems_task Init(rtems_task_argument argument); |
---|
| 22 | rtems_task Test_task(rtems_task_argument argument); |
---|
| 23 | void ObtainRelease(bool suspendIdle); |
---|
| 24 | |
---|
[5bbc204] | 25 | /* |
---|
| 26 | * Keep the names and IDs in global variables so another task can use them. |
---|
| 27 | */ |
---|
[e3be6915] | 28 | rtems_id Idle_id; |
---|
[5bbc204] | 29 | rtems_id Task_id[ 3 ]; /* array of task ids */ |
---|
| 30 | rtems_name Task_name[ 3 ]; /* array of task names */ |
---|
| 31 | rtems_name Semaphore_name[ 2 ]; |
---|
| 32 | rtems_id Semaphore_id[ 2 ]; |
---|
| 33 | |
---|
| 34 | rtems_task Test_task( |
---|
| 35 | rtems_task_argument unused |
---|
| 36 | ) |
---|
| 37 | { |
---|
| 38 | rtems_id tid; |
---|
| 39 | rtems_status_code status; |
---|
| 40 | |
---|
| 41 | status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); |
---|
[c0d7e23] | 42 | directive_failed( status, "wake after" ); |
---|
[5bbc204] | 43 | |
---|
| 44 | for ( ; ; ) { |
---|
[c0d7e23] | 45 | status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
| 46 | directive_failed( status, "yield" ); |
---|
[5bbc204] | 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
[3c8eda7] | 50 | void ObtainRelease( bool suspendIdle ) |
---|
[5bbc204] | 51 | { |
---|
| 52 | rtems_status_code status; |
---|
| 53 | |
---|
| 54 | if (suspendIdle) { |
---|
| 55 | puts( "INIT - Suspend Idle Task"); |
---|
[e3be6915] | 56 | status = rtems_task_suspend( Idle_id ); |
---|
[5bbc204] | 57 | directive_failed( status, "rtems_task_suspend idle" ); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | puts( "INIT - Obtain priority ceiling semaphore - priority increases" ); |
---|
| 61 | status= rtems_semaphore_obtain( Semaphore_id[1], RTEMS_DEFAULT_OPTIONS, 0 ); |
---|
| 62 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
| 63 | |
---|
| 64 | puts( "INIT - Obtain priority ceiling semaphore - priority decreases" ); |
---|
| 65 | status = rtems_semaphore_release( Semaphore_id[1] ); |
---|
| 66 | directive_failed( status, "rtems_semaphore_release" ); |
---|
| 67 | |
---|
| 68 | if (suspendIdle) { |
---|
| 69 | puts( "INIT - Resume Idle Task"); |
---|
[e3be6915] | 70 | status = rtems_task_resume( Idle_id ); |
---|
[5bbc204] | 71 | directive_failed( status, "rtems_task_resume idle" ); |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | rtems_task Init( |
---|
| 76 | rtems_task_argument argument |
---|
| 77 | ) |
---|
| 78 | { |
---|
| 79 | rtems_status_code status; |
---|
| 80 | |
---|
[6c0301d] | 81 | TEST_BEGIN(); |
---|
[5bbc204] | 82 | |
---|
[e3be6915] | 83 | status = _Objects_Name_to_id_u32( |
---|
[21275b58] | 84 | &_Thread_Information.Objects, |
---|
[e3be6915] | 85 | rtems_build_name( 'I', 'D', 'L', 'E' ), |
---|
| 86 | RTEMS_SEARCH_LOCAL_NODE, |
---|
| 87 | &Idle_id |
---|
| 88 | ); |
---|
| 89 | rtems_test_assert( status == RTEMS_SUCCESSFUL ); |
---|
| 90 | |
---|
[5bbc204] | 91 | /* |
---|
| 92 | * Create the semaphore. Then obtain and release the |
---|
| 93 | * semaphore with no other tasks running. |
---|
| 94 | */ |
---|
| 95 | puts( "INIT - Create priority ceiling semaphore" ); |
---|
| 96 | Semaphore_name[ 1 ] = rtems_build_name( 'S', 'M', '1', ' ' ); |
---|
| 97 | status = rtems_semaphore_create( |
---|
| 98 | Semaphore_name[ 1 ], |
---|
| 99 | 1, |
---|
| 100 | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY_CEILING | RTEMS_PRIORITY, |
---|
| 101 | 2, |
---|
| 102 | &Semaphore_id[ 1 ] |
---|
| 103 | ); |
---|
| 104 | directive_failed( status, "rtems_semaphore_create of SM1" ); |
---|
| 105 | ObtainRelease( false ); |
---|
| 106 | |
---|
| 107 | /* |
---|
| 108 | * Create test task and obtain release the semaphore with |
---|
| 109 | * one other task running. |
---|
| 110 | */ |
---|
| 111 | puts( "INIT - create task 1" ); |
---|
| 112 | Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' ); |
---|
| 113 | status = rtems_task_create( |
---|
| 114 | Task_name[ 1 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, |
---|
| 115 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 1 ] |
---|
| 116 | ); |
---|
| 117 | status = rtems_task_start( Task_id[ 1 ], Test_task, 1 ); |
---|
| 118 | ObtainRelease( false ); |
---|
| 119 | |
---|
| 120 | /* |
---|
| 121 | * Create a a second test task and obtain release the semaphore |
---|
| 122 | * with both tasks running. |
---|
| 123 | */ |
---|
| 124 | puts( "INIT - create task 2" ); |
---|
| 125 | Task_name[ 1 ] = rtems_build_name( 'T', 'A', '2', ' ' ); |
---|
| 126 | status = rtems_task_create( |
---|
| 127 | Task_name[ 2 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, |
---|
| 128 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 2 ] |
---|
| 129 | ); |
---|
| 130 | status = rtems_task_start( Task_id[ 2 ], Test_task, 1 ); |
---|
| 131 | ObtainRelease( false ); |
---|
| 132 | |
---|
| 133 | /* |
---|
| 134 | * Obtain and release the semaphore with the idle task suspended. |
---|
| 135 | */ |
---|
| 136 | ObtainRelease( true ); |
---|
| 137 | |
---|
| 138 | /* End the Test */ |
---|
[6c0301d] | 139 | TEST_END(); |
---|
[5bbc204] | 140 | rtems_test_exit(0); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | /* configuration information */ |
---|
| 144 | |
---|
| 145 | #define CONFIGURE_SCHEDULER_SIMPLE |
---|
| 146 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
[c4b8b147] | 147 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
[5bbc204] | 148 | |
---|
[3c8eda7] | 149 | #define CONFIGURE_MAXIMUM_TASKS 3 |
---|
[5bbc204] | 150 | #define CONFIGURE_MAXIMUM_SEMAPHORES 2 |
---|
| 151 | |
---|
[6c0301d] | 152 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
| 153 | |
---|
[5bbc204] | 154 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 155 | |
---|
| 156 | #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) |
---|
| 157 | #define CONFIGURE_INIT_TASK_PRIORITY 4 |
---|
| 158 | |
---|
[13097181] | 159 | #define CONFIGURE_DISABLE_SMP_CONFIGURATION |
---|
| 160 | |
---|
[5bbc204] | 161 | #define CONFIGURE_INIT |
---|
| 162 | #include <rtems/confdefs.h> |
---|
| 163 | /* end of include file */ |
---|