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