source: rtems/testsuites/samples/capture/test1.c @ 51a95ff9

4.115
Last change on this file since 51a95ff9 was 3324383c, checked in by Joel Sherrill <joel.sherrill@…>, on 05/05/14 at 14:47:30

testsuites: Remove BSP_SMALL_MEMORY

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