From 5ba4f38399c318191afcc7a2ee5cd6a19a6939ec Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 6 Nov 2019 06:58:34 +0100 Subject: libtests: Avoid build system defined defines Update #3818. --- testsuites/libtests/Makefile.am | 27 +- testsuites/libtests/complex/docomplexl.c | 3 + testsuites/libtests/dl06/init.c | 89 +----- testsuites/libtests/dl06/initimpl.h | 88 ++++++ testsuites/libtests/dl06/pre-init.c | 2 + testsuites/libtests/mathl/domathl.c | 3 + testsuites/libtests/mouse01/init.c | 3 +- testsuites/libtests/mouse01/serial_mouse_config.c | 2 +- .../libtests/termios04/termios_testdriver_impl.h | 306 ++++++++++++++++++++ .../libtests/termios04/termios_testdriver_intr.c | 307 +-------------------- testsuites/libtests/termios05/init.c | 2 +- .../libtests/termios05/termios_testdriver_task.c | 2 + testsuites/libtests/termios06/init.c | 2 +- testsuites/libtests/termios07/init.c | 2 +- testsuites/libtests/termios08/init.c | 2 +- testsuites/libtests/termios10/init.c | 192 +------------ testsuites/libtests/termios10/termios10impl.h | 191 +++++++++++++ testsuites/libtests/termios11/init.c | 2 + testsuites/libtests/uid01/init.c | 3 +- testsuites/libtests/uid01/serial_mouse_config.c | 2 +- 20 files changed, 621 insertions(+), 609 deletions(-) create mode 100644 testsuites/libtests/dl06/initimpl.h create mode 100644 testsuites/libtests/dl06/pre-init.c create mode 100644 testsuites/libtests/termios04/termios_testdriver_impl.h create mode 100644 testsuites/libtests/termios05/termios_testdriver_task.c create mode 100644 testsuites/libtests/termios10/termios10impl.h create mode 100644 testsuites/libtests/termios11/init.c diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am index 1300a5f669..171e2e3b65 100644 --- a/testsuites/libtests/Makefile.am +++ b/testsuites/libtests/Makefile.am @@ -219,7 +219,7 @@ lib_screens += complex/complex.scn complex_SOURCES = complex/init.c complex/docomplex.c \ complex/docomplexf.c complex/docomplexl.c complex_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_complex) \ - $(support_includes) -DNO_LONG_DOUBLE + $(support_includes) complex_LDADD = -lm $(LDADD) endif @@ -483,7 +483,7 @@ dl06-pre-tar.o: dl06-pre-tar.c dl06-pre-tar.h $(AM_V_CC)$(COMPILE) -c -o $@ $< dl06-pre-init.o: dl06-pre-tar.o $(AM_V_CC)$(COMPILE) $(dl06_CPPFLAGS) $(CPU_CFLAGS) $(AM_CFLAGS) \ - -DDL06_PRE -c -o $@ $(srcdir)/dl06/init.c + -c -o $@ $(srcdir)/dl06/pre-init.c dl06.pre: dl06-pre-init.o dl06/dl06-dl-load.o dl06-pre-tar.o @rm -f $@ dl06-sym.o $(AM_V_CCLD)$(LINK.c) $(CPU_CFLAGS) $(AM_CFLAGS) $(AM_LDFLAGS) -o $@ $+ $(LDADD) @@ -985,8 +985,7 @@ lib_tests += mathl lib_screens += mathl/mathl.scn mathl_SOURCES = mathl/init.c mathl/domathl.c mathl_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_mathl) \ - $(support_includes) -I$(top_srcdir)/math \ - -DNO_LONG_DOUBLE + $(support_includes) -I$(top_srcdir)/math mathl_LDADD = -lm $(LDADD) endif @@ -1044,7 +1043,7 @@ lib_docs += mouse01/mouse01.doc mouse01_SOURCES = mouse01/init.c mouse01/serial_mouse_config.c \ mouse01/msmouse.c termios04/termios_testdriver_intr.c mouse01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_mouse01) \ - $(support_includes) -I$(top_srcdir)/termios04 + $(support_includes) endif if TEST_nanosleep @@ -1448,9 +1447,9 @@ lib_tests += termios05 lib_screens += termios05/termios05.scn lib_docs += termios05/termios05.doc termios05_SOURCES = termios05/init.c \ - termios04/termios_testdriver_intr.c + termios05/termios_testdriver_task.c termios05_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_termios05) \ - $(support_includes) -I$(top_srcdir)/termios04 -DTASK_DRIVEN + $(support_includes) endif if TEST_termios06 @@ -1460,7 +1459,7 @@ lib_docs += termios06/termios06.doc termios06_SOURCES = termios06/init.c \ termios03/termios_testdriver_polled.c termios06/test_pppd.c termios06_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_termios06) \ - $(support_includes) -I$(top_srcdir)/termios03 + $(support_includes) endif if TEST_termios07 @@ -1470,7 +1469,7 @@ lib_docs += termios07/termios07.doc termios07_SOURCES = termios07/init.c \ termios04/termios_testdriver_intr.c termios07_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_termios07) \ - $(support_includes) -I$(top_srcdir)/termios04 + $(support_includes) endif if TEST_termios08 @@ -1480,7 +1479,7 @@ lib_docs += termios08/termios08.doc termios08_SOURCES = termios08/init.c \ termios03/termios_testdriver_polled.c termios08_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_termios08) \ - $(support_includes) -I$(top_srcdir)/termios03 + $(support_includes) endif if TEST_termios09 @@ -1499,17 +1498,17 @@ lib_docs += termios10/termios10.doc termios10_SOURCES = termios10/init.c termios10_SOURCES += termios03/termios_testdriver_polled.c termios10_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_termios10) \ - $(support_includes) -I$(top_srcdir)/termios03 + $(support_includes) endif if TEST_termios11 lib_tests += termios11 lib_screens += termios11/termios11.scn lib_docs += termios11/termios11.doc -termios11_SOURCES = termios10/init.c +termios11_SOURCES = termios11/init.c termios11_SOURCES += termios04/termios_testdriver_intr.c termios11_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_termios11) \ - $(support_includes) -I$(top_srcdir)/termios04 -DINTERRUPT_DRIVEN + $(support_includes) endif if TEST_top @@ -1560,7 +1559,7 @@ lib_docs += uid01/uid01.doc uid01_SOURCES = uid01/init.c uid01/serial_mouse_config.c \ uid01/msmouse.c termios04/termios_testdriver_intr.c uid01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_uid01) \ - $(support_includes) -I$(top_srcdir)/termios04 + $(support_includes) endif if TEST_unlink diff --git a/testsuites/libtests/complex/docomplexl.c b/testsuites/libtests/complex/docomplexl.c index 87817c7773..8b8317b3ff 100644 --- a/testsuites/libtests/complex/docomplexl.c +++ b/testsuites/libtests/complex/docomplexl.c @@ -14,6 +14,9 @@ #include "config.h" #endif +/* FIXME: Why is this defined? */ +#define NO_LONG_DOUBLE + #ifdef NO_LONG_DOUBLE #define PROVIDE_EMPTY_FUNC #endif diff --git a/testsuites/libtests/dl06/init.c b/testsuites/libtests/dl06/init.c index 6f03d01843..413ebf0d11 100644 --- a/testsuites/libtests/dl06/init.c +++ b/testsuites/libtests/dl06/init.c @@ -1,88 +1 @@ -/* - * Copyright (c) 2014 Chris Johns . 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 "tmacros.h" - -#include -#include -#include -#include - -#include -#include - -#include "dl-load.h" - -const char rtems_test_name[] = "libdl (RTL) 6"; - -/* forward declarations to avoid warnings */ -static rtems_task Init(rtems_task_argument argument); - -#if DL06_PRE -#include "dl06-pre-tar.h" -#else -#include "dl06-tar.h" -#endif - -#define TARFILE_START dl06_tar -#define TARFILE_SIZE dl06_tar_size - -static int test(void) -{ - int ret; - ret = dl_load_test(); - if (ret) - rtems_test_exit(ret); - return 0; -} - -static void Init(rtems_task_argument arg) -{ - int te; - - TEST_BEGIN(); - - te = Untar_FromMemory((void *)TARFILE_START, (size_t)TARFILE_SIZE); - if (te != 0) - { - printf("untar failed: %d\n", te); - rtems_test_exit(1); - exit (1); - } - - test(); - - TEST_END(); - - rtems_test_exit(0); -} - -#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER -#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER - -#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 - -#define CONFIGURE_MAXIMUM_TASKS 1 - -#define CONFIGURE_MAXIMUM_SEMAPHORES 1 - -#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION - -#define CONFIGURE_RTEMS_INIT_TASKS_TABLE - -#define CONFIGURE_INIT_TASK_STACK_SIZE (8U * 1024U) - -#define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT) - -#define CONFIGURE_INIT - -#include +#include "initimpl.h" diff --git a/testsuites/libtests/dl06/initimpl.h b/testsuites/libtests/dl06/initimpl.h new file mode 100644 index 0000000000..6f03d01843 --- /dev/null +++ b/testsuites/libtests/dl06/initimpl.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2014 Chris Johns . 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 "tmacros.h" + +#include +#include +#include +#include + +#include +#include + +#include "dl-load.h" + +const char rtems_test_name[] = "libdl (RTL) 6"; + +/* forward declarations to avoid warnings */ +static rtems_task Init(rtems_task_argument argument); + +#if DL06_PRE +#include "dl06-pre-tar.h" +#else +#include "dl06-tar.h" +#endif + +#define TARFILE_START dl06_tar +#define TARFILE_SIZE dl06_tar_size + +static int test(void) +{ + int ret; + ret = dl_load_test(); + if (ret) + rtems_test_exit(ret); + return 0; +} + +static void Init(rtems_task_argument arg) +{ + int te; + + TEST_BEGIN(); + + te = Untar_FromMemory((void *)TARFILE_START, (size_t)TARFILE_SIZE); + if (te != 0) + { + printf("untar failed: %d\n", te); + rtems_test_exit(1); + exit (1); + } + + test(); + + TEST_END(); + + rtems_test_exit(0); +} + +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER + +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 + +#define CONFIGURE_MAXIMUM_TASKS 1 + +#define CONFIGURE_MAXIMUM_SEMAPHORES 1 + +#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_INIT_TASK_STACK_SIZE (8U * 1024U) + +#define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT) + +#define CONFIGURE_INIT + +#include diff --git a/testsuites/libtests/dl06/pre-init.c b/testsuites/libtests/dl06/pre-init.c new file mode 100644 index 0000000000..6dc232a574 --- /dev/null +++ b/testsuites/libtests/dl06/pre-init.c @@ -0,0 +1,2 @@ +#define DL06_PRE 1 +#include "initimpl.h" diff --git a/testsuites/libtests/mathl/domathl.c b/testsuites/libtests/mathl/domathl.c index d0758dcc74..0781577d28 100644 --- a/testsuites/libtests/mathl/domathl.c +++ b/testsuites/libtests/mathl/domathl.c @@ -14,6 +14,9 @@ #include "config.h" #endif +/* FIXME: Why is this defined? */ +#define NO_LONG_DOUBLE + #ifdef NO_LONG_DOUBLE #define PROVIDE_EMPTY_FUNC #endif diff --git a/testsuites/libtests/mouse01/init.c b/testsuites/libtests/mouse01/init.c index 8b71615d6b..b20afe121c 100644 --- a/testsuites/libtests/mouse01/init.c +++ b/testsuites/libtests/mouse01/init.c @@ -22,7 +22,7 @@ #include #include #include -#include "termios_testdriver_intr.h" +#include "../termios04/termios_testdriver_intr.h" #include "tmacros.h" const char rtems_test_name[] = "MOUSE 1"; @@ -151,7 +151,6 @@ rtems_task Init( /* configuration information */ #include -#include "termios_testdriver_intr.h" /* NOTICE: the clock driver is explicitly disabled */ #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER diff --git a/testsuites/libtests/mouse01/serial_mouse_config.c b/testsuites/libtests/mouse01/serial_mouse_config.c index 09e420a3f2..798cbf3a3b 100644 --- a/testsuites/libtests/mouse01/serial_mouse_config.c +++ b/testsuites/libtests/mouse01/serial_mouse_config.c @@ -17,7 +17,7 @@ #include "tmacros.h" #include -#include "termios_testdriver_intr.h" +#include "../termios04/termios_testdriver_intr.h" extern const char *Mouse_Type_Short; diff --git a/testsuites/libtests/termios04/termios_testdriver_impl.h b/testsuites/libtests/termios04/termios_testdriver_impl.h new file mode 100644 index 0000000000..53764fb9da --- /dev/null +++ b/testsuites/libtests/termios04/termios_testdriver_impl.h @@ -0,0 +1,306 @@ +/** + * @file + * + * This file contains a test fixture termios device driver + */ + +/* + * COPYRIGHT (c) 1989-2012. + * On-Line Applications Research Corporation (OAR). + * + * 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 "tmacros.h" +#include +#include +#include +#include +#include +#include "termios_testdriver_intr.h" + +/* forward declarations to avoid warnings */ +void termios_test_driver_wait_for_tx_to_complete(void); +rtems_timer_service_routine Rx_ISR( + rtems_id ignored_id, + void *ignored_address +); +rtems_timer_service_routine Tx_ISR( + rtems_id ignored_id, + void *ignored_address +); +ssize_t termios_test_driver_write_helper( + int port, + const char *buf, + size_t len +); +int termios_test_driver_set_attributes( + int minor, + const struct termios *t +); +#if defined(TASK_DRIVEN) + int termios_test_driver_inbyte_nonblocking(int port); +#endif + +/* global variables */ +rtems_id Rx_Timer; +rtems_id Tx_Timer; + +#define TX_MAX 1024 +uint8_t Tx_Buffer[TX_MAX]; +int Tx_Index = 0; +struct rtems_termios_tty *Ttyp; + +void termios_test_driver_wait_for_tx_to_complete(void) +{ + rtems_task_wake_after( 2 * rtems_clock_get_ticks_per_second() ); +} + +void termios_test_driver_dump_tx(const char *c) +{ + termios_test_driver_wait_for_tx_to_complete(); + + printf( "%s %d characters\n", c, Tx_Index ); + rtems_print_buffer( Tx_Buffer, Tx_Index ); + Tx_Index = 0; +} + +const uint8_t *Rx_Buffer; +int Rx_Index = 0; +int Rx_Length = 0; +bool Rx_FirstTime = true; +bool Rx_EnqueueNow = false; + +#if defined(TASK_DRIVEN) + int termios_test_driver_inbyte_nonblocking( int port ) + { + if ( Rx_FirstTime == true ) { + Rx_FirstTime = false; + return -1; + } + if ( Rx_Index >= Rx_Length ) + return -1; + return Rx_Buffer[ Rx_Index++ ]; + } +#endif + +rtems_timer_service_routine Rx_ISR( + rtems_id ignored_id, + void *ignored_address +) +{ + uint8_t ch; + + if ( Rx_Index >= Rx_Length ) + return; + + ch = Rx_Buffer[ Rx_Index++ ]; + rtems_termios_enqueue_raw_characters (Ttyp, (char *)&ch, 1); + #if defined(TASK_DRIVEN) + rtems_termios_rxirq_occured(Ttyp); + #endif + + (void) rtems_timer_fire_after( Rx_Timer, 10, Rx_ISR, NULL ); +} + +rtems_timer_service_routine Tx_ISR( + rtems_id ignored_id, + void *ignored_address +) +{ + rtems_termios_dequeue_characters (Ttyp, 1); + + (void) rtems_timer_fire_after( Tx_Timer, 10, Tx_ISR, NULL ); +} + +void termios_test_driver_set_rx_enqueue_now( + bool value +) +{ + Rx_EnqueueNow = value; +} + +void termios_test_driver_set_rx( + const void *p, + size_t len +) +{ + Rx_Buffer = p; + Rx_Length = len; + Rx_Index = 0; + + if ( Rx_EnqueueNow == false) { + (void) rtems_timer_fire_after( Rx_Timer, 10, Rx_ISR, NULL ); + return; + } + + do { + uint8_t ch; + ch = Rx_Buffer[ Rx_Index++ ]; + rtems_termios_enqueue_raw_characters (Ttyp, (char *)&ch, 1); + } while (Rx_Index < Rx_Length ); +} + +ssize_t termios_test_driver_write_helper( + int port, + const char *buf, + size_t len +) +{ + if (len > 0) { + Tx_Buffer[Tx_Index++] = buf[0]; + (void) rtems_timer_fire_after( Tx_Timer, 10, Tx_ISR, NULL ); + } + + return 0; +} + +/* + * Set Attributes Handler + */ +int termios_test_driver_set_attributes( + int minor, + const struct termios *t +) +{ + return 0; +} + +/* + * Test Device Driver Entry Points + */ +rtems_device_driver termios_test_driver_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *arg +) +{ + rtems_termios_initialize(); + + /* + * Register Device Names + */ + (void) rtems_io_register_name( TERMIOS_TEST_DRIVER_DEVICE_NAME, major, 0 ); + + return RTEMS_SUCCESSFUL; +} + +static int first_open(int major, int minor, void *arg) +{ + rtems_status_code status; + + status = rtems_timer_create(rtems_build_name('T', 'M', 'R', 'X'), &Rx_Timer); + if ( status != RTEMS_SUCCESSFUL ) + rtems_fatal_error_occurred(1); + + status = rtems_timer_create(rtems_build_name('T', 'M', 'T', 'X'), &Tx_Timer); + if ( status != RTEMS_SUCCESSFUL ) + rtems_fatal_error_occurred(1); + + return 0; +} + +static int last_close(int major, int minor, void *arg) +{ + rtems_status_code status; + + status = rtems_timer_cancel(Rx_Timer); + if ( status != RTEMS_SUCCESSFUL ) + rtems_fatal_error_occurred(1); + + status = rtems_timer_cancel(Tx_Timer); + if ( status != RTEMS_SUCCESSFUL ) + rtems_fatal_error_occurred(1); + + status = rtems_timer_delete(Rx_Timer); + if ( status != RTEMS_SUCCESSFUL ) + rtems_fatal_error_occurred(1); + + status = rtems_timer_delete(Tx_Timer); + if ( status != RTEMS_SUCCESSFUL ) + rtems_fatal_error_occurred(1); + + return 0; +} + +rtems_device_driver termios_test_driver_open( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + rtems_status_code sc; + rtems_libio_open_close_args_t *args = arg; + static const rtems_termios_callbacks Callbacks = { + first_open, /* firstOpen */ + last_close, /* lastClose */ + #if defined(TASK_DRIVEN) + termios_test_driver_inbyte_nonblocking,/* pollRead */ + #else + NULL, /* pollRead */ + #endif + termios_test_driver_write_helper, /* write */ + termios_test_driver_set_attributes, /* setAttributes */ + NULL, /* stopRemoteTx */ + NULL, /* startRemoteTx */ + #if defined(TASK_DRIVEN) + TERMIOS_TASK_DRIVEN /* outputUsesInterrupts */ + #else + 0 /* outputUsesInterrupts */ + #endif + }; + + if ( minor > 2 ) { + puts( "ERROR - Termios_testdriver - only 1 minor supported" ); + rtems_test_exit(0); + } + + sc = rtems_termios_open (major, minor, arg, &Callbacks); + directive_failed( sc, "termios open" ); + + Ttyp = args->iop->data1; /* Keep cookie returned by termios_open */ + + return RTEMS_SUCCESSFUL; +} + +rtems_device_driver termios_test_driver_close( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return rtems_termios_close (arg); +} + +rtems_device_driver termios_test_driver_read( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return rtems_termios_read (arg); +} + +rtems_device_driver termios_test_driver_write( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return rtems_termios_write (arg); +} + +rtems_device_driver termios_test_driver_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return rtems_termios_ioctl (arg); +} diff --git a/testsuites/libtests/termios04/termios_testdriver_intr.c b/testsuites/libtests/termios04/termios_testdriver_intr.c index 53764fb9da..5946c29a4e 100644 --- a/testsuites/libtests/termios04/termios_testdriver_intr.c +++ b/testsuites/libtests/termios04/termios_testdriver_intr.c @@ -1,306 +1 @@ -/** - * @file - * - * This file contains a test fixture termios device driver - */ - -/* - * COPYRIGHT (c) 1989-2012. - * On-Line Applications Research Corporation (OAR). - * - * 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 "tmacros.h" -#include -#include -#include -#include -#include -#include "termios_testdriver_intr.h" - -/* forward declarations to avoid warnings */ -void termios_test_driver_wait_for_tx_to_complete(void); -rtems_timer_service_routine Rx_ISR( - rtems_id ignored_id, - void *ignored_address -); -rtems_timer_service_routine Tx_ISR( - rtems_id ignored_id, - void *ignored_address -); -ssize_t termios_test_driver_write_helper( - int port, - const char *buf, - size_t len -); -int termios_test_driver_set_attributes( - int minor, - const struct termios *t -); -#if defined(TASK_DRIVEN) - int termios_test_driver_inbyte_nonblocking(int port); -#endif - -/* global variables */ -rtems_id Rx_Timer; -rtems_id Tx_Timer; - -#define TX_MAX 1024 -uint8_t Tx_Buffer[TX_MAX]; -int Tx_Index = 0; -struct rtems_termios_tty *Ttyp; - -void termios_test_driver_wait_for_tx_to_complete(void) -{ - rtems_task_wake_after( 2 * rtems_clock_get_ticks_per_second() ); -} - -void termios_test_driver_dump_tx(const char *c) -{ - termios_test_driver_wait_for_tx_to_complete(); - - printf( "%s %d characters\n", c, Tx_Index ); - rtems_print_buffer( Tx_Buffer, Tx_Index ); - Tx_Index = 0; -} - -const uint8_t *Rx_Buffer; -int Rx_Index = 0; -int Rx_Length = 0; -bool Rx_FirstTime = true; -bool Rx_EnqueueNow = false; - -#if defined(TASK_DRIVEN) - int termios_test_driver_inbyte_nonblocking( int port ) - { - if ( Rx_FirstTime == true ) { - Rx_FirstTime = false; - return -1; - } - if ( Rx_Index >= Rx_Length ) - return -1; - return Rx_Buffer[ Rx_Index++ ]; - } -#endif - -rtems_timer_service_routine Rx_ISR( - rtems_id ignored_id, - void *ignored_address -) -{ - uint8_t ch; - - if ( Rx_Index >= Rx_Length ) - return; - - ch = Rx_Buffer[ Rx_Index++ ]; - rtems_termios_enqueue_raw_characters (Ttyp, (char *)&ch, 1); - #if defined(TASK_DRIVEN) - rtems_termios_rxirq_occured(Ttyp); - #endif - - (void) rtems_timer_fire_after( Rx_Timer, 10, Rx_ISR, NULL ); -} - -rtems_timer_service_routine Tx_ISR( - rtems_id ignored_id, - void *ignored_address -) -{ - rtems_termios_dequeue_characters (Ttyp, 1); - - (void) rtems_timer_fire_after( Tx_Timer, 10, Tx_ISR, NULL ); -} - -void termios_test_driver_set_rx_enqueue_now( - bool value -) -{ - Rx_EnqueueNow = value; -} - -void termios_test_driver_set_rx( - const void *p, - size_t len -) -{ - Rx_Buffer = p; - Rx_Length = len; - Rx_Index = 0; - - if ( Rx_EnqueueNow == false) { - (void) rtems_timer_fire_after( Rx_Timer, 10, Rx_ISR, NULL ); - return; - } - - do { - uint8_t ch; - ch = Rx_Buffer[ Rx_Index++ ]; - rtems_termios_enqueue_raw_characters (Ttyp, (char *)&ch, 1); - } while (Rx_Index < Rx_Length ); -} - -ssize_t termios_test_driver_write_helper( - int port, - const char *buf, - size_t len -) -{ - if (len > 0) { - Tx_Buffer[Tx_Index++] = buf[0]; - (void) rtems_timer_fire_after( Tx_Timer, 10, Tx_ISR, NULL ); - } - - return 0; -} - -/* - * Set Attributes Handler - */ -int termios_test_driver_set_attributes( - int minor, - const struct termios *t -) -{ - return 0; -} - -/* - * Test Device Driver Entry Points - */ -rtems_device_driver termios_test_driver_initialize( - rtems_device_major_number major, - rtems_device_minor_number minor, - void *arg -) -{ - rtems_termios_initialize(); - - /* - * Register Device Names - */ - (void) rtems_io_register_name( TERMIOS_TEST_DRIVER_DEVICE_NAME, major, 0 ); - - return RTEMS_SUCCESSFUL; -} - -static int first_open(int major, int minor, void *arg) -{ - rtems_status_code status; - - status = rtems_timer_create(rtems_build_name('T', 'M', 'R', 'X'), &Rx_Timer); - if ( status != RTEMS_SUCCESSFUL ) - rtems_fatal_error_occurred(1); - - status = rtems_timer_create(rtems_build_name('T', 'M', 'T', 'X'), &Tx_Timer); - if ( status != RTEMS_SUCCESSFUL ) - rtems_fatal_error_occurred(1); - - return 0; -} - -static int last_close(int major, int minor, void *arg) -{ - rtems_status_code status; - - status = rtems_timer_cancel(Rx_Timer); - if ( status != RTEMS_SUCCESSFUL ) - rtems_fatal_error_occurred(1); - - status = rtems_timer_cancel(Tx_Timer); - if ( status != RTEMS_SUCCESSFUL ) - rtems_fatal_error_occurred(1); - - status = rtems_timer_delete(Rx_Timer); - if ( status != RTEMS_SUCCESSFUL ) - rtems_fatal_error_occurred(1); - - status = rtems_timer_delete(Tx_Timer); - if ( status != RTEMS_SUCCESSFUL ) - rtems_fatal_error_occurred(1); - - return 0; -} - -rtems_device_driver termios_test_driver_open( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -) -{ - rtems_status_code sc; - rtems_libio_open_close_args_t *args = arg; - static const rtems_termios_callbacks Callbacks = { - first_open, /* firstOpen */ - last_close, /* lastClose */ - #if defined(TASK_DRIVEN) - termios_test_driver_inbyte_nonblocking,/* pollRead */ - #else - NULL, /* pollRead */ - #endif - termios_test_driver_write_helper, /* write */ - termios_test_driver_set_attributes, /* setAttributes */ - NULL, /* stopRemoteTx */ - NULL, /* startRemoteTx */ - #if defined(TASK_DRIVEN) - TERMIOS_TASK_DRIVEN /* outputUsesInterrupts */ - #else - 0 /* outputUsesInterrupts */ - #endif - }; - - if ( minor > 2 ) { - puts( "ERROR - Termios_testdriver - only 1 minor supported" ); - rtems_test_exit(0); - } - - sc = rtems_termios_open (major, minor, arg, &Callbacks); - directive_failed( sc, "termios open" ); - - Ttyp = args->iop->data1; /* Keep cookie returned by termios_open */ - - return RTEMS_SUCCESSFUL; -} - -rtems_device_driver termios_test_driver_close( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -) -{ - return rtems_termios_close (arg); -} - -rtems_device_driver termios_test_driver_read( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -) -{ - return rtems_termios_read (arg); -} - -rtems_device_driver termios_test_driver_write( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -) -{ - return rtems_termios_write (arg); -} - -rtems_device_driver termios_test_driver_control( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -) -{ - return rtems_termios_ioctl (arg); -} +#include "termios_testdriver_impl.h" diff --git a/testsuites/libtests/termios05/init.c b/testsuites/libtests/termios05/init.c index 089123dbd6..6b980cc7af 100644 --- a/testsuites/libtests/termios05/init.c +++ b/testsuites/libtests/termios05/init.c @@ -13,7 +13,7 @@ #include #include "test_support.h" -#include "termios_testdriver_intr.h" +#include "../termios04/termios_testdriver_intr.h" #include #include diff --git a/testsuites/libtests/termios05/termios_testdriver_task.c b/testsuites/libtests/termios05/termios_testdriver_task.c new file mode 100644 index 0000000000..e1b31810a7 --- /dev/null +++ b/testsuites/libtests/termios05/termios_testdriver_task.c @@ -0,0 +1,2 @@ +#define TASK_DRIVEN +#include "../termios04/termios_testdriver_impl.h" diff --git a/testsuites/libtests/termios06/init.c b/testsuites/libtests/termios06/init.c index 6ed8ac73ff..ead88e5e39 100644 --- a/testsuites/libtests/termios06/init.c +++ b/testsuites/libtests/termios06/init.c @@ -13,7 +13,7 @@ #include #include "test_support.h" -#include "termios_testdriver_polled.h" +#include "../termios03/termios_testdriver_polled.h" #include #include diff --git a/testsuites/libtests/termios07/init.c b/testsuites/libtests/termios07/init.c index 7acd48b49b..f3d3500333 100644 --- a/testsuites/libtests/termios07/init.c +++ b/testsuites/libtests/termios07/init.c @@ -13,7 +13,7 @@ #include #include "test_support.h" -#include "termios_testdriver_intr.h" +#include "../termios04/termios_testdriver_intr.h" #include #include diff --git a/testsuites/libtests/termios08/init.c b/testsuites/libtests/termios08/init.c index 34f9d23757..b6aa59e2ba 100644 --- a/testsuites/libtests/termios08/init.c +++ b/testsuites/libtests/termios08/init.c @@ -13,7 +13,7 @@ #include #include "test_support.h" -#include "termios_testdriver_polled.h" +#include "../termios03/termios_testdriver_polled.h" #include #include diff --git a/testsuites/libtests/termios10/init.c b/testsuites/libtests/termios10/init.c index ca5de97f24..8655879500 100644 --- a/testsuites/libtests/termios10/init.c +++ b/testsuites/libtests/termios10/init.c @@ -1,191 +1 @@ -/* - * COPYRIGHT (c) 1989-2012,2019. - * On-Line Applications Research Corporation (OAR). - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "test_support.h" - -#ifdef INTERRUPT_DRIVEN -#include "termios_testdriver_intr.h" -const char rtems_test_name[] = "TERMIOS 11 -- Interrupt driven"; -#else -#include "termios_testdriver_polled.h" -const char rtems_test_name[] = "TERMIOS 10 -- Polled"; -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int Test_fd; - -static void open_it(void) -{ - Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); - rtems_test_assert( Test_fd != -1 ); -} - -static void change_lflag( const char *desc, int mask, int new ) -{ - int rc; - struct termios attr; - - if (desc) { - printf( "Changing c_lflag to: %s\n", desc ); - } - - rc = tcgetattr( Test_fd, &attr ); - rtems_test_assert( rc == 0 ); - - attr.c_lflag &= ~mask; - attr.c_lflag |= new; - - rc = tcsetattr( Test_fd, TCSANOW, &attr ); - rtems_test_assert( rc == 0 ); -} - - -static void read_it(ssize_t expected, int expected_intr) -{ - ssize_t rc; - char buf[32]; - - rtems_test_assert( expected <= sizeof(buf) ); - - rc = read( Test_fd, buf, expected ); - if (expected_intr) { - rtems_test_assert( rc == -1 ); - rtems_test_assert( errno == EINTR ); - } else { - if ( expected != rc ) - printf( "ERROR - expected=%zd rc=%zd\n", expected, rc ); - rtems_test_assert( expected == rc ); - } -} - -static void close_it(void) -{ - int rc; - - rc = close( Test_fd ); - rtems_test_assert( rc == 0 ); -} - -volatile int sigint_occurred = 0; -volatile int sigquit_occurred = 0; - -static void sigint_handler(int signo) -{ - rtems_test_assert(signo == SIGINT); - sigint_occurred = 1; -} - -static void sigquit_handler(int signo) -{ - rtems_test_assert(signo == SIGQUIT); - sigquit_occurred = 1; -} - -static void test_read_for_signal( - const char *description, - int isig_value, - char c, - int sigint_expected, - int sigquit_expected -) -{ - char expected[3]; - - printf("Test read for %s\n", description); - - expected[0] = c; - expected[1] = '\n'; /* in canonical mode, so need \n for read to return */ - expected[2] = '\0'; - - sigint_occurred = 0; - sigquit_occurred = 0; - - open_it(); - - change_lflag(NULL, ISIG, isig_value); - - termios_test_driver_set_rx( expected, 2 ); - - read_it(1, (sigint_expected || sigquit_expected)); - - rtems_test_assert(sigint_occurred == sigint_expected); - rtems_test_assert(sigquit_occurred == sigquit_expected); - close_it(); -} - -/* - * Use a POSIX init thread so signals are enabled. - */ -static void *POSIX_Init(void *argument) -{ - int rc; - - TEST_BEGIN(); - - signal(SIGINT, sigint_handler); - signal(SIGQUIT, sigquit_handler); - - puts( "Exercise default ISIG handler with ISIG enabled"); - test_read_for_signal("VKILL - no signals", ISIG, '\003', 0, 0); - test_read_for_signal("VQUIT - no signals", ISIG, '\034', 0, 0); - - puts( "Exercise POSIX ISIG handler with ISIG enabled"); - rc = rtems_termios_register_isig_handler(rtems_termios_posix_isig_handler); - rtems_test_assert( rc == 0 ); - test_read_for_signal("VKILL - signal caught", ISIG, '\003', 1, 0); - test_read_for_signal("VQUIT - signal caught", ISIG, '\034', 0, 1); - - puts( "Exercise default ISIG handler with ISIG enabled"); - rc = rtems_termios_register_isig_handler(rtems_termios_default_isig_handler); - rtems_test_assert( rc == 0 ); - test_read_for_signal("VKILL - signal caught", ISIG, '\003', 0, 0); - test_read_for_signal("VQUIT - signal caught", ISIG, '\034', 0, 0); - - puts( "Exercise POSIX ISIG handler with ISIG disabled"); - rc = rtems_termios_register_isig_handler(rtems_termios_posix_isig_handler); - rtems_test_assert( rc == 0 ); - test_read_for_signal("VKILL - signal caught", 0, '\003', 0, 0); - test_read_for_signal("VQUIT - signal caught", 0, '\034', 0, 0); - - TEST_END(); - - rtems_test_exit(0); -} - -/* configuration information */ - -#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER -#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER -#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \ - TERMIOS_TEST_DRIVER_TABLE_ENTRY - -/* we need to be able to open the test device */ -#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 -#define CONFIGURE_MAXIMUM_POSIX_THREADS 1 -#define CONFIGURE_MAXIMUM_TIMERS 2 -#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION - -#define CONFIGURE_POSIX_INIT_THREAD_TABLE - -#define CONFIGURE_INIT - -#include -/* end of file */ +#include "termios10impl.h" diff --git a/testsuites/libtests/termios10/termios10impl.h b/testsuites/libtests/termios10/termios10impl.h new file mode 100644 index 0000000000..a01f203857 --- /dev/null +++ b/testsuites/libtests/termios10/termios10impl.h @@ -0,0 +1,191 @@ +/* + * COPYRIGHT (c) 1989-2012,2019. + * On-Line Applications Research Corporation (OAR). + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "test_support.h" + +#ifdef INTERRUPT_DRIVEN +#include "../termios04/termios_testdriver_intr.h" +const char rtems_test_name[] = "TERMIOS 11 -- Interrupt driven"; +#else +#include "../termios03/termios_testdriver_polled.h" +const char rtems_test_name[] = "TERMIOS 10 -- Polled"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int Test_fd; + +static void open_it(void) +{ + Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); + rtems_test_assert( Test_fd != -1 ); +} + +static void change_lflag( const char *desc, int mask, int new ) +{ + int rc; + struct termios attr; + + if (desc) { + printf( "Changing c_lflag to: %s\n", desc ); + } + + rc = tcgetattr( Test_fd, &attr ); + rtems_test_assert( rc == 0 ); + + attr.c_lflag &= ~mask; + attr.c_lflag |= new; + + rc = tcsetattr( Test_fd, TCSANOW, &attr ); + rtems_test_assert( rc == 0 ); +} + + +static void read_it(ssize_t expected, int expected_intr) +{ + ssize_t rc; + char buf[32]; + + rtems_test_assert( expected <= sizeof(buf) ); + + rc = read( Test_fd, buf, expected ); + if (expected_intr) { + rtems_test_assert( rc == -1 ); + rtems_test_assert( errno == EINTR ); + } else { + if ( expected != rc ) + printf( "ERROR - expected=%zd rc=%zd\n", expected, rc ); + rtems_test_assert( expected == rc ); + } +} + +static void close_it(void) +{ + int rc; + + rc = close( Test_fd ); + rtems_test_assert( rc == 0 ); +} + +volatile int sigint_occurred = 0; +volatile int sigquit_occurred = 0; + +static void sigint_handler(int signo) +{ + rtems_test_assert(signo == SIGINT); + sigint_occurred = 1; +} + +static void sigquit_handler(int signo) +{ + rtems_test_assert(signo == SIGQUIT); + sigquit_occurred = 1; +} + +static void test_read_for_signal( + const char *description, + int isig_value, + char c, + int sigint_expected, + int sigquit_expected +) +{ + char expected[3]; + + printf("Test read for %s\n", description); + + expected[0] = c; + expected[1] = '\n'; /* in canonical mode, so need \n for read to return */ + expected[2] = '\0'; + + sigint_occurred = 0; + sigquit_occurred = 0; + + open_it(); + + change_lflag(NULL, ISIG, isig_value); + + termios_test_driver_set_rx( expected, 2 ); + + read_it(1, (sigint_expected || sigquit_expected)); + + rtems_test_assert(sigint_occurred == sigint_expected); + rtems_test_assert(sigquit_occurred == sigquit_expected); + close_it(); +} + +/* + * Use a POSIX init thread so signals are enabled. + */ +static void *POSIX_Init(void *argument) +{ + int rc; + + TEST_BEGIN(); + + signal(SIGINT, sigint_handler); + signal(SIGQUIT, sigquit_handler); + + puts( "Exercise default ISIG handler with ISIG enabled"); + test_read_for_signal("VKILL - no signals", ISIG, '\003', 0, 0); + test_read_for_signal("VQUIT - no signals", ISIG, '\034', 0, 0); + + puts( "Exercise POSIX ISIG handler with ISIG enabled"); + rc = rtems_termios_register_isig_handler(rtems_termios_posix_isig_handler); + rtems_test_assert( rc == 0 ); + test_read_for_signal("VKILL - signal caught", ISIG, '\003', 1, 0); + test_read_for_signal("VQUIT - signal caught", ISIG, '\034', 0, 1); + + puts( "Exercise default ISIG handler with ISIG enabled"); + rc = rtems_termios_register_isig_handler(rtems_termios_default_isig_handler); + rtems_test_assert( rc == 0 ); + test_read_for_signal("VKILL - signal caught", ISIG, '\003', 0, 0); + test_read_for_signal("VQUIT - signal caught", ISIG, '\034', 0, 0); + + puts( "Exercise POSIX ISIG handler with ISIG disabled"); + rc = rtems_termios_register_isig_handler(rtems_termios_posix_isig_handler); + rtems_test_assert( rc == 0 ); + test_read_for_signal("VKILL - signal caught", 0, '\003', 0, 0); + test_read_for_signal("VQUIT - signal caught", 0, '\034', 0, 0); + + TEST_END(); + + rtems_test_exit(0); +} + +/* configuration information */ + +#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \ + TERMIOS_TEST_DRIVER_TABLE_ENTRY + +/* we need to be able to open the test device */ +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 +#define CONFIGURE_MAXIMUM_POSIX_THREADS 1 +#define CONFIGURE_MAXIMUM_TIMERS 2 +#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION + +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_INIT + +#include +/* end of file */ diff --git a/testsuites/libtests/termios11/init.c b/testsuites/libtests/termios11/init.c new file mode 100644 index 0000000000..3492a62753 --- /dev/null +++ b/testsuites/libtests/termios11/init.c @@ -0,0 +1,2 @@ +#define INTERRUPT_DRIVEN +#include "../termios10/termios10impl.h" diff --git a/testsuites/libtests/uid01/init.c b/testsuites/libtests/uid01/init.c index 85b8f447cd..f71c0023ec 100644 --- a/testsuites/libtests/uid01/init.c +++ b/testsuites/libtests/uid01/init.c @@ -21,7 +21,7 @@ #include #include #include -#include "termios_testdriver_intr.h" +#include "../termios04/termios_testdriver_intr.h" #include "tmacros.h" const char rtems_test_name[] = "UID 1"; @@ -123,7 +123,6 @@ rtems_task Init( /* configuration information */ #include -#include "termios_testdriver_intr.h" /* NOTICE: the clock driver is explicitly disabled */ #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER diff --git a/testsuites/libtests/uid01/serial_mouse_config.c b/testsuites/libtests/uid01/serial_mouse_config.c index 63840b117b..78c8602257 100644 --- a/testsuites/libtests/uid01/serial_mouse_config.c +++ b/testsuites/libtests/uid01/serial_mouse_config.c @@ -25,7 +25,7 @@ #include "tmacros.h" #include -#include "termios_testdriver_intr.h" +#include "../termios04/termios_testdriver_intr.h" extern const char *Mouse_Type_Short; -- cgit v1.2.3