source: rtems/c/src/tests/support/include/buffer_test_io.h @ cd9396e

4.104.114.84.95
Last change on this file since cd9396e was cd9396e, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 2, 2002 at 12:51:52 AM

2002-08-01 Joel Sherrill <joel@…>

  • Per PR47 add support for buffered test output. This involved adding defines to redirect output to a buffer and dump it when full, at "test pause", and at exit. To avoid problems when redefining exit(), all tests were modified to call rtems_test_exit(). Some tests, notable psxtests, had to be modified to include the standard test macro .h file (pmacros.h or tmacros.h) to enable this support.
  • include/buffer_test_io.h: New file.
  • Property mode set to 100644
File size: 2.3 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#define rtems_test_exit(_s) \
26  do { \
27    exit(_s); \
28  } while (0)
29
30#define FLUSH_OUTPUT() \
31  do { \
32    fflush(stdout); \
33  } while (0)
34
35#else  /* buffer test output */
36
37#define _TEST_OUTPUT_BUFFER_SIZE 2048
38extern char _test_output_buffer[_TEST_OUTPUT_BUFFER_SIZE];
39void _test_output_append(char *);
40void _test_output_flush(void);
41
42#define rtems_test_exit(_s) \
43  do { \
44    _test_output_flush(); \
45    exit(_s); \
46  } while (0)
47
48#undef printf
49#define printf(...) \
50  do { \
51     char _buffer[128]; \
52     sprintf( _buffer, __VA_ARGS__); \
53     _test_output_append( _buffer ); \
54  } while (0)
55
56#undef puts
57#define puts(_string) \
58  do { \
59     char _buffer[128]; \
60     sprintf( _buffer, "%s\n", _string ); \
61     _test_output_append( _buffer ); \
62  } while (0)
63
64#undef putchar
65#define putchar(_c) \
66  do { \
67     char _buffer[2]; \
68     _buffer[0] = _c; \
69     _buffer[1] = '\0'; \
70     _test_output_append( _buffer ); \
71  } while (0)
72
73/* we write to stderr when there is a pause() */
74#define FLUSH_OUTPUT() _test_output_flush()
75
76#if defined(TEST_INIT) || defined(CONFIGURE_INIT)
77
78char _test_output_buffer[_TEST_OUTPUT_BUFFER_SIZE];
79int _test_output_buffer_index = 0;
80
81void _test_output_append(char *_buffer)
82{
83  char *p;
84 
85  for ( p=_buffer ; *p ; p++ ) {
86    _test_output_buffer[_test_output_buffer_index++] = *p;
87    _test_output_buffer[_test_output_buffer_index]   = '\0';
88#if 0
89    if ( *p == '\n' ) {
90      fprintf( stderr, "BUFFER -- %s", _test_output_buffer );
91      _test_output_buffer_index = 0;
92     _test_output_buffer[0]   = '\0';
93    }
94#endif
95    if ( _test_output_buffer_index >= (_TEST_OUTPUT_BUFFER_SIZE - 80) ) 
96      _test_output_flush();
97  }
98}
99
100#include <termios.h>
101#include <unistd.h>
102
103void _test_output_flush(void)
104{
105  fprintf( stderr, "%s", _test_output_buffer );
106  _test_output_buffer_index = 0;
107  tcdrain( 2 );
108}
109
110#endif  /* TEST_INIT */
111#endif /* TESTS_BUFFER_OUTPUT */
112
113#ifdef __cplusplus
114}
115#endif
116
117#endif
Note: See TracBrowser for help on using the repository browser.