OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [support/] [include/] [buffer_test_io.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  Support for running the test output through a buffer
3
 *
4
 *  buffer_test_io.h,v 1.1 2002/08/02 00:51:52 joel Exp
5
 */
6
 
7
#ifndef __BUFFER_TEST_IO_h
8
#define __BUFFER_TEST_IO_h
9
 
10
#ifdef __cplusplus
11
extern "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
38
extern char _test_output_buffer[_TEST_OUTPUT_BUFFER_SIZE];
39
void _test_output_append(char *);
40
void _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
 
78
char _test_output_buffer[_TEST_OUTPUT_BUFFER_SIZE];
79
int _test_output_buffer_index = 0;
80
 
81
void _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
 
103
void _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

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.