1 | /* Test1 |
---|
2 | * |
---|
3 | * This test uses creates a number of tasks so the capture engine |
---|
4 | * can show a trace. |
---|
5 | * |
---|
6 | * Input parameters: NONE |
---|
7 | * |
---|
8 | * Output parameters: NONE |
---|
9 | * |
---|
10 | * COPYRIGHT (c) 1989-1997. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may in |
---|
14 | * the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.com/license/LICENSE. |
---|
16 | * |
---|
17 | * $Id$ |
---|
18 | */ |
---|
19 | |
---|
20 | #include "system.h" |
---|
21 | #include <stdio.h> |
---|
22 | #include <stdlib.h> |
---|
23 | |
---|
24 | #include <rtems.h> |
---|
25 | #include <rtems/monitor.h> |
---|
26 | |
---|
27 | static volatile int capture_CT1a_deleted; |
---|
28 | static volatile int capture_CT1b_deleted; |
---|
29 | static volatile int capture_CT1c_deleted; |
---|
30 | |
---|
31 | static void |
---|
32 | capture_wait (uint32_t period) |
---|
33 | { |
---|
34 | rtems_task_wake_after (TOD_MICROSECONDS_TO_TICKS (period * 1000)); |
---|
35 | } |
---|
36 | |
---|
37 | /* |
---|
38 | * CT1a: Claim the mutex and then wait a while then wake |
---|
39 | * up and release the mutex. While this task waits with |
---|
40 | * the mutex another higher priority task is started that |
---|
41 | * just loops using all the processing time. It is not until |
---|
42 | * another even higher priority thread blocks on the mutex |
---|
43 | * does this task get raised to that priority and so |
---|
44 | * releases the mutex. This will allow us to capture the |
---|
45 | * action of priority inversion. |
---|
46 | */ |
---|
47 | static void |
---|
48 | capture_CT1a (rtems_task_argument arg) |
---|
49 | { |
---|
50 | rtems_id mutex = (rtems_id) arg; |
---|
51 | rtems_status_code sc; |
---|
52 | |
---|
53 | sc = rtems_semaphore_obtain (mutex, RTEMS_WAIT, 0); |
---|
54 | |
---|
55 | if (sc != RTEMS_SUCCESSFUL) |
---|
56 | fprintf (stdout, "error: CT1a: mutex obtain: %s\n", |
---|
57 | rtems_status_text (sc)); |
---|
58 | |
---|
59 | capture_wait (2500); |
---|
60 | |
---|
61 | sc = rtems_semaphore_release (mutex); |
---|
62 | |
---|
63 | if (sc != RTEMS_SUCCESSFUL) |
---|
64 | fprintf (stdout, "error: CT1a: mutex release: %s\n", |
---|
65 | rtems_status_text (sc)); |
---|
66 | |
---|
67 | capture_CT1a_deleted = 1; |
---|
68 | |
---|
69 | rtems_task_delete (RTEMS_SELF); |
---|
70 | } |
---|
71 | |
---|
72 | static void |
---|
73 | capture_CT1b (rtems_task_argument arg) |
---|
74 | { |
---|
75 | volatile int i; |
---|
76 | |
---|
77 | while (!capture_CT1c_deleted) |
---|
78 | i++; |
---|
79 | |
---|
80 | capture_CT1b_deleted = 1; |
---|
81 | |
---|
82 | rtems_task_delete (RTEMS_SELF); |
---|
83 | } |
---|
84 | |
---|
85 | static void |
---|
86 | capture_CT1c (rtems_task_argument arg) |
---|
87 | { |
---|
88 | rtems_id mutex = (rtems_id) arg; |
---|
89 | rtems_status_code sc; |
---|
90 | |
---|
91 | sc = rtems_semaphore_obtain (mutex, RTEMS_WAIT, 0); |
---|
92 | |
---|
93 | if (sc != RTEMS_SUCCESSFUL) |
---|
94 | fprintf (stdout, "error: CT1c: mutex obtain: %s\n", |
---|
95 | rtems_status_text (sc)); |
---|
96 | |
---|
97 | capture_wait (500); |
---|
98 | |
---|
99 | sc = rtems_semaphore_release (mutex); |
---|
100 | |
---|
101 | if (sc != RTEMS_SUCCESSFUL) |
---|
102 | fprintf (stdout, "error: CT1c: mutex release: %s\n", |
---|
103 | rtems_status_text (sc)); |
---|
104 | |
---|
105 | capture_CT1c_deleted = 1; |
---|
106 | |
---|
107 | rtems_task_delete (RTEMS_SELF); |
---|
108 | } |
---|
109 | |
---|
110 | static void |
---|
111 | capture_test_1 (int argc, |
---|
112 | char** argv, |
---|
113 | rtems_monitor_command_arg_t* command_arg, |
---|
114 | boolean verbose) |
---|
115 | { |
---|
116 | rtems_status_code sc; |
---|
117 | rtems_name name; |
---|
118 | rtems_id id[3]; |
---|
119 | rtems_id mutex; |
---|
120 | int loops; |
---|
121 | |
---|
122 | capture_CT1a_deleted = 0; |
---|
123 | capture_CT1b_deleted = 0; |
---|
124 | capture_CT1c_deleted = 0; |
---|
125 | |
---|
126 | name = rtems_build_name('C', 'T', 'm', '1'); |
---|
127 | |
---|
128 | sc = rtems_semaphore_create (name, 1, |
---|
129 | RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | |
---|
130 | RTEMS_INHERIT_PRIORITY, |
---|
131 | 0, &mutex); |
---|
132 | |
---|
133 | if (sc != RTEMS_SUCCESSFUL) |
---|
134 | { |
---|
135 | fprintf (stdout, "error: Test 1: cannot mutex: %s\n", |
---|
136 | rtems_status_text (sc)); |
---|
137 | return; |
---|
138 | } |
---|
139 | |
---|
140 | name = rtems_build_name('C', 'T', '1', 'a'); |
---|
141 | |
---|
142 | sc = rtems_task_create (name, 102, 2 * 1024, |
---|
143 | RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, |
---|
144 | RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR, |
---|
145 | &id[0]); |
---|
146 | |
---|
147 | if (sc != RTEMS_SUCCESSFUL) |
---|
148 | { |
---|
149 | fprintf (stdout, "error: Test 1: cannot create CT1a: %s\n", |
---|
150 | rtems_status_text (sc)); |
---|
151 | rtems_semaphore_delete (mutex); |
---|
152 | return; |
---|
153 | } |
---|
154 | |
---|
155 | sc = rtems_task_start (id[0], capture_CT1a, (rtems_task_argument) mutex); |
---|
156 | |
---|
157 | if (sc != RTEMS_SUCCESSFUL) |
---|
158 | { |
---|
159 | fprintf (stdout, "error: Test 1: cannot start CT1a: %s\n", |
---|
160 | rtems_status_text (sc)); |
---|
161 | rtems_task_delete (id[0]); |
---|
162 | rtems_semaphore_delete (mutex); |
---|
163 | return; |
---|
164 | } |
---|
165 | |
---|
166 | capture_wait (1000); |
---|
167 | |
---|
168 | name = rtems_build_name('C', 'T', '1', 'b'); |
---|
169 | |
---|
170 | sc = rtems_task_create (name, 101, 2 * 1024, |
---|
171 | RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, |
---|
172 | RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR, |
---|
173 | &id[1]); |
---|
174 | |
---|
175 | if (sc != RTEMS_SUCCESSFUL) |
---|
176 | { |
---|
177 | fprintf (stdout, "error: Test 1: cannot create CT1b: %s\n", |
---|
178 | rtems_status_text (sc)); |
---|
179 | rtems_task_delete (id[0]); |
---|
180 | rtems_semaphore_delete (mutex); |
---|
181 | return; |
---|
182 | } |
---|
183 | |
---|
184 | sc = rtems_task_start (id[1], capture_CT1b, 0); |
---|
185 | |
---|
186 | if (sc != RTEMS_SUCCESSFUL) |
---|
187 | { |
---|
188 | fprintf (stdout, "error: Test 1: cannot start CT1b: %s\n", |
---|
189 | rtems_status_text (sc)); |
---|
190 | rtems_task_delete (id[1]); |
---|
191 | rtems_task_delete (id[0]); |
---|
192 | rtems_semaphore_delete (mutex); |
---|
193 | return; |
---|
194 | } |
---|
195 | |
---|
196 | capture_wait (1000); |
---|
197 | |
---|
198 | name = rtems_build_name('C', 'T', '1', 'c'); |
---|
199 | |
---|
200 | sc = rtems_task_create (name, 100, 2 * 1024, |
---|
201 | RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, |
---|
202 | RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR, |
---|
203 | &id[2]); |
---|
204 | |
---|
205 | if (sc != RTEMS_SUCCESSFUL) |
---|
206 | { |
---|
207 | fprintf (stdout, "error: Test 1: cannot create CT1c: %s\n", |
---|
208 | rtems_status_text (sc)); |
---|
209 | rtems_task_delete (id[1]); |
---|
210 | rtems_task_delete (id[0]); |
---|
211 | rtems_semaphore_delete (mutex); |
---|
212 | return; |
---|
213 | } |
---|
214 | |
---|
215 | sc = rtems_task_start (id[2], capture_CT1c, (rtems_task_argument) mutex); |
---|
216 | |
---|
217 | if (sc != RTEMS_SUCCESSFUL) |
---|
218 | { |
---|
219 | fprintf (stdout, "error: Test 1: cannot start CT1c: %s\n", |
---|
220 | rtems_status_text (sc)); |
---|
221 | rtems_task_delete (id[2]); |
---|
222 | rtems_task_delete (id[1]); |
---|
223 | rtems_task_delete (id[0]); |
---|
224 | rtems_semaphore_delete (mutex); |
---|
225 | return; |
---|
226 | } |
---|
227 | |
---|
228 | loops = 15; |
---|
229 | |
---|
230 | while (!(capture_CT1a_deleted || capture_CT1b_deleted || |
---|
231 | capture_CT1c_deleted) && loops) |
---|
232 | { |
---|
233 | loops--; |
---|
234 | capture_wait (1000); |
---|
235 | } |
---|
236 | |
---|
237 | if (!loops) |
---|
238 | { |
---|
239 | fprintf (stdout, "error: Test 1: test tasks did not delete\n"); |
---|
240 | rtems_task_delete (id[2]); |
---|
241 | rtems_task_delete (id[1]); |
---|
242 | rtems_task_delete (id[0]); |
---|
243 | } |
---|
244 | |
---|
245 | sc = rtems_semaphore_delete (mutex); |
---|
246 | if (sc != RTEMS_SUCCESSFUL) |
---|
247 | fprintf (stdout, "error: Test 1: deleting the mutex: %s\n", |
---|
248 | rtems_status_text (sc)); |
---|
249 | } |
---|
250 | |
---|
251 | static rtems_monitor_command_entry_t capture_cmds[] = |
---|
252 | { |
---|
253 | { |
---|
254 | "test1", |
---|
255 | "usage: \n", |
---|
256 | 0, |
---|
257 | capture_test_1, |
---|
258 | { 0 }, |
---|
259 | 0 |
---|
260 | } |
---|
261 | }; |
---|
262 | |
---|
263 | void setup_tasks_to_watch () |
---|
264 | { |
---|
265 | int cmd; |
---|
266 | for (cmd = 0; |
---|
267 | cmd < sizeof (capture_cmds) / sizeof (rtems_monitor_command_entry_t); |
---|
268 | cmd++) |
---|
269 | rtems_monitor_insert_cmd (&capture_cmds[cmd]); |
---|
270 | } |
---|