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__ 1 |
---|
13 | #include <tmacros.h> |
---|
14 | #include <intrcritical.h> |
---|
15 | |
---|
16 | /* common parameters */ |
---|
17 | #define SEMAPHORE_ATTRIBUTES RTEMS_PRIORITY |
---|
18 | |
---|
19 | #if defined(PRIORITY_NO_TIMEOUT_FORWARD) |
---|
20 | #define TEST_NAME "06" |
---|
21 | #define TEST_STRING "Priority/Restart Search Task (Forward)" |
---|
22 | |
---|
23 | #define INIT_PRIORITY 2 |
---|
24 | #define BLOCKER_PRIORITY 1 |
---|
25 | #define SEMAPHORE_OBTAIN_TIMEOUT 0 |
---|
26 | |
---|
27 | #elif defined(PRIORITY_NO_TIMEOUT_REVERSE) |
---|
28 | #define TEST_NAME "07" |
---|
29 | #define TEST_STRING "Priority/Restart Search Task (Backward)" |
---|
30 | #define INIT_PRIORITY 126 |
---|
31 | #define BLOCKER_PRIORITY 127 |
---|
32 | #define SEMAPHORE_OBTAIN_TIMEOUT 2 |
---|
33 | |
---|
34 | #else |
---|
35 | |
---|
36 | #error "Test Mode not defined" |
---|
37 | #endif |
---|
38 | |
---|
39 | rtems_id Main_task; |
---|
40 | rtems_id Secondary_task_id; |
---|
41 | rtems_id Semaphore; |
---|
42 | |
---|
43 | Thread_blocking_operation_States getState(void) |
---|
44 | { |
---|
45 | Objects_Locations location; |
---|
46 | Semaphore_Control *sem; |
---|
47 | |
---|
48 | sem = (Semaphore_Control *)_Objects_Get( |
---|
49 | &_Semaphore_Information, Semaphore, &location ); |
---|
50 | if ( location != OBJECTS_LOCAL ) { |
---|
51 | puts( "Bad object lookup" ); |
---|
52 | rtems_test_exit(0); |
---|
53 | } |
---|
54 | _Thread_Unnest_dispatch(); |
---|
55 | |
---|
56 | return sem->Core_control.semaphore.Wait_queue.sync_state; |
---|
57 | } |
---|
58 | |
---|
59 | rtems_timer_service_routine test_release_from_isr( |
---|
60 | rtems_id timer, |
---|
61 | void *arg |
---|
62 | ) |
---|
63 | { |
---|
64 | (void) rtems_task_restart( Secondary_task_id, 1 ); |
---|
65 | } |
---|
66 | |
---|
67 | rtems_task Secondary_task( |
---|
68 | rtems_task_argument arg |
---|
69 | ) |
---|
70 | { |
---|
71 | rtems_status_code status; |
---|
72 | |
---|
73 | if ( arg ) |
---|
74 | (void) rtems_semaphore_flush( Semaphore ); |
---|
75 | |
---|
76 | status = rtems_semaphore_obtain( |
---|
77 | Semaphore, |
---|
78 | RTEMS_DEFAULT_OPTIONS, |
---|
79 | SEMAPHORE_OBTAIN_TIMEOUT |
---|
80 | ); |
---|
81 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
82 | } |
---|
83 | |
---|
84 | rtems_task Init( |
---|
85 | rtems_task_argument ignored |
---|
86 | ) |
---|
87 | { |
---|
88 | rtems_status_code status; |
---|
89 | int resets; |
---|
90 | |
---|
91 | puts( "\n\n*** TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***" ); |
---|
92 | |
---|
93 | puts( "Init - Trying to generate semaphore release from ISR while blocking" ); |
---|
94 | puts( "Init - There is no way for the test to know if it hits the case" ); |
---|
95 | puts( "Init - Variation is: " TEST_STRING ); |
---|
96 | status = rtems_semaphore_create( |
---|
97 | rtems_build_name( 'S', 'M', '1', ' ' ), |
---|
98 | 0, |
---|
99 | SEMAPHORE_ATTRIBUTES, |
---|
100 | RTEMS_NO_PRIORITY, |
---|
101 | &Semaphore |
---|
102 | ); |
---|
103 | directive_failed( status, "rtems_semaphore_create of SM1" ); |
---|
104 | |
---|
105 | Main_task = rtems_task_self(); |
---|
106 | |
---|
107 | status = rtems_task_create( |
---|
108 | rtems_build_name( 'B', 'L', 'C', 'K' ), |
---|
109 | BLOCKER_PRIORITY, |
---|
110 | RTEMS_MINIMUM_STACK_SIZE, |
---|
111 | RTEMS_NO_PREEMPT, |
---|
112 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
113 | &Secondary_task_id |
---|
114 | ); |
---|
115 | directive_failed( status, "rtems_task_create" ); |
---|
116 | |
---|
117 | status = rtems_task_start( Secondary_task_id, Secondary_task, 0 ); |
---|
118 | directive_failed( status, "rtems_task_start" ); |
---|
119 | |
---|
120 | interrupt_critical_section_test_support_initialize( test_release_from_isr ); |
---|
121 | |
---|
122 | for (resets=0 ; resets< 2 ;) { |
---|
123 | if ( interrupt_critical_section_test_support_delay() ) |
---|
124 | resets++; |
---|
125 | |
---|
126 | status = rtems_semaphore_obtain( |
---|
127 | Semaphore, |
---|
128 | RTEMS_DEFAULT_OPTIONS, |
---|
129 | SEMAPHORE_OBTAIN_TIMEOUT |
---|
130 | ); |
---|
131 | } |
---|
132 | |
---|
133 | puts( "*** END OF TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***" ); |
---|
134 | rtems_test_exit(0); |
---|
135 | } |
---|
136 | |
---|
137 | /* configuration information */ |
---|
138 | |
---|
139 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
140 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
141 | |
---|
142 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
143 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
144 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
145 | #define CONFIGURE_INIT_TASK_PRIORITY INIT_PRIORITY |
---|
146 | #define CONFIGURE_INIT_TASK_MODE RTEMS_PREEMPT |
---|
147 | #define CONFIGURE_MICROSECONDS_PER_TICK 2000 |
---|
148 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
149 | |
---|
150 | #define CONFIGURE_INIT |
---|
151 | #include <rtems/confdefs.h> |
---|
152 | |
---|
153 | /* global variables */ |
---|