source: rtems/testsuites/samples/capture/test1.c @ 52410c2

4.104.115
Last change on this file since 52410c2 was 52410c2, checked in by Joel Sherrill <joel.sherrill@…>, on 12/18/08 at 21:14:16

2008-12-18 Joel Sherrill <joel.sherrill@…>

  • capture/test1.c: Add const to eliminate warning.
  • Property mode set to 100644
File size: 6.6 KB
Line 
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
27static volatile int capture_CT1a_deleted;
28static volatile int capture_CT1b_deleted;
29static volatile int capture_CT1c_deleted;
30
31static void
32capture_wait (uint32_t period)
33{
34  rtems_task_wake_after (RTEMS_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 */
47static void
48capture_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
72static void
73capture_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
85static void
86capture_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
110static void
111capture_test_1 (int                                argc,
112                char**                             argv,
113                const rtems_monitor_command_arg_t* command_arg,
114                bool                               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
251static 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
263void 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}
Note: See TracBrowser for help on using the repository browser.