source: rtems/testsuites/support/include/buffer_test_io.h @ 8f71a36

4.104.114.84.9
Last change on this file since 8f71a36 was 8f71a36, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 20, 2004 at 7:09:31 AM

Remove stray white spaces.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 *  Support for running the test output through a buffer
3 *
4 *  $Id$
5 */
6
7#ifndef __BUFFER_TEST_IO_h
8#define __BUFFER_TEST_IO_h
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#include <stdlib.h>
15
16/*
17 *  Uncomment this to get buffered test output.  When commented out,
18 *  test output behaves as it always has and is printed ASAP.
19 */
20
21/* #define TESTS_BUFFER_OUTPUT */
22
23#if !defined(TESTS_BUFFER_OUTPUT)
24
25/* do not use iprintf if strict ansi mode */
26#ifndef __STRICT_ANSI__
27#undef printf
28#define printf(...) \
29  do { \
30     iprintf( __VA_ARGS__); \
31  } while (0)
32#endif
33
34#define rtems_test_exit(_s) \
35  do { \
36    exit(_s); \
37  } while (0)
38
39#define FLUSH_OUTPUT() \
40  do { \
41    fflush(stdout); \
42  } while (0)
43
44#else  /* buffer test output */
45
46#define _TEST_OUTPUT_BUFFER_SIZE 2048
47extern char _test_output_buffer[_TEST_OUTPUT_BUFFER_SIZE];
48void _test_output_append(char *);
49void _test_output_flush(void);
50
51#define rtems_test_exit(_s) \
52  do { \
53    _test_output_flush(); \
54    exit(_s); \
55  } while (0)
56
57#undef printf
58#define printf(...) \
59  do { \
60     char _buffer[128]; \
61     sprintf( _buffer, __VA_ARGS__); \
62     _test_output_append( _buffer ); \
63  } while (0)
64
65#undef puts
66#define puts(_string) \
67  do { \
68     char _buffer[128]; \
69     sprintf( _buffer, "%s\n", _string ); \
70     _test_output_append( _buffer ); \
71  } while (0)
72
73#undef putchar
74#define putchar(_c) \
75  do { \
76     char _buffer[2]; \
77     _buffer[0] = _c; \
78     _buffer[1] = '\0'; \
79     _test_output_append( _buffer ); \
80  } while (0)
81
82/* we write to stderr when there is a pause() */
83#define FLUSH_OUTPUT() _test_output_flush()
84
85#if defined(TEST_INIT) || defined(CONFIGURE_INIT)
86
87char _test_output_buffer[_TEST_OUTPUT_BUFFER_SIZE];
88int _test_output_buffer_index = 0;
89
90void _test_output_append(char *_buffer)
91{
92  char *p;
93
94  for ( p=_buffer ; *p ; p++ ) {
95    _test_output_buffer[_test_output_buffer_index++] = *p;
96    _test_output_buffer[_test_output_buffer_index]   = '\0';
97#if 0
98    if ( *p == '\n' ) {
99      fprintf( stderr, "BUFFER -- %s", _test_output_buffer );
100      _test_output_buffer_index = 0;
101     _test_output_buffer[0]   = '\0';
102    }
103#endif
104    if ( _test_output_buffer_index >= (_TEST_OUTPUT_BUFFER_SIZE - 80) )
105      _test_output_flush();
106  }
107}
108
109#include <termios.h>
110#include <unistd.h>
111
112void _test_output_flush(void)
113{
114  fprintf( stderr, "%s", _test_output_buffer );
115  _test_output_buffer_index = 0;
116  tcdrain( 2 );
117}
118
119#endif  /* TEST_INIT */
120#endif /* TESTS_BUFFER_OUTPUT */
121
122#ifdef __cplusplus
123};
124#endif
125
126#endif
Note: See TracBrowser for help on using the repository browser.