source: rtems/testsuites/samples/capture/test1.c @ 8c1f4064

Last change on this file since 8c1f4064 was 8c1f4064, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 2, 2017 at 12:56:12 PM

tests: Use printf() instead of fprintf()

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 6.4 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    printf ("error: CT1a: mutex obtain: %s\n", rtems_status_text (sc));
59
60  capture_wait (2500);
61
62  sc = rtems_semaphore_release (mutex);
63
64  if (sc != RTEMS_SUCCESSFUL)
65    printf ("error: CT1a: mutex release: %s\n", 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    printf ("error: CT1c: mutex obtain: %s\n", rtems_status_text (sc));
95
96  capture_wait (500);
97
98  sc = rtems_semaphore_release (mutex);
99
100  if (sc != RTEMS_SUCCESSFUL)
101    printf ("error: CT1c: mutex release: %s\n", rtems_status_text (sc));
102
103  capture_CT1c_deleted = 1;
104
105  rtems_task_delete (RTEMS_SELF);
106}
107
108static void
109capture_test_1 (int                                argc,
110                char**                             argv,
111                const rtems_monitor_command_arg_t* command_arg,
112                bool                               verbose)
113{
114  rtems_status_code sc;
115  rtems_name        name;
116  rtems_id          id[3];
117  rtems_id          mutex;
118  int               loops;
119
120  capture_CT1a_deleted = 0;
121  capture_CT1b_deleted = 0;
122  capture_CT1c_deleted = 0;
123
124  name = rtems_build_name('C', 'T', 'm', '1');
125
126  sc = rtems_semaphore_create (name, 1,
127                               RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE |
128                               RTEMS_INHERIT_PRIORITY,
129                               0, &mutex);
130
131  if (sc != RTEMS_SUCCESSFUL)
132  {
133    printf ("error: Test 1: cannot mutex: %s\n", rtems_status_text (sc));
134    return;
135  }
136
137  name = rtems_build_name('C', 'T', '1', 'a');
138
139  sc = rtems_task_create (name, 102, 2 * 1024,
140                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
141                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
142                          &id[0]);
143
144  if (sc != RTEMS_SUCCESSFUL)
145  {
146    printf ("error: Test 1: cannot create CT1a: %s\n", rtems_status_text (sc));
147    rtems_semaphore_delete (mutex);
148    return;
149  }
150
151  sc = rtems_task_start (id[0], capture_CT1a, (rtems_task_argument) mutex);
152
153  if (sc != RTEMS_SUCCESSFUL)
154  {
155    printf ("error: Test 1: cannot start CT1a: %s\n", rtems_status_text (sc));
156    rtems_task_delete (id[0]);
157    rtems_semaphore_delete (mutex);
158    return;
159  }
160
161  capture_wait (1000);
162
163  name = rtems_build_name('C', 'T', '1', 'b');
164
165  sc = rtems_task_create (name, 101, 2 * 1024,
166                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
167                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
168                          &id[1]);
169
170  if (sc != RTEMS_SUCCESSFUL)
171  {
172    printf ("error: Test 1: cannot create CT1b: %s\n", rtems_status_text (sc));
173    rtems_task_delete (id[0]);
174    rtems_semaphore_delete (mutex);
175    return;
176  }
177
178  sc = rtems_task_start (id[1], capture_CT1b, 0);
179
180  if (sc != RTEMS_SUCCESSFUL)
181  {
182    printf ("error: Test 1: cannot start CT1b: %s\n", rtems_status_text (sc));
183    rtems_task_delete (id[1]);
184    rtems_task_delete (id[0]);
185    rtems_semaphore_delete (mutex);
186    return;
187  }
188
189  capture_wait (1000);
190
191  name = rtems_build_name('C', 'T', '1', 'c');
192
193  sc = rtems_task_create (name, 100, 2 * 1024,
194                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
195                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
196                          &id[2]);
197
198  if (sc != RTEMS_SUCCESSFUL)
199  {
200    printf ("error: Test 1: cannot create CT1c: %s\n", rtems_status_text (sc));
201    rtems_task_delete (id[1]);
202    rtems_task_delete (id[0]);
203    rtems_semaphore_delete (mutex);
204    return;
205  }
206
207  sc = rtems_task_start (id[2], capture_CT1c, (rtems_task_argument) mutex);
208
209  if (sc != RTEMS_SUCCESSFUL)
210  {
211    printf ("error: Test 1: cannot start CT1c: %s\n", rtems_status_text (sc));
212    rtems_task_delete (id[2]);
213    rtems_task_delete (id[1]);
214    rtems_task_delete (id[0]);
215    rtems_semaphore_delete (mutex);
216    return;
217  }
218
219  loops = 15;
220
221  while (!(capture_CT1a_deleted || capture_CT1b_deleted ||
222           capture_CT1c_deleted) && loops)
223  {
224    loops--;
225    capture_wait (1000);
226  }
227
228  if (!loops)
229  {
230    printf ("error: Test 1: test tasks did not delete\n");
231    rtems_task_delete (id[2]);
232    rtems_task_delete (id[1]);
233    rtems_task_delete (id[0]);
234  }
235
236  sc = rtems_semaphore_delete (mutex);
237  if (sc != RTEMS_SUCCESSFUL)
238    printf ("error: Test 1: deleting the mutex: %s\n", rtems_status_text (sc));
239}
240
241static rtems_monitor_command_entry_t capture_cmds[] =
242{
243  {
244    "test1",
245    "usage: \n",
246    0,
247    capture_test_1,
248    { 0 },
249    0
250  }
251};
252
253void setup_tasks_to_watch (void)
254{
255  size_t cmd;
256  for (cmd = 0;
257       cmd < sizeof (capture_cmds) / sizeof (rtems_monitor_command_entry_t);
258       cmd++)
259      rtems_monitor_insert_cmd (&capture_cmds[cmd]);
260}
Note: See TracBrowser for help on using the repository browser.