source: rtems/testsuites/support/src/locked_print.c @ f703e7f

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

tests: Move rtems_test_printer definition

Statically initialize it to use printk().

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
17static rtems_id locked_print_semaphore;      /* synchronisation semaphore */
18
19static int locked_printf_plugin(void *context, const char *fmt, va_list ap)
20{
21  (void) context;
22  return locked_vprintf(fmt, ap);
23}
24
25void locked_print_initialize(void)
26{
27  rtems_status_code sc;
28  static            bool initted = false;
29
30  if ( initted )
31    return;
32
33  initted = true;
34
35  /* Create/verify synchronisation semaphore */
36  sc = rtems_semaphore_create(
37    rtems_build_name ('S', 'E', 'M', '1'),
38    1,
39    RTEMS_LOCAL                   |
40    RTEMS_BINARY_SEMAPHORE |
41    RTEMS_PRIORITY_CEILING |
42    RTEMS_PRIORITY,
43    1,
44    &locked_print_semaphore
45  );
46  directive_failed( sc, "rtems_semaphore_create" );
47
48  /*
49   * Set up the printer to use the locked printf printer.
50   */
51  rtems_test_printer.context = NULL;
52  rtems_test_printer.printer = locked_printf_plugin;
53}
54
55int locked_vprintf(const char *fmt, va_list ap)
56{
57  int rv;
58  rtems_status_code sc;
59
60  locked_print_initialize();
61
62  /* Lock semaphore without releasing the cpu */
63  do {
64    sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
65  } while (sc != RTEMS_SUCCESSFUL );
66
67  rv = vprintf(fmt, ap);
68
69  /* Release the semaphore  */
70  rtems_semaphore_release( locked_print_semaphore );
71
72  return rv;
73}
74
75int locked_printf(const char *fmt, ...)
76{
77  int               rv;
78  va_list           ap;       /* points to each unnamed argument in turn */
79
80  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
81  rv = locked_vprintf(fmt, ap);
82  va_end(ap);        /* clean up when done */
83
84  return rv;
85}
86
87void locked_printk(const char *fmt, ...)
88{
89  va_list           ap;       /* points to each unnamed argument in turn */
90  rtems_status_code sc;
91
92
93  locked_print_initialize();
94
95  /* Lock semaphore without releasing the cpu */
96  do {
97    sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
98  } while (sc != RTEMS_SUCCESSFUL );
99
100  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
101  vprintk(fmt, ap);
102  va_end(ap);        /* clean up when done */
103
104  /* Release the semaphore  */
105  rtems_semaphore_release( locked_print_semaphore );
106}
Note: See TracBrowser for help on using the repository browser.