source: rtems/testsuites/support/src/locked_print.c @ 7e102915

5
Last change on this file since 7e102915 was 7e102915, checked in by Sebastian Huber <sebastian.huber@…>, on 10/26/17 at 11:59:09

tests: Use rtems_test_printer in general

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include "test_support.h"
15#include "tmacros.h"
16
17#include <rtems/bspIo.h>
18
19static rtems_id locked_print_semaphore;      /* synchronisation semaphore */
20
21static int locked_printf_plugin(void *context, const char *fmt, va_list ap)
22{
23  (void) context;
24  return locked_vprintf(fmt, ap);
25}
26
27void locked_print_initialize(void)
28{
29  rtems_status_code sc;
30  static            bool initted = false;
31
32  if ( initted )
33    return;
34
35  initted = true;
36
37  /* Create/verify synchronisation semaphore */
38  sc = rtems_semaphore_create(
39    rtems_build_name ('S', 'E', 'M', '1'),
40    1,
41    RTEMS_LOCAL                   |
42    RTEMS_BINARY_SEMAPHORE |
43    RTEMS_PRIORITY_CEILING |
44    RTEMS_PRIORITY,
45    1,
46    &locked_print_semaphore
47  );
48  directive_failed( sc, "rtems_semaphore_create" );
49
50  /*
51   * Set up the printer to use the locked printf printer.
52   */
53  rtems_test_printer.context = NULL;
54  rtems_test_printer.printer = locked_printf_plugin;
55}
56
57int locked_vprintf(const char *fmt, va_list ap)
58{
59  int rv;
60  rtems_status_code sc;
61
62  locked_print_initialize();
63
64  /* Lock semaphore without releasing the cpu */
65  do {
66    sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
67  } while (sc != RTEMS_SUCCESSFUL );
68
69  rv = vprintf(fmt, ap);
70
71  /* Release the semaphore  */
72  rtems_semaphore_release( locked_print_semaphore );
73
74  return rv;
75}
76
77int locked_printf(const char *fmt, ...)
78{
79  int               rv;
80  va_list           ap;       /* points to each unnamed argument in turn */
81
82  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
83  rv = locked_vprintf(fmt, ap);
84  va_end(ap);        /* clean up when done */
85
86  return rv;
87}
88
89void locked_printk(const char *fmt, ...)
90{
91  va_list           ap;       /* points to each unnamed argument in turn */
92  rtems_status_code sc;
93
94
95  locked_print_initialize();
96
97  /* Lock semaphore without releasing the cpu */
98  do {
99    sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
100  } while (sc != RTEMS_SUCCESSFUL );
101
102  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
103  vprintk(fmt, ap);
104  va_end(ap);        /* clean up when done */
105
106  /* Release the semaphore  */
107  rtems_semaphore_release( locked_print_semaphore );
108}
Note: See TracBrowser for help on using the repository browser.