2007-05-11 Joel Sherrill <joel.sherrill@OARcorp.com>

* support/include/buffer_test_io.h: Add support for using printk for
	output in tests. This should be followed up by disabling the console
	driver and other support when the tests are using printk.
This commit is contained in:
Joel Sherrill
2007-05-11 19:53:29 +00:00
parent 9de4e5be47
commit 71531a6fa0
2 changed files with 155 additions and 85 deletions

View File

@@ -1,3 +1,9 @@
2007-05-11 Joel Sherrill <joel.sherrill@OARcorp.com>
* support/include/buffer_test_io.h: Add support for using printk for
output in tests. This should be followed up by disabling the console
driver and other support when the tests are using printk.
2007-02-11 Ralf Corsépius <ralf.corsepius@rtems.org> 2007-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
* aclocal/check-cpuopts.m4: Check rtems/system.h instead of * aclocal/check-cpuopts.m4: Check rtems/system.h instead of

View File

@@ -11,67 +11,86 @@
extern "C" { extern "C" {
#endif #endif
#include <stdlib.h>
/* /*
* Uncomment this to get buffered test output. When commented out, * Uncomment this to get buffered test output. When commented out,
* test output behaves as it always has and is printed ASAP. * test output behaves as it always has and is printed using stdio.
*/ */
/* #define TESTS_BUFFER_OUTPUT */ /* #define TESTS_BUFFER_OUTPUT */
/* #define TESTS_USE_PRINTK */
#if !defined(TESTS_BUFFER_OUTPUT) /*
* USE PRINTK TO MINIMIZE SIZE
*/
#if defined(TESTS_USE_PRINTK)
/* do not use iprintf if strict ansi mode */ #include <rtems/bspIo.h>
#if defined(_NEWLIB_VERSION) && !defined(__STRICT_ANSI__)
#undef printf #undef printf
#define printf(...) \ #define printf(...) \
do { \ do { \
iprintf( __VA_ARGS__); \ printk( __VA_ARGS__); \
} while (0)
#endif
#define rtems_test_exit(_s) \
do { \
exit(_s); \
} while (0) } while (0)
#define FLUSH_OUTPUT() \ #undef puts
#define puts(_s) \
do { \ do { \
fflush(stdout); \ printk( "%s\n", _s); \
} while (0) } while (0)
#else /* buffer test output */ #undef putchar
#define putchar(_c) \
do { \
printk( "%c", _c ); \
} while (0)
#define _TEST_OUTPUT_BUFFER_SIZE 2048 /* Do not call exit() since it closes stdin, etc and pulls in stdio code */
extern char _test_output_buffer[_TEST_OUTPUT_BUFFER_SIZE]; #define rtems_test_exit(_s) \
void _test_output_append(char *); do { \
void _test_output_flush(void); rtems_shutdown_executive(0); \
} while (0)
#define rtems_test_exit(_s) \ #define FLUSH_OUTPUT() \
do { \
} while (0)
/*
* BUFFER TEST OUTPUT
*/
#elif defined(TESTS_BUFFER_OUTPUT)
#include <stdio.h>
#include <stdlib.h>
#define _TEST_OUTPUT_BUFFER_SIZE 2048
extern char _test_output_buffer[_TEST_OUTPUT_BUFFER_SIZE];
void _test_output_append(char *);
void _test_output_flush(void);
#define rtems_test_exit(_s) \
do { \ do { \
_test_output_flush(); \ _test_output_flush(); \
exit(_s); \ exit(_s); \
} while (0) } while (0)
#undef printf #undef printf
#define printf(...) \ #define printf(...) \
do { \ do { \
char _buffer[128]; \ char _buffer[128]; \
sprintf( _buffer, __VA_ARGS__); \ sprintf( _buffer, __VA_ARGS__); \
_test_output_append( _buffer ); \ _test_output_append( _buffer ); \
} while (0) } while (0)
#undef puts #undef puts
#define puts(_string) \ #define puts(_string) \
do { \ do { \
char _buffer[128]; \ char _buffer[128]; \
sprintf( _buffer, "%s\n", _string ); \ sprintf( _buffer, "%s\n", _string ); \
_test_output_append( _buffer ); \ _test_output_append( _buffer ); \
} while (0) } while (0)
#undef putchar #undef putchar
#define putchar(_c) \ #define putchar(_c) \
do { \ do { \
char _buffer[2]; \ char _buffer[2]; \
_buffer[0] = _c; \ _buffer[0] = _c; \
@@ -79,45 +98,90 @@ void _test_output_flush(void);
_test_output_append( _buffer ); \ _test_output_append( _buffer ); \
} while (0) } while (0)
/* we write to stderr when there is a pause() */ /* we write to stderr when there is a pause() */
#define FLUSH_OUTPUT() _test_output_flush() #define FLUSH_OUTPUT() _test_output_flush()
#if defined(TEST_INIT) || defined(CONFIGURE_INIT) #if defined(TEST_INIT) || defined(CONFIGURE_INIT)
char _test_output_buffer[_TEST_OUTPUT_BUFFER_SIZE]; char _test_output_buffer[_TEST_OUTPUT_BUFFER_SIZE];
int _test_output_buffer_index = 0; int _test_output_buffer_index = 0;
void _test_output_append(char *_buffer) void _test_output_append(char *_buffer)
{ {
char *p; char *p;
for ( p=_buffer ; *p ; p++ ) { for ( p=_buffer ; *p ; p++ ) {
_test_output_buffer[_test_output_buffer_index++] = *p; _test_output_buffer[_test_output_buffer_index++] = *p;
_test_output_buffer[_test_output_buffer_index] = '\0'; _test_output_buffer[_test_output_buffer_index] = '\0';
#if 0 #if 0
if ( *p == '\n' ) { if ( *p == '\n' ) {
fprintf( stderr, "BUFFER -- %s", _test_output_buffer ); fprintf( stderr, "BUFFER -- %s", _test_output_buffer );
_test_output_buffer_index = 0; _test_output_buffer_index = 0;
_test_output_buffer[0] = '\0'; _test_output_buffer[0] = '\0';
} }
#endif #endif
if ( _test_output_buffer_index >= (_TEST_OUTPUT_BUFFER_SIZE - 80) ) if ( _test_output_buffer_index >= (_TEST_OUTPUT_BUFFER_SIZE - 80) )
_test_output_flush(); _test_output_flush();
} }
} }
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
void _test_output_flush(void) void _test_output_flush(void)
{ {
fprintf( stderr, "%s", _test_output_buffer ); fprintf( stderr, "%s", _test_output_buffer );
_test_output_buffer_index = 0; _test_output_buffer_index = 0;
tcdrain( 2 ); tcdrain( 2 );
} }
#endif /* TEST_INIT */ #endif
#endif /* TESTS_BUFFER_OUTPUT */ /*
* USE IPRINT
*/
#else
#include <stdio.h>
#include <stdlib.h>
/* do not use iprintf if strict ansi mode */
#if defined(_NEWLIB_VERSION) && !defined(__STRICT_ANSI__)
#undef printf
#define printf(...) \
do { \
fiprintf( stderr, __VA_ARGS__ ); \
} while (0)
#else
#undef printf
#define printf(...) \
do { \
fprintf( stderr, __VA_ARGS__ ); \
} while (0)
#endif
#undef puts
#define puts(_s) \
do { \
printf( "%s\n", _s ); \
} while (0)
#undef putchar
#define putchar(_c) \
do { \
printf( "%c", _c ); \
} while (0)
#define rtems_test_exit(_s) \
do { \
exit(_s); \
} while (0)
#define FLUSH_OUTPUT() \
do { \
fflush(stdout); \
} while (0)
#endif
#ifdef __cplusplus #ifdef __cplusplus
}; };