[4a4aabc] | 1 | /* |
---|
| 2 | * Exercise thread queue enqueue and dequeue priority |
---|
| 3 | * |
---|
[b84f1fdc] | 4 | * COPYRIGHT (c) 1989-2009. |
---|
[4a4aabc] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
| 7 | * The license and distribution terms for this file may be |
---|
| 8 | * found in the file LICENSE in this distribution or at |
---|
| 9 | * http://www.rtems.com/license/LICENSE. |
---|
| 10 | * |
---|
| 11 | * $Id$ |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | #include <stdio.h> |
---|
| 15 | #include <stdlib.h> |
---|
| 16 | |
---|
| 17 | #include <bsp.h> |
---|
| 18 | |
---|
| 19 | #include "tmacros.h" |
---|
| 20 | |
---|
| 21 | #define MAX_TASKS 20 |
---|
| 22 | |
---|
[b84f1fdc] | 23 | rtems_task Init(rtems_task_argument argument); |
---|
| 24 | rtems_task Locker_task(rtems_task_argument unused); |
---|
| 25 | void do_test( |
---|
| 26 | rtems_attribute attr, |
---|
| 27 | bool extract /* TRUE if extract, not release */ |
---|
| 28 | ); |
---|
| 29 | |
---|
[4a4aabc] | 30 | /* |
---|
| 31 | * Carefully chosen to exercise threadq enqueue/dequeue priority logic. |
---|
| 32 | * Somewhat randomly sorted to ensure than if discipline is FIFO, run-time |
---|
| 33 | * behavior won't be the same when released. |
---|
| 34 | */ |
---|
[a986c075] | 35 | #if (RTEMS_MAXIMUM_PRIORITY >= 64) |
---|
[4a4aabc] | 36 | rtems_task_priority Priorities[MAX_TASKS] = { |
---|
| 37 | 37, 37, 37, 37, /* backward - more 2-n */ |
---|
| 38 | 2, 2, 2, 2, /* forward - multiple are on 2-n chain */ |
---|
| 39 | 4, 3, /* forward - search forward arbitrary */ |
---|
| 40 | 3, 3, 3, 3, /* forward - more 2-n */ |
---|
| 41 | 38, 37, /* backward - search backward arbitrary */ |
---|
| 42 | 34, 34, 34, 34, /* backward - multple on 2-n chain */ |
---|
| 43 | }; |
---|
[a986c075] | 44 | #else |
---|
| 45 | rtems_task_priority Priorities[MAX_TASKS] = { |
---|
| 46 | 13, 13, 13, 13, /* backward - more 2-n */ |
---|
| 47 | 2, 2, 2, 2, /* forward - multiple are on 2-n chain */ |
---|
| 48 | 4, 3, /* forward - search forward arbitrary */ |
---|
| 49 | 3, 3, 3, 3, /* forward - more 2-n */ |
---|
| 50 | 14, 13, /* backward - search backward arbitrary */ |
---|
| 51 | 12, 12, 12, 12, /* backward - multple on 2-n chain */ |
---|
| 52 | }; |
---|
| 53 | #endif |
---|
[4a4aabc] | 54 | |
---|
| 55 | |
---|
| 56 | rtems_id Semaphore; |
---|
| 57 | rtems_id Task_id[ MAX_TASKS ]; |
---|
| 58 | rtems_name Task_name[ MAX_TASKS ]; |
---|
| 59 | |
---|
| 60 | rtems_task Locker_task( |
---|
| 61 | rtems_task_argument unused |
---|
| 62 | ) |
---|
| 63 | { |
---|
| 64 | rtems_id tid; |
---|
| 65 | uint32_t task_index; |
---|
| 66 | rtems_status_code status; |
---|
| 67 | |
---|
| 68 | status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); |
---|
| 69 | directive_failed( status, "rtems_task_ident" ); |
---|
| 70 | |
---|
| 71 | task_index = task_number( tid ) - 1; |
---|
| 72 | |
---|
| 73 | status = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 0 ); |
---|
| 74 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
| 75 | |
---|
| 76 | put_name( Task_name[ task_index ], FALSE ); |
---|
| 77 | puts( " - unblocked - OK" ); |
---|
| 78 | |
---|
| 79 | (void) rtems_task_delete( RTEMS_SELF ); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | void do_test( |
---|
| 83 | rtems_attribute attr, |
---|
[f0157b8] | 84 | bool extract /* TRUE if extract, not release */ |
---|
[4a4aabc] | 85 | ) |
---|
| 86 | { |
---|
| 87 | rtems_status_code status; |
---|
| 88 | int i; |
---|
| 89 | |
---|
| 90 | status = rtems_semaphore_create( |
---|
| 91 | rtems_build_name( 'S', 'E', 'M', '0' ), /* name = SEM0 */ |
---|
| 92 | 0, /* unlocked */ |
---|
| 93 | RTEMS_BINARY_SEMAPHORE | attr, /* mutex w/desired discipline */ |
---|
| 94 | 0, /* IGNORED */ |
---|
| 95 | &Semaphore |
---|
| 96 | ); |
---|
| 97 | directive_failed( status, "rtems_semaphore_create" ); |
---|
| 98 | |
---|
| 99 | for (i=0 ; i< MAX_TASKS ; i++ ) { |
---|
| 100 | |
---|
| 101 | Task_name[ i ] = rtems_build_name( |
---|
| 102 | 'T', |
---|
| 103 | 'A', |
---|
| 104 | '0' + (char)(i/10), |
---|
| 105 | '0' + (char)(i%10) |
---|
| 106 | ); |
---|
| 107 | |
---|
| 108 | status = rtems_task_create( |
---|
| 109 | Task_name[ i ], |
---|
| 110 | Priorities[ i ], |
---|
| 111 | RTEMS_MINIMUM_STACK_SIZE, |
---|
| 112 | RTEMS_DEFAULT_MODES, |
---|
| 113 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
| 114 | &Task_id[ i ] |
---|
| 115 | ); |
---|
| 116 | directive_failed( status, "rtems_task_create" ); |
---|
| 117 | |
---|
[b84f1fdc] | 118 | status = rtems_task_start( |
---|
| 119 | Task_id[ i ], Locker_task, (rtems_task_argument)i ); |
---|
[4a4aabc] | 120 | directive_failed( status, "rtems_task_start" ); |
---|
| 121 | |
---|
| 122 | status = rtems_task_wake_after( 10 ); |
---|
| 123 | directive_failed( status, "rtems_task_wake_after" ); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | for (i=0 ; i< MAX_TASKS ; i++ ) { |
---|
| 127 | if ( extract == FALSE ) { |
---|
| 128 | status = rtems_semaphore_release( Semaphore ); |
---|
| 129 | directive_failed( status, "rtems_semaphore_release" ); |
---|
| 130 | |
---|
| 131 | status = rtems_task_wake_after( 100 ); |
---|
| 132 | directive_failed( status, "rtems_task_wake_after" ); |
---|
| 133 | } else { |
---|
| 134 | status = rtems_task_delete( Task_id[ i ] ); |
---|
| 135 | directive_failed( status, "rtems_task_delete" ); |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | /* one extra release for the initial state */ |
---|
| 140 | status = rtems_semaphore_release( Semaphore ); |
---|
| 141 | directive_failed( status, "rtems_semaphore_release" ); |
---|
| 142 | |
---|
| 143 | /* now delete the semaphore since no one is waiting and it is unlocked */ |
---|
| 144 | status = rtems_semaphore_delete( Semaphore ); |
---|
| 145 | directive_failed( status, "rtems_semaphore_delete" ); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | rtems_task Init( |
---|
| 149 | rtems_task_argument argument |
---|
| 150 | ) |
---|
| 151 | { |
---|
[90f6ea62] | 152 | puts( "\n\n*** START OF TEST 40 ***" ); |
---|
[4a4aabc] | 153 | |
---|
| 154 | if ( sizeof( Priorities ) / sizeof( rtems_task_priority ) != MAX_TASKS ) { |
---|
| 155 | puts( "Priorities table does not have right number of entries" ); |
---|
| 156 | exit( 0 ); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | puts( "Exercising blocking discipline w/extract in FIFO order " ); |
---|
| 160 | do_test( RTEMS_FIFO, TRUE ); |
---|
| 161 | |
---|
| 162 | puts( "Exercising blocking discipline w/unblock in FIFO order" ); |
---|
| 163 | do_test( RTEMS_FIFO, FALSE ); |
---|
| 164 | |
---|
| 165 | rtems_test_pause_and_screen_number( 2 ); |
---|
| 166 | |
---|
| 167 | puts( "Exercising blocking discipline w/extract in priority order " ); |
---|
| 168 | do_test( RTEMS_PRIORITY, TRUE ); |
---|
| 169 | |
---|
| 170 | puts( "Exercising blocking discipline w/unblock in priority order" ); |
---|
| 171 | do_test( RTEMS_PRIORITY, FALSE ); |
---|
| 172 | |
---|
[6e315132] | 173 | puts( "*** END OF TEST 42 ***" ); |
---|
[4a4aabc] | 174 | exit(0); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | /**************** START OF CONFIGURATION INFORMATION ****************/ |
---|
| 178 | |
---|
| 179 | #define CONFIGURE_INIT |
---|
| 180 | |
---|
| 181 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 182 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 183 | |
---|
| 184 | #define CONFIGURE_MAXIMUM_TASKS MAX_TASKS+1 |
---|
| 185 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
| 186 | |
---|
| 187 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 188 | |
---|
| 189 | #include <rtems/confdefs.h> |
---|
| 190 | |
---|
| 191 | /**************** END OF CONFIGURATION INFORMATION ****************/ |
---|
| 192 | |
---|