source: rtems/testsuites/libtests/capture01/test1.c @ 82d137ae

4.11
Last change on this file since 82d137ae was 82d137ae, checked in by Jennifer Averett <jennifer.averett@…>, on Apr 23, 2014 at 8:08:26 PM

capture01: New non-interactive test for capture engine.

  • Property mode set to 100644
File size: 6.1 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
28#if !BSP_SMALL_MEMORY
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
112void capture_test_1 ()
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    fprintf (stdout, "error: Test 1: cannot mutex: %s\n",
134             rtems_status_text (sc));
135    return;
136  }
137
138  name = rtems_build_name('C', 'T', '1', 'a');
139
140  sc = rtems_task_create (name, 102, 2 * 1024,
141                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
142                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
143                          &id[0]);
144
145  if (sc != RTEMS_SUCCESSFUL)
146  {
147    fprintf (stdout, "error: Test 1: cannot create CT1a: %s\n",
148             rtems_status_text (sc));
149    rtems_semaphore_delete (mutex);
150    return;
151  }
152
153  sc = rtems_task_start (id[0], capture_CT1a, (rtems_task_argument) mutex);
154
155  if (sc != RTEMS_SUCCESSFUL)
156  {
157    fprintf (stdout, "error: Test 1: cannot start CT1a: %s\n",
158             rtems_status_text (sc));
159    rtems_task_delete (id[0]);
160    rtems_semaphore_delete (mutex);
161    return;
162  }
163
164  capture_wait (1000);
165
166  name = rtems_build_name('C', 'T', '1', 'b');
167
168  sc = rtems_task_create (name, 101, 2 * 1024,
169                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
170                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
171                          &id[1]);
172
173  if (sc != RTEMS_SUCCESSFUL)
174  {
175    fprintf (stdout, "error: Test 1: cannot create CT1b: %s\n",
176             rtems_status_text (sc));
177    rtems_task_delete (id[0]);
178    rtems_semaphore_delete (mutex);
179    return;
180  }
181
182  sc = rtems_task_start (id[1], capture_CT1b, 0);
183
184  if (sc != RTEMS_SUCCESSFUL)
185  {
186    fprintf (stdout, "error: Test 1: cannot start CT1b: %s\n",
187             rtems_status_text (sc));
188    rtems_task_delete (id[1]);
189    rtems_task_delete (id[0]);
190    rtems_semaphore_delete (mutex);
191    return;
192  }
193
194  capture_wait (1000);
195
196  name = rtems_build_name('C', 'T', '1', 'c');
197
198  sc = rtems_task_create (name, 100, 2 * 1024,
199                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
200                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
201                          &id[2]);
202
203  if (sc != RTEMS_SUCCESSFUL)
204  {
205    fprintf (stdout, "error: Test 1: cannot create CT1c: %s\n",
206             rtems_status_text (sc));
207    rtems_task_delete (id[1]);
208    rtems_task_delete (id[0]);
209    rtems_semaphore_delete (mutex);
210    return;
211  }
212
213  sc = rtems_task_start (id[2], capture_CT1c, (rtems_task_argument) mutex);
214
215  if (sc != RTEMS_SUCCESSFUL)
216  {
217    fprintf (stdout, "error: Test 1: cannot start CT1c: %s\n",
218             rtems_status_text (sc));
219    rtems_task_delete (id[2]);
220    rtems_task_delete (id[1]);
221    rtems_task_delete (id[0]);
222    rtems_semaphore_delete (mutex);
223    return;
224  }
225
226  loops = 15;
227
228  while (!(capture_CT1a_deleted || capture_CT1b_deleted ||
229           capture_CT1c_deleted) && loops)
230  {
231    loops--;
232    capture_wait (1000);
233  }
234
235  if (!loops)
236  {
237    fprintf (stdout, "error: Test 1: test tasks did not delete\n");
238    rtems_task_delete (id[2]);
239    rtems_task_delete (id[1]);
240    rtems_task_delete (id[0]);
241  }
242
243  sc = rtems_semaphore_delete (mutex);
244  if (sc != RTEMS_SUCCESSFUL)
245    fprintf (stdout, "error: Test 1: deleting the mutex: %s\n",
246             rtems_status_text (sc));
247
248}
249
250#endif /* BSP_SMALL_MEMORY */
Note: See TracBrowser for help on using the repository browser.