source: rtems/testsuites/samples/capture/test1.c @ e313551

4.11
Last change on this file since e313551 was e313551, checked in by Ralf Corsepius <ralf.corsepius@…>, on Feb 22, 2011 at 10:58:44 AM

Add HAVE_CONFIG_H.

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