]> rtime.felk.cvut.cz Git - rtems-devel.git/blob - rtems-tests/prioinh_check/prio_inherit_test.c
Added test application to check priority inheritance behavior.
[rtems-devel.git] / rtems-tests / prioinh_check / prio_inherit_test.c
1 #include "system.h"
2 #include <string.h>
3 #include <rtems.h>
4 #include <rtems/error.h>
5 #include <stdio.h>
6
7 #include "app_def.h"
8
9 rtems_id shared_with_hi_sem;
10 rtems_id shared_with_lo_sem;
11
12 rtems_id release_hi_sem;
13 rtems_id release_mid_sem;
14 rtems_id release_lo_sem;
15
16 rtems_id hi_task_id;
17 rtems_id mid_task_id;
18 rtems_id lo_task_id;
19
20
21 void block_delay(int delay)
22 {
23   volatile int l;
24   
25   while(delay--) {
26     l = 100000;
27     while(l--);
28   }
29 }
30
31
32 rtems_task hi_task(
33   rtems_task_argument argument
34 )
35 {
36   rtems_status_code status;
37
38   printf("THI created\n");
39   while(1){
40     status=rtems_semaphore_obtain(release_hi_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT);
41     check_rtems_status(status, 0, "rtems_semaphore_obtain RHI from THI");
42     printf("THI released (RHI)\n");
43
44     status=rtems_semaphore_obtain(shared_with_hi_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT);
45     check_rtems_status(status, 0, "rtems_semaphore_obtain SHI from THI");
46     printf("THI obtained SHI\n");
47
48     block_delay(100);
49
50     printf("THI going to release SHI\n");
51     status=rtems_semaphore_release(shared_with_hi_sem);
52     check_rtems_status(status, 0, "rtems_semaphore_release SHI from THI");
53     printf("THI released SHI\n");
54   }
55 }
56
57 rtems_task mid_task(
58   rtems_task_argument argument
59 )
60 {
61   rtems_status_code status;
62
63   printf("TMID created\n");
64   while(1){
65     status=rtems_semaphore_obtain(release_mid_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT);
66     check_rtems_status(status, 0, "rtems_semaphore_obtain RMID from TMID");
67     printf("MID released (RMID)\n");
68
69     block_delay(100);
70
71     printf("MID going to sleep\n");
72   }
73 }
74
75 rtems_task lo_task(
76   rtems_task_argument argument
77 )
78 {
79   rtems_status_code status;
80
81   printf("LO created\n");
82   while(1){
83     status=rtems_semaphore_obtain(release_lo_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT);
84     check_rtems_status(status, 0, "rtems_semaphore_obtain RLO from TLO");
85     printf("TLO released (RLO)\n");
86
87     status=rtems_semaphore_obtain(shared_with_lo_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT);
88     check_rtems_status(status, 0, "rtems_semaphore_obtain SLO from TLO");
89     printf("TLO obtained SLO\n");
90
91     block_delay(100);
92
93     printf("TLO going to release SLO\n");
94     status=rtems_semaphore_release(shared_with_lo_sem);
95     check_rtems_status(status, 0, "rtems_semaphore_release SLO from TLO");
96     printf("TLO released SLO\n");
97   }
98 }
99
100
101 rtems_task Task_1(
102   rtems_task_argument argument
103 )
104 {
105   rtems_status_code status;
106   rtems_task_priority prio;
107
108   status = rtems_task_wake_after( TICKS_PER_SECOND );
109   check_rtems_status( status, 0, "rtems_task_wake_after" );
110
111   printf("*** Starting up Task_1 ***\n");
112
113
114   status=rtems_semaphore_create(rtems_build_name('S','H','I',' '),
115           1,
116           RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY|RTEMS_LOCAL,
117           0,
118           &shared_with_hi_sem);
119   check_rtems_status( status, 0, "rtems_semaphore_create SHI" );
120
121   status=rtems_semaphore_create(rtems_build_name('S','L','O',' '),
122           1,
123           RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY|RTEMS_LOCAL,
124           0,
125           &shared_with_lo_sem);
126   check_rtems_status( status, 0, "rtems_semaphore_create SLO" );
127
128   status=rtems_semaphore_create(rtems_build_name('R','H','I',' '),
129           0,
130           RTEMS_PRIORITY|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_LOCAL,
131           0,
132           &release_hi_sem);
133   check_rtems_status( status, 0, "rtems_semaphore_create RHI" );
134
135   status=rtems_semaphore_create(rtems_build_name('R','M','I','D'),
136           0,
137           RTEMS_PRIORITY|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_LOCAL,
138           0,
139           &release_mid_sem);
140   check_rtems_status( status, 0, "rtems_semaphore_create RMID" );
141
142   status=rtems_semaphore_create(rtems_build_name('R','L','O',' '),
143           0,
144           RTEMS_PRIORITY|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_LOCAL,
145           0,
146           &release_lo_sem);
147   check_rtems_status( status, 0, "rtems_semaphore_create RLO" );
148
149   status = rtems_task_create(rtems_build_name('T','H','I',' '),
150      TASK_HI_PRIORITY,
151      RTEMS_MINIMUM_STACK_SIZE+0x1000,
152      RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/,
153      RTEMS_DEFAULT_ATTRIBUTES,
154      &hi_task_id
155   );
156   check_rtems_status(status, 0, "rtems_task_create THI");
157
158   status = rtems_task_create(rtems_build_name('T','M','I','D'),
159      TASK_MID_PRIORITY,
160      RTEMS_MINIMUM_STACK_SIZE+0x1000,
161      RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/,
162      RTEMS_DEFAULT_ATTRIBUTES,
163      &mid_task_id
164   );
165   check_rtems_status(status, 0, "rtems_task_create MID");
166
167   status = rtems_task_create(rtems_build_name('T','L','O',' '),
168      TASK_LO_PRIORITY,
169      RTEMS_MINIMUM_STACK_SIZE+0x1000,
170      RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/,
171      RTEMS_DEFAULT_ATTRIBUTES,
172      &lo_task_id
173   );
174   check_rtems_status(status, 0, "rtems_task_create LO");
175
176   status = rtems_task_start( hi_task_id, hi_task, 0 );
177   check_rtems_status(status, 0, "rtems_task_start THI\n");
178
179   status = rtems_task_start( mid_task_id, mid_task, 0 );
180   check_rtems_status(status, 0, "rtems_task_start MID\n");
181
182   status = rtems_task_start( lo_task_id, lo_task, 0 );
183   check_rtems_status(status, 0, "rtems_task_start LO\n");
184
185
186   while(1){
187
188
189     status=rtems_semaphore_obtain(shared_with_lo_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT);
190     check_rtems_status(status, 0, "rtems_semaphore_obtain SLO");
191     printf("1 obtained SLO\n");
192
193     printf("1 going to release RLO\n");
194     status=rtems_semaphore_release(release_lo_sem);
195     check_rtems_status(status, 0, "rtems_semaphore_release RLO");
196
197     status=rtems_semaphore_obtain(shared_with_hi_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT);
198     check_rtems_status(status, 0, "rtems_semaphore_obtain SHI");
199     printf("1 obtained SHI\n");
200
201     printf("1 going to release RHI\n");
202     status=rtems_semaphore_release(release_hi_sem);
203     check_rtems_status(status, 0, "rtems_semaphore_release RHI");
204
205     status = rtems_task_wake_after( TICKS_PER_SECOND );
206     check_rtems_status( status, 0, "rtems_task_wake_after" );
207
208     status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio);
209     check_rtems_status( status, 0, "rtems_task_set_priority");
210     printf("1 priority is %d\n", (int)prio);
211
212     printf("1 going to release RMID\n");
213     status=rtems_semaphore_release(release_mid_sem);
214     check_rtems_status(status, 0, "rtems_semaphore_release RMID");
215
216     block_delay(100);
217
218     printf("1 going to release SHI\n");
219     status=rtems_semaphore_release(shared_with_hi_sem);
220     check_rtems_status(status, 0, "rtems_semaphore_release SHI");
221
222     status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio);
223     check_rtems_status( status, 0, "rtems_task_set_priority");
224     printf("1 priority is %d\n", (int)prio);
225
226     block_delay(100);
227
228     printf("1 going to release SLO\n");
229     status=rtems_semaphore_release(shared_with_lo_sem);
230     check_rtems_status(status, 0, "rtems_semaphore_release SLO");
231     printf("1 released both SHI and SLO\n");
232
233     status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio);
234     check_rtems_status( status, 0, "rtems_task_set_priority");
235     printf("1 priority is %d\n", (int)prio);
236
237     block_delay(100);
238
239     printf("1 going to sleep\n");
240     status = rtems_task_wake_after( TICKS_PER_SECOND );
241     check_rtems_status( status, 0, "rtems_task_wake_after" );
242   }
243 }