[rtems commit] tests: Use ld to map (wrap) printf, puts and putchar to tester functions.
Chris Johns
chrisj at rtems.org
Sat Nov 11 05:23:58 UTC 2017
Module: rtems
Branch: master
Commit: e6df806a3f46b5488e5e383add9cda43e0059dbe
Changeset: http://git.rtems.org/rtems/commit/?id=e6df806a3f46b5488e5e383add9cda43e0059dbe
Author: Chris Johns <chrisj at rtems.org>
Date: Wed Nov 8 13:27:25 2017 +1100
tests: Use ld to map (wrap) printf, puts and putchar to tester functions.
- Remove the macro defines and the need for tmacro.h by remapping the
symbols using ld's wrap option.
- Remove FLUSH_OUTPUT, it was empty.
- Move rtems_test_exit to libmisc/testsupport as a function.
Update #3199.
---
cpukit/libmisc/Makefile.am | 1 +
cpukit/libmisc/testsupport/test.h | 6 ++++
cpukit/libmisc/testsupport/testbeginend.c | 6 ++++
cpukit/libmisc/testsupport/testwrappers.c | 48 +++++++++++++++++++++++++++++
testsuites/automake/compile.am | 5 +--
testsuites/automake/local.am | 2 ++
testsuites/libtests/rtmonuse/task1.c | 2 --
testsuites/sptests/sp14/asr.c | 2 --
testsuites/sptests/sp14/task1.c | 5 +--
testsuites/sptests/sp14/task2.c | 1 -
testsuites/support/include/buffer_test_io.h | 28 -----------------
testsuites/support/include/tmacros.h | 13 --------
12 files changed, 67 insertions(+), 52 deletions(-)
diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am
index 7867829..e1343dd 100644
--- a/cpukit/libmisc/Makefile.am
+++ b/cpukit/libmisc/Makefile.am
@@ -182,6 +182,7 @@ libtestsupport_a_SOURCES += testsupport/testbeginend.c
libtestsupport_a_SOURCES += testsupport/testbusy.c
libtestsupport_a_SOURCES += testsupport/testextension.c
libtestsupport_a_SOURCES += testsupport/testparallel.c
+libtestsupport_a_SOURCES += testsupport/testwrappers.c
## fsmount
noinst_LIBRARIES += libfsmount.a
diff --git a/cpukit/libmisc/testsupport/test.h b/cpukit/libmisc/testsupport/test.h
index 116b92d..2b4fcd1 100644
--- a/cpukit/libmisc/testsupport/test.h
+++ b/cpukit/libmisc/testsupport/test.h
@@ -105,6 +105,12 @@ int rtems_test_begin(const char* name, const RTEMS_TEST_STATE state);
int rtems_test_end(const char* name);
/**
+ * @brief Exit the test without calling exit() since it closes stdin, etc and
+ * pulls in stdio code
+ */
+void rtems_test_exit(int status);
+
+/**
* @brief Prints via the RTEMS printer.
*
* @returns As specified by printf().
diff --git a/cpukit/libmisc/testsupport/testbeginend.c b/cpukit/libmisc/testsupport/testbeginend.c
index 04748cb..f9dab4e 100644
--- a/cpukit/libmisc/testsupport/testbeginend.c
+++ b/cpukit/libmisc/testsupport/testbeginend.c
@@ -123,6 +123,12 @@ int rtems_test_end(const char* name)
);
}
+void rtems_test_exit(int status)
+{
+ (void) status;
+ rtems_shutdown_executive(0);
+}
+
int rtems_test_printf(
const char* format,
...
diff --git a/cpukit/libmisc/testsupport/testwrappers.c b/cpukit/libmisc/testsupport/testwrappers.c
new file mode 100644
index 0000000..c86c4cc
--- /dev/null
+++ b/cpukit/libmisc/testsupport/testwrappers.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017 Chris Johns <chrisj at rtems.org>. All rights reserved.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/test.h>
+
+int __wrap_printf(const char* format, ...);
+int __wrap_puts(const char *str);
+int __wrap_putchar(int c);
+
+int __wrap_printf(
+ const char* format,
+ ...
+)
+{
+ va_list ap;
+ int len;
+ va_start(ap, format);
+ len = rtems_vprintf(
+ &rtems_test_printer,
+ format,
+ ap
+ );
+ va_end(ap);
+ return len;
+}
+
+int __wrap_puts(
+ const char *str
+)
+{
+ return rtems_test_printf( "%s\n", str );
+}
+
+int __wrap_putchar(
+ int c
+)
+{
+ return rtems_test_printf( "%c", c );
+}
diff --git a/testsuites/automake/compile.am b/testsuites/automake/compile.am
index d5545c5..ee1f773 100644
--- a/testsuites/automake/compile.am
+++ b/testsuites/automake/compile.am
@@ -10,7 +10,8 @@ STRIP = @STRIP@
##
AM_CPPFLAGS = $(TEST_FLAGS)
-AM_CFLAGS =
-AM_CXXFLAGS =
+AM_CFLAGS = $(TEST_C_FLAGS)
+AM_CXXFLAGS = $(TEST_CXX_FLAGS)
+AM_LDFLAGS = $(TEST_LD_FLAGS)
CLEANFILES = *.num *.nxe *.elf *.srec* *.bin *.bt *.ralf
diff --git a/testsuites/automake/local.am b/testsuites/automake/local.am
index aaf86ac..3129902 100644
--- a/testsuites/automake/local.am
+++ b/testsuites/automake/local.am
@@ -2,3 +2,5 @@ preinstall:
.PHONY: preinstall
PROJECT_TOOLS = $(PROJECT_RELEASE)/build-tools
+
+TEST_LD_FLAGS = -Wl,--wrap=printf -Wl,--wrap=puts -Wl,--wrap=putchar
diff --git a/testsuites/libtests/rtmonuse/task1.c b/testsuites/libtests/rtmonuse/task1.c
index 9e8cf8f..b0db7fe 100644
--- a/testsuites/libtests/rtmonuse/task1.c
+++ b/testsuites/libtests/rtmonuse/task1.c
@@ -105,8 +105,6 @@ rtems_task Task_1_through_5(
printf( "TA5 - PERIODS CHECK OK (%" PRIu32 ")\n", pass );
- FLUSH_OUTPUT();
-
if ( pass == 10 ) {
puts( "" );
rtems_rate_monotonic_report_statistics();
diff --git a/testsuites/sptests/sp14/asr.c b/testsuites/sptests/sp14/asr.c
index e9187cc..4239a34 100644
--- a/testsuites/sptests/sp14/asr.c
+++ b/testsuites/sptests/sp14/asr.c
@@ -32,7 +32,6 @@ rtems_asr Process_asr(
case RTEMS_SIGNAL_0:
case RTEMS_SIGNAL_1:
puts( "ASR - rtems_task_wake_after - yield processor" );
- FLUSH_OUTPUT();
status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
directive_failed( status, "rtems_task_wake_after yield" );
break;
@@ -44,5 +43,4 @@ rtems_asr Process_asr(
"ASR - EXIT - signal => %08" PRIxrtems_signal_set "\n",
the_signal_set
);
- FLUSH_OUTPUT();
}
diff --git a/testsuites/sptests/sp14/task1.c b/testsuites/sptests/sp14/task1.c
index e71070d..7a8559d 100644
--- a/testsuites/sptests/sp14/task1.c
+++ b/testsuites/sptests/sp14/task1.c
@@ -52,9 +52,7 @@ rtems_task Task_1(
status = rtems_signal_catch( Process_asr, RTEMS_NO_ASR );
directive_failed( status, "rtems_signal_catch" );
- FLUSH_OUTPUT();
-
-rtems_test_pause();
+ rtems_test_pause();
puts( "TA1 - rtems_signal_send - RTEMS_SIGNAL_1 to self" );
status = rtems_signal_send( RTEMS_SELF, RTEMS_SIGNAL_1 );
@@ -98,7 +96,6 @@ rtems_test_pause();
);
puts( "TA1 - rtems_task_mode - enable ASRs" );
- FLUSH_OUTPUT();
status = rtems_task_mode( RTEMS_ASR, RTEMS_ASR_MASK, &previous_mode );
directive_failed( status, "rtems_task_mode" );
diff --git a/testsuites/sptests/sp14/task2.c b/testsuites/sptests/sp14/task2.c
index 9e1714f..da14dc8 100644
--- a/testsuites/sptests/sp14/task2.c
+++ b/testsuites/sptests/sp14/task2.c
@@ -44,7 +44,6 @@ rtems_task Task_2(
directive_failed( status, "rtems_signal_send" );
puts( "TA2 - rtems_task_wake_after - yield processor" );
- FLUSH_OUTPUT();
status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
directive_failed( status, "rtems_task_wake_after" );
diff --git a/testsuites/support/include/buffer_test_io.h b/testsuites/support/include/buffer_test_io.h
index 8fbcd68..ea68fea 100644
--- a/testsuites/support/include/buffer_test_io.h
+++ b/testsuites/support/include/buffer_test_io.h
@@ -11,34 +11,6 @@
extern "C" {
#endif
-#undef printf
-#define printf(...) \
- do { \
- rtems_printf( &rtems_test_printer, __VA_ARGS__ ); \
- } while (0)
-
-#undef puts
-#define puts(_s) \
- do { \
- rtems_printf( &rtems_test_printer, "%s\n", _s ); \
- } while (0)
-
-#undef putchar
-#define putchar(_c) \
- do { \
- rtems_printf( &rtems_test_printer, "%c", _c ); \
- } while (0)
-
-/* Do not call exit() since it closes stdin, etc and pulls in stdio code */
-#define rtems_test_exit(_s) \
- do { \
- rtems_shutdown_executive(0); \
- } while (0)
-
-#define FLUSH_OUTPUT() \
- do { \
- } while (0)
-
#define TEST_BEGIN() rtems_test_begin(rtems_test_name, TEST_STATE)
#define TEST_END() rtems_test_end(rtems_test_name)
diff --git a/testsuites/support/include/tmacros.h b/testsuites/support/include/tmacros.h
index 354d4cf..60da764 100644
--- a/testsuites/support/include/tmacros.h
+++ b/testsuites/support/include/tmacros.h
@@ -64,7 +64,6 @@ extern "C" {
"\n_Thread_Dispatch_disable_level is (%i)" \
" not %d detected at %s:%d\n", \
!_Thread_Dispatch_is_enabled(), (_expect), __FILE__, __LINE__ ); \
- FLUSH_OUTPUT(); \
rtems_test_exit( 1 ); \
} \
} while ( 0 )
@@ -84,7 +83,6 @@ extern "C" {
__FILE__, \
__LINE__ \
); \
- FLUSH_OUTPUT(); \
rtems_test_exit( 1 ); \
} \
} while ( 0 )
@@ -107,7 +105,6 @@ extern "C" {
if ( (_stat) != (_desired) ) { \
printf( "\n%s FAILED -- expected (%s) got (%s)\n", \
(_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \
- FLUSH_OUTPUT(); \
rtems_test_exit( _stat ); \
} \
} while ( 0 )
@@ -137,7 +134,6 @@ extern "C" {
printf( "\n%s FAILED -- expected (%d - %s) got (%ld %d - %s)\n", \
(_msg), _desired, strerror(_desired), \
statx, errno, strerror(errno) ); \
- FLUSH_OUTPUT(); \
rtems_test_exit( _stat ); \
}
@@ -153,7 +149,6 @@ extern "C" {
(_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \
printf( "\n FAILED -- errno (%d - %s)\n", \
errno, strerror(errno) ); \
- FLUSH_OUTPUT(); \
rtems_test_exit( _stat ); \
} \
} while ( 0 )
@@ -166,7 +161,6 @@ extern "C" {
check_dispatch_disable_level( 0 ); \
printf( "\n%s FAILED -- expected (-1) got (%p - %d/%s)\n", \
(_msg), _ptr, errno, strerror(errno) ); \
- FLUSH_OUTPUT(); \
rtems_test_exit( -1 ); \
}
@@ -178,7 +172,6 @@ extern "C" {
check_dispatch_disable_level( 0 ); \
printf( "\n%s FAILED -- expected (-1) got (%" PRId32 " - %d/%s)\n", \
(_msg), _ptr, errno, strerror(errno) ); \
- FLUSH_OUTPUT(); \
rtems_test_exit( -1 ); \
}
@@ -202,7 +195,6 @@ extern "C" {
if ( (_stat) != (_desired) ) { \
printf( "\n%s FAILED -- expected (%d) got (%d)\n", \
(_msg), (_desired), (_stat) ); \
- FLUSH_OUTPUT(); \
rtems_test_exit( _stat ); \
} \
} while ( 0 )
@@ -229,7 +221,6 @@ extern "C" {
#define put_dot( _c ) \
do { \
putchar( _c ); \
- FLUSH_OUTPUT(); \
} while ( 0 )
#define new_line puts( "" )
@@ -240,20 +231,17 @@ extern "C" {
#define rtems_test_pause() \
do { \
printf( "<pause>\n" ); \
- FLUSH_OUTPUT(); \
} while ( 0 )
#define rtems_test_pause_and_screen_number( _screen ) \
do { \
printf( "<pause - screen %d>\n", (_screen) ); \
- FLUSH_OUTPUT(); \
} while ( 0 )
#else
#define rtems_test_pause() \
do { \
char buffer[ 80 ]; \
printf( "<pause>" ); \
- FLUSH_OUTPUT(); \
gets( buffer ); \
puts( "" ); \
} while ( 0 )
@@ -262,7 +250,6 @@ extern "C" {
do { \
char buffer[ 80 ]; \
printf( "<pause - screen %d>", (_screen) ); \
- FLUSH_OUTPUT(); \
gets( buffer ); \
puts( "" ); \
} while ( 0 )
More information about the vc
mailing list