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