source: rtems/testsuites/libtests/capture01/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: 5.8 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    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
108void capture_test_1 ()
109{
110  rtems_status_code sc;
111  rtems_name        name;
112  rtems_id          id[3];
113  rtems_id          mutex;
114  int               loops;
115
116  capture_CT1a_deleted = 0;
117  capture_CT1b_deleted = 0;
118  capture_CT1c_deleted = 0;
119
120  name = rtems_build_name('C', 'T', 'm', '1');
121
122  sc = rtems_semaphore_create (name, 1,
123                               RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE |
124                               RTEMS_INHERIT_PRIORITY,
125                               0, &mutex);
126
127  if (sc != RTEMS_SUCCESSFUL)
128  {
129    printf ("error: Test 1: cannot mutex: %s\n", rtems_status_text (sc));
130    return;
131  }
132
133  name = rtems_build_name('C', 'T', '1', 'a');
134
135  sc = rtems_task_create (name, 102, 2 * 1024,
136                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
137                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
138                          &id[0]);
139
140  if (sc != RTEMS_SUCCESSFUL)
141  {
142    printf ("error: Test 1: cannot create CT1a: %s\n", rtems_status_text (sc));
143    rtems_semaphore_delete (mutex);
144    return;
145  }
146
147  sc = rtems_task_start (id[0], capture_CT1a, (rtems_task_argument) mutex);
148
149  if (sc != RTEMS_SUCCESSFUL)
150  {
151    printf ("error: Test 1: cannot start CT1a: %s\n", rtems_status_text (sc));
152    rtems_task_delete (id[0]);
153    rtems_semaphore_delete (mutex);
154    return;
155  }
156
157  capture_wait (1000);
158
159  name = rtems_build_name('C', 'T', '1', 'b');
160
161  sc = rtems_task_create (name, 101, 2 * 1024,
162                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
163                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
164                          &id[1]);
165
166  if (sc != RTEMS_SUCCESSFUL)
167  {
168    printf ("error: Test 1: cannot create CT1b: %s\n", rtems_status_text (sc));
169    rtems_task_delete (id[0]);
170    rtems_semaphore_delete (mutex);
171    return;
172  }
173
174  sc = rtems_task_start (id[1], capture_CT1b, 0);
175
176  if (sc != RTEMS_SUCCESSFUL)
177  {
178    printf ("error: Test 1: cannot start CT1b: %s\n", rtems_status_text (sc));
179    rtems_task_delete (id[1]);
180    rtems_task_delete (id[0]);
181    rtems_semaphore_delete (mutex);
182    return;
183  }
184
185  capture_wait (1000);
186
187  name = rtems_build_name('C', 'T', '1', 'c');
188
189  sc = rtems_task_create (name, 100, 2 * 1024,
190                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
191                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
192                          &id[2]);
193
194  if (sc != RTEMS_SUCCESSFUL)
195  {
196    printf ("error: Test 1: cannot create CT1c: %s\n", rtems_status_text (sc));
197    rtems_task_delete (id[1]);
198    rtems_task_delete (id[0]);
199    rtems_semaphore_delete (mutex);
200    return;
201  }
202
203  sc = rtems_task_start (id[2], capture_CT1c, (rtems_task_argument) mutex);
204
205  if (sc != RTEMS_SUCCESSFUL)
206  {
207    printf ("error: Test 1: cannot start CT1c: %s\n", rtems_status_text (sc));
208    rtems_task_delete (id[2]);
209    rtems_task_delete (id[1]);
210    rtems_task_delete (id[0]);
211    rtems_semaphore_delete (mutex);
212    return;
213  }
214
215  loops = 15;
216
217  while (!(capture_CT1a_deleted || capture_CT1b_deleted ||
218           capture_CT1c_deleted) && loops)
219  {
220    loops--;
221    capture_wait (1000);
222  }
223
224  if (!loops)
225  {
226    printf ("error: Test 1: test tasks did not delete\n");
227    rtems_task_delete (id[2]);
228    rtems_task_delete (id[1]);
229    rtems_task_delete (id[0]);
230  }
231
232  sc = rtems_semaphore_delete (mutex);
233  if (sc != RTEMS_SUCCESSFUL)
234    printf ("error: Test 1: deleting the mutex: %s\n", rtems_status_text (sc));
235
236}
237
238#endif /* BSP_SMALL_MEMORY */
Note: See TracBrowser for help on using the repository browser.