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

4.115
Last change on this file since 82d137ae was 82d137ae, checked in by Jennifer Averett <jennifer.averett@…>, on 04/23/14 at 20:08:26

capture01: New non-interactive test for capture engine.

  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may in
6 *  the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#define CONFIGURE_INIT
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include "system.h"
17#include <ctype.h>
18#include <stdlib.h>
19#include <stdio.h>
20#include <string.h>
21#include <inttypes.h>
22
23#include <rtems.h>
24#include <rtems/capture-cli.h>
25#include <rtems/monitor.h>
26#include <rtems/shell.h>
27
28#define ASSERT_SC(sc) assert((sc) == RTEMS_SUCCESSFUL)
29
30/* forward declarations to avoid warnings */
31rtems_task Init(rtems_task_argument argument);
32
33const char rtems_test_name[] = "CAPTURE ENGINE";
34
35static void cwlist(void);
36static void ctrace(void);
37
38static void cwlist ()
39{
40  rtems_capture_control_t* control = rtems_capture_get_control_list ();
41  rtems_task_priority      ceiling = rtems_capture_watch_get_ceiling ();
42  rtems_task_priority      floor = rtems_capture_watch_get_floor ();
43
44  fprintf (stdout, "watch priority ceiling is %" PRId32 "\n", ceiling);
45  fprintf (stdout, "watch priority floor is %" PRId32 "\n", floor);
46  fprintf (stdout, "global watch is %s\n",
47          rtems_capture_watch_global_on () ? "enabled" : "disabled");
48  fprintf (stdout, "total %" PRId32 "\n", rtems_capture_control_count ());
49
50  while (control)
51  {
52    uint32_t flags;
53    int      f;
54    int      fshowed;
55    int      lf;
56
57    fprintf (stdout, " ");
58    rtems_monitor_dump_id (rtems_capture_control_id (control));
59    fprintf (stdout, " ");
60    rtems_monitor_dump_name (rtems_capture_control_name (control));
61    flags = rtems_capture_control_flags (control);
62    fprintf (stdout, " %c%c ",
63             rtems_capture_watch_global_on () ? 'g' : '-',
64             flags & RTEMS_CAPTURE_WATCH ? 'w' : '-');
65    flags = rtems_capture_control_to_triggers (control);
66    fprintf (stdout, " T:%c%c%c%c%c%c%c",
67             flags & RTEMS_CAPTURE_SWITCH    ? 'S' : '-',
68             flags & RTEMS_CAPTURE_CREATE ? 'C' : '-',
69             flags & RTEMS_CAPTURE_START ? 'S' : '-',
70             flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
71             flags & RTEMS_CAPTURE_DELETE ? 'D' : '-',
72             flags & RTEMS_CAPTURE_BEGIN ? 'B' : '-',
73             flags & RTEMS_CAPTURE_EXITTED ? 'E' : '-');
74    flags = rtems_capture_control_from_triggers (control);
75    fprintf (stdout, " F:%c%c%c%c%c",
76             flags & RTEMS_CAPTURE_SWITCH  ? 'S' : '-',
77             flags & RTEMS_CAPTURE_CREATE  ? 'C' : '-',
78             flags & RTEMS_CAPTURE_START   ? 'S' : '-',
79             flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
80             flags & RTEMS_CAPTURE_DELETE  ? 'D' : '-');
81
82    for (f = 0, fshowed = 0, lf = 1; f < RTEMS_CAPTURE_TRIGGER_TASKS; f++)
83    {
84      if (rtems_capture_control_by_valid (control, f))
85      {
86        if (lf && ((fshowed % 3) == 0))
87        {
88          fprintf (stdout, "\n");
89          lf = 0;
90        }
91
92        fprintf (stdout, "  %2i:", f);
93        rtems_monitor_dump_name (rtems_capture_control_by_name (control, f));
94        fprintf (stdout, "/");
95        rtems_monitor_dump_id (rtems_capture_control_by_id (control, f));
96        flags = rtems_capture_control_by_triggers (control, f);
97        fprintf (stdout, ":%c%c%c%c%c",
98                 flags & RTEMS_CAPTURE_SWITCH  ? 'S' : '-',
99                 flags & RTEMS_CAPTURE_CREATE  ? 'C' : '-',
100                 flags & RTEMS_CAPTURE_START   ? 'S' : '-',
101                 flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
102                 flags & RTEMS_CAPTURE_DELETE  ? 'D' : '-');
103        fshowed++;
104        lf = 1;
105      }
106    }
107
108    if (lf)
109      fprintf (stdout, "\n");
110
111    control = rtems_capture_next_control (control);
112  }
113}
114
115static void ctrace()
116{
117  rtems_status_code       sc;
118  bool                    csv = false;
119  static int              dump_total = 22;
120  int                     total;
121  int                     count;
122  uint32_t                read;
123  rtems_capture_record_t* rec;
124
125  total = dump_total;
126
127  while (total)
128  {
129    sc = rtems_capture_read (0, 0, &read, &rec);
130
131    if (sc != RTEMS_SUCCESSFUL)
132    {
133      fprintf (stdout, "error: trace read failed: %s\n", rtems_status_text (sc));
134      rtems_capture_flush (0);
135      return;
136    }
137
138    /*
139     * If we have no records then just exist. We still need to release
140     * the reader lock.
141     */
142
143    if (read == 0)
144    {
145      rtems_capture_release (read);
146      break;
147    }
148
149    count = total < read ? total : read;
150
151    while (count--)
152    {
153      if (csv)
154        fprintf (stdout, "%08" PRIxPTR ",%03" PRIu32
155                   ",%03" PRIu32 ",%04" PRIx32 ",%" PRId64 "\n",
156                 (uintptr_t) rec->task,
157                 (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
158                 (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
159                 (rec->events >> RTEMS_CAPTURE_EVENT_START),
160                 (uint64_t) rec->time);
161      else
162      {
163        uint32_t event;
164        int      e;
165
166        event = rec->events >> RTEMS_CAPTURE_EVENT_START;
167
168        for (e = RTEMS_CAPTURE_EVENT_START; e <= RTEMS_CAPTURE_EVENT_END; e++)
169        {
170          if (event & 1)
171          {
172            rtems_monitor_dump_id (rtems_capture_task_id (rec->task));
173            fprintf (stdout, " %c%c%c%c",
174                     (char) (rec->task->name >> 24) & 0xff,
175                     (char) (rec->task->name >> 16) & 0xff,
176                     (char) (rec->task->name >> 8) & 0xff,
177                     (char) (rec->task->name >> 0) & 0xff);
178            fprintf (stdout, " %3" PRId32 " %3" PRId32 " %s\n",
179                    (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
180                    (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
181                    rtems_capture_event_text (e));
182          }
183          event >>= 1;
184        }
185      }
186      rec++;
187    }
188
189    count = total < read ? total : read;
190
191    if (count < total)
192      total -= count;
193    else
194      total = 0;
195
196    rtems_capture_release (count);
197  }
198}
199
200rtems_task Init(
201  rtems_task_argument ignored
202)
203{
204#if BSP_SMALL_MEMORY
205  printf("NO Capture Engine. MEMORY TOO SMALL");
206#else
207  rtems_status_code   sc;
208  rtems_task_priority old_priority;
209  rtems_mode          old_mode;
210  rtems_name          to_name = rtems_build_name('I', 'D', 'L', 'E');;
211
212  rtems_test_begin();
213
214  rtems_task_set_priority(RTEMS_SELF, 20, &old_priority);
215  rtems_task_mode(RTEMS_PREEMPT,  RTEMS_PREEMPT_MASK, &old_mode);
216
217  sc = rtems_capture_open (5000, NULL);
218  ASSERT_SC(sc);
219
220  sc = rtems_capture_watch_ceiling (100);
221  ASSERT_SC(sc);
222
223  sc = rtems_capture_watch_floor (102);
224  ASSERT_SC(sc);
225
226  sc = rtems_capture_watch_global (true);
227  ASSERT_SC(sc);
228
229  sc = rtems_capture_set_trigger (
230    0,
231    0,
232    to_name,
233    0,
234    rtems_capture_from_any,
235    rtems_capture_switch
236  );
237  ASSERT_SC(sc);
238
239  cwlist();
240
241  sc = rtems_capture_control (true);
242  ASSERT_SC(sc);
243
244  capture_test_1();
245 
246  ctrace();
247  ctrace();
248
249  rtems_test_end();
250  exit( 0 );
251
252#endif
253}
Note: See TracBrowser for help on using the repository browser.