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

4.11
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

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