[5353469a] | 1 | /* |
---|
| 2 | * COPYRIGHT (c) 1989-2009. |
---|
| 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 | |
---|
[7d3f9c6] | 10 | #ifdef HAVE_CONFIG_H |
---|
| 11 | #include "config.h" |
---|
| 12 | #endif |
---|
| 13 | |
---|
[5353469a] | 14 | #include <tmacros.h> |
---|
| 15 | #include <intrcritical.h> |
---|
| 16 | |
---|
[2bbea657] | 17 | #include <rtems/rtems/semimpl.h> |
---|
| 18 | |
---|
[3c8eda7] | 19 | /* forward declarations to avoid warnings */ |
---|
| 20 | rtems_task Init(rtems_task_argument argument); |
---|
| 21 | rtems_timer_service_routine test_release_from_isr(rtems_id timer, void *arg); |
---|
| 22 | Thread_blocking_operation_States getState(void); |
---|
| 23 | |
---|
[5353469a] | 24 | #define TEST_NAME "16" |
---|
| 25 | |
---|
| 26 | Thread_Control *Main_TCB; |
---|
| 27 | rtems_id Main_task; |
---|
| 28 | rtems_id Semaphore; |
---|
| 29 | volatile bool case_hit; |
---|
| 30 | |
---|
| 31 | Thread_blocking_operation_States getState(void) |
---|
| 32 | { |
---|
| 33 | Objects_Locations location; |
---|
| 34 | Semaphore_Control *sem; |
---|
| 35 | |
---|
| 36 | sem = (Semaphore_Control *)_Objects_Get( |
---|
[b1274bd9] | 37 | &_Semaphore_Information, Semaphore, &location ); |
---|
[5353469a] | 38 | if ( location != OBJECTS_LOCAL ) { |
---|
| 39 | puts( "Bad object lookup" ); |
---|
| 40 | rtems_test_exit(0); |
---|
| 41 | } |
---|
| 42 | _Thread_Unnest_dispatch(); |
---|
| 43 | |
---|
| 44 | return sem->Core_control.semaphore.Wait_queue.sync_state; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | rtems_timer_service_routine test_release_from_isr( |
---|
| 48 | rtems_id timer, |
---|
| 49 | void *arg |
---|
| 50 | ) |
---|
| 51 | { |
---|
| 52 | if ( getState() == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) { |
---|
| 53 | case_hit = true; |
---|
| 54 | (void) rtems_semaphore_release( Semaphore ); |
---|
| 55 | } |
---|
[355ca1ad] | 56 | |
---|
| 57 | if ( Main_TCB->Wait.queue != NULL ) { |
---|
| 58 | _Thread_queue_Process_timeout( Main_TCB ); |
---|
| 59 | } |
---|
[5353469a] | 60 | } |
---|
| 61 | |
---|
| 62 | rtems_task Init( |
---|
| 63 | rtems_task_argument ignored |
---|
| 64 | ) |
---|
| 65 | { |
---|
| 66 | rtems_status_code sc; |
---|
| 67 | int resets; |
---|
| 68 | |
---|
| 69 | puts( |
---|
| 70 | "\n\n*** TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***\n" |
---|
| 71 | "Init - Trying to generate timeout of a thread that had its blocking\n" |
---|
| 72 | "Init - request satisfied while blocking but before time timeout" |
---|
| 73 | ); |
---|
| 74 | |
---|
| 75 | puts( "Init - rtems_semaphore_create - OK" ); |
---|
| 76 | sc = rtems_semaphore_create( |
---|
| 77 | rtems_build_name( 'S', 'M', '1', ' ' ), |
---|
| 78 | 0, |
---|
| 79 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
| 80 | RTEMS_NO_PRIORITY, |
---|
| 81 | &Semaphore |
---|
| 82 | ); |
---|
| 83 | directive_failed( sc, "rtems_semaphore_create of SM1" ); |
---|
| 84 | |
---|
| 85 | Main_task = rtems_task_self(); |
---|
[d7ce33f1] | 86 | Main_TCB = _Thread_Get_executing(); |
---|
[5353469a] | 87 | |
---|
| 88 | interrupt_critical_section_test_support_initialize( test_release_from_isr ); |
---|
| 89 | |
---|
| 90 | case_hit = false; |
---|
| 91 | |
---|
| 92 | for (resets=0 ; !case_hit && resets<10 ;) { |
---|
| 93 | if ( interrupt_critical_section_test_support_delay() ) |
---|
| 94 | resets++; |
---|
| 95 | |
---|
| 96 | sc = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 2 ); |
---|
| 97 | if ( sc == RTEMS_SUCCESSFUL ) |
---|
| 98 | break; |
---|
| 99 | fatal_directive_status( sc, RTEMS_TIMEOUT, "rtems_semaphore_obtain" ); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | if ( case_hit ) { |
---|
| 103 | puts( "Init - Case hit" ); |
---|
| 104 | puts( "*** END OF TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***" ); |
---|
[b1274bd9] | 105 | } else |
---|
[5353469a] | 106 | puts( "Init - Case not hit - ran too long" ); |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | rtems_test_exit(0); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | /* configuration information */ |
---|
| 113 | |
---|
| 114 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 115 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 116 | |
---|
| 117 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
| 118 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
[288cebb] | 119 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
[5353469a] | 120 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
| 121 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 122 | |
---|
| 123 | #define CONFIGURE_INIT |
---|
| 124 | #include <rtems/confdefs.h> |
---|
| 125 | |
---|
| 126 | /* global variables */ |
---|