summaryrefslogtreecommitdiffstats
path: root/testsuites/libtests/termios05
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2010-07-01 14:35:00 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2010-07-01 14:35:00 +0000
commit7424c3ee866ba2a468d7959c4993f83e8667e7a0 (patch)
treec06da1c7abadce221ed963092384055d4ad3b037 /testsuites/libtests/termios05
parent2010-07-01 Sebastian Huber <sebastian.huber@embedded-brains.de> (diff)
downloadrtems-7424c3ee866ba2a468d7959c4993f83e8667e7a0.tar.bz2
2010-07-01 Joel Sherrill <joel.sherrill@oarcorp.com>
* Makefile.am, configure.ac: Add test for task driven drivers. * termios05/.cvsignore, termios05/Makefile.am, termios05/init.c, termios05/termios05.doc, termios05/termios05.scn, termios05/termios_testdriver_taskdriven.c, termios05/termios_testdriver_taskdriven.h: New files.
Diffstat (limited to 'testsuites/libtests/termios05')
-rw-r--r--testsuites/libtests/termios05/.cvsignore2
-rw-r--r--testsuites/libtests/termios05/Makefile.am28
-rw-r--r--testsuites/libtests/termios05/init.c158
-rw-r--r--testsuites/libtests/termios05/termios05.doc22
-rw-r--r--testsuites/libtests/termios05/termios05.scn59
-rw-r--r--testsuites/libtests/termios05/termios_testdriver_taskdriven.c171
-rw-r--r--testsuites/libtests/termios05/termios_testdriver_taskdriven.h164
7 files changed, 604 insertions, 0 deletions
diff --git a/testsuites/libtests/termios05/.cvsignore b/testsuites/libtests/termios05/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/testsuites/libtests/termios05/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/testsuites/libtests/termios05/Makefile.am b/testsuites/libtests/termios05/Makefile.am
new file mode 100644
index 0000000000..1ac6602633
--- /dev/null
+++ b/testsuites/libtests/termios05/Makefile.am
@@ -0,0 +1,28 @@
+##
+## $Id$
+##
+
+MANAGERS = all
+
+rtems_tests_PROGRAMS = termios05
+termios05_SOURCES = init.c ../termios04/termios_testdriver_intr.c
+
+dist_rtems_tests_DATA = termios05.scn
+dist_rtems_tests_DATA += termios05.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+AM_CPPFLAGS += -I$(top_srcdir)/termios04
+AM_CPPFLAGS += -DTASK_DRIVEN
+
+LINK_OBJS = $(termios05_OBJECTS) $(termios05_LDADD)
+LINK_LIBS = $(termios05_LDLIBS)
+
+termios05$(EXEEXT): $(termios05_OBJECTS) $(termios05_DEPENDENCIES)
+ @rm -f termios05$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/libtests/termios05/init.c b/testsuites/libtests/termios05/init.c
new file mode 100644
index 0000000000..a4df3341ee
--- /dev/null
+++ b/testsuites/libtests/termios05/init.c
@@ -0,0 +1,158 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * 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.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <tmacros.h>
+#include "test_support.h"
+#include "termios_testdriver_intr.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <termios.h>
+#include <rtems/dumpbuf.h>
+
+void write_helper(
+ int fd,
+ const char *c
+)
+{
+ size_t len;
+ int rc;
+
+ len = strlen( c );
+ printf( "Writing: %s", c );
+
+ rc = write( fd, c, len );
+ rtems_test_assert( rc == len );
+
+ termios_test_driver_dump_tx("Transmitted");
+}
+
+uint8_t read_helper_buffer[256];
+
+void read_helper(
+ int fd,
+ const char *expected
+)
+{
+ int rc;
+ size_t len;
+
+ len = strlen( expected );
+
+ termios_test_driver_set_rx( expected, len );
+ printf( "\nReading (expected):\n" );
+ rtems_print_buffer( (unsigned char *)expected, len-1 );
+
+ rc = read( fd, read_helper_buffer, sizeof(read_helper_buffer) );
+ rtems_test_assert( rc != -1 );
+
+ printf( "Read %d bytes from read(2)\n", rc );
+ rtems_print_buffer( read_helper_buffer, rc );
+
+ termios_test_driver_dump_tx("Echoed");
+}
+
+int Test_fd;
+
+void open_it(void)
+{
+ /* open the file */
+ puts( "open(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
+ Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
+ rtems_test_assert( Test_fd != -1 );
+}
+
+void close_it(void)
+{
+ int rc;
+
+ puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
+ rc = close( Test_fd );
+ rtems_test_assert( rc == 0 );
+}
+
+void change_iflag( const char *desc, int mask, int new )
+{
+ int rc;
+ struct termios attr;
+
+ printf( "Changing c_iflag to: %s\n", desc );
+ rc = tcgetattr( Test_fd, &attr );
+ rtems_test_assert( rc == 0 );
+
+ attr.c_iflag &= ~mask;
+ attr.c_iflag |= new;
+
+ rc = tcsetattr( Test_fd, TCSANOW, &attr );
+ rtems_test_assert( rc == 0 );
+}
+
+const char ExpectedOutput_1[] = "This is test output.\n";
+const char ExpectedInput_1[] = "Test input this is.\n";
+const char ExpectedInput_2[] = "1235\b456.\n";
+const char ExpectedInput_3[] = "tab\ttab.\n";
+const char ExpectedInput_4[] = "cr\r.";
+const char ExpectedInput_5[] = "aBcDeFgH.\n";
+
+rtems_task Init(
+ rtems_task_argument argument
+)
+{
+ puts( "\n\n*** TEST TERMIOS05 ***" );
+
+ open_it();
+
+ /* some basic cases */
+ write_helper( Test_fd, ExpectedOutput_1 );
+ read_helper( Test_fd, ExpectedInput_1 );
+ read_helper( Test_fd, ExpectedInput_2 );
+ read_helper( Test_fd, ExpectedInput_3 );
+ read_helper( Test_fd, ExpectedInput_4 );
+
+ /* test to lower case input mapping */
+ read_helper( Test_fd, ExpectedInput_5 );
+ change_iflag( "Enable to lower case mapping on input", IUCLC, IUCLC );
+ read_helper( Test_fd, ExpectedInput_5 );
+ change_iflag( "Disable to lower case mapping on input", IUCLC, 0 );
+
+ close_it();
+
+ puts( "*** END OF TEST TERMIOS05 ***" );
+
+ rtems_test_exit(0);
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
+ TERMIOS_TEST_DRIVER_TABLE_ENTRY
+
+/* include an extra slot for registering the termios one dynamically */
+#define CONFIGURE_MAXIMUM_DRIVERS 3
+
+/* one for the console and one for the test port */
+#define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 3
+
+/* we need to be able to open the test device */
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
+
+#define CONFIGURE_MAXIMUM_TASKS 4
+#define CONFIGURE_MAXIMUM_TIMERS 2
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
+/* end of file */
diff --git a/testsuites/libtests/termios05/termios05.doc b/testsuites/libtests/termios05/termios05.doc
new file mode 100644
index 0000000000..962c774a00
--- /dev/null
+++ b/testsuites/libtests/termios05/termios05.doc
@@ -0,0 +1,22 @@
+#
+# $Id$
+#
+# COPYRIGHT (c) 1989-2010.
+# 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.com/license/LICENSE.
+#
+
+This file describes the directives and concepts tested by this test set.
+
+test set name: termios05
+
+directives:
+
+ various termios services related to task driven IO
+
+concepts:
+
++ task driven IO
diff --git a/testsuites/libtests/termios05/termios05.scn b/testsuites/libtests/termios05/termios05.scn
new file mode 100644
index 0000000000..4d2988f86d
--- /dev/null
+++ b/testsuites/libtests/termios05/termios05.scn
@@ -0,0 +1,59 @@
+*** TEST TERMIOS05 ***
+open(/dev/test) - OK
+Writing: This is test output.
+Transmitted 20 characters
+54 68 69 73 20 69 73 20 74 65 73 74 20 6f 75 74 |This is test out|
+70 75 74 2e |put. |
+
+Reading (expected):
+54 65 73 74 20 69 6e 70 75 74 20 74 68 69 73 20 |Test input this |
+69 73 2e |is. |
+Read 20 bytes from read(2)
+54 65 73 74 20 69 6e 70 75 74 20 74 68 69 73 20 |Test input this |
+69 73 2e 0a |is.. |
+Echoed 23 characters
+0d 0a 54 65 73 74 20 69 6e 70 75 74 20 74 68 69 |..Test input thi|
+73 20 69 73 2e 0d 0a |s is... |
+
+Reading (expected):
+31 32 33 35 08 34 35 36 2e |1235.456. |
+Read 10 bytes from read(2)
+31 32 33 35 08 34 35 36 2e 0a |1235.456.. |
+Echoed 24 characters
+31 00 00 00 00 00 00 00 00 00 00 00 54 68 69 73 |1...........This|
+20 69 73 20 74 65 73 74 | is test |
+
+Reading (expected):
+74 61 62 09 74 61 62 2e |tab.tab. |
+Read 9 bytes from read(2)
+74 61 62 09 74 61 62 2e 0a |tab.tab.. |
+Echoed 25 characters
+20 6f 75 74 70 75 74 2e 0d 0a 54 65 73 74 20 69 | output...Test i|
+6e 70 75 74 20 74 68 69 73 |nput this |
+
+Reading (expected):
+63 72 0d |cr. |
+Read 3 bytes from read(2)
+63 72 0a |cr. |
+Echoed 22 characters
+20 69 73 2e 0d 0a 31 32 33 35 5e 48 34 35 36 2e | is...1235^H456.|
+0d 0a 74 61 62 20 |..tab |
+
+Reading (expected):
+61 42 63 44 65 46 67 48 2e |aBcDeFgH. |
+Read 11 bytes from read(2)
+2e 61 42 63 44 65 46 67 48 2e 0a |.aBcDeFgH.. |
+Echoed 25 characters
+20 20 20 20 74 61 62 2e 0d 0a 63 72 0d 0a 2e 61 | tab...cr...a|
+42 63 44 65 46 67 48 2e 0d |BcDeFgH.. |
+Changing c_iflag to: Enable to lower case mapping on input
+
+Reading (expected):
+61 42 63 44 65 46 67 48 2e |aBcDeFgH. |
+Read 10 bytes from read(2)
+61 62 63 64 65 66 67 68 2e 0a |abcdefgh.. |
+Echoed 12 characters
+0a 61 62 63 64 65 66 67 68 2e 0d 0a |.abcdefgh... |
+Changing c_iflag to: Disable to lower case mapping on input
+close(/dev/test) - OK
+*** END OF TEST TERMIOS05 ***
diff --git a/testsuites/libtests/termios05/termios_testdriver_taskdriven.c b/testsuites/libtests/termios05/termios_testdriver_taskdriven.c
new file mode 100644
index 0000000000..1ef0057df1
--- /dev/null
+++ b/testsuites/libtests/termios05/termios_testdriver_taskdriven.c
@@ -0,0 +1,171 @@
+/*
+ * This file contains a test fixture termios device driver
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * 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.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include "tmacros.h"
+#include <rtems/libio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <rtems/termiostypes.h>
+#include <rtems/dumpbuf.h>
+#include "termios_testdriver_taskdriven.h"
+
+#define TX_MAX 1024
+uint8_t Tx_Buffer[TX_MAX];
+int Tx_Index = 0;
+
+void termios_test_driver_dump_tx(const char *c)
+{
+ 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;
+int Rx_Length;
+bool Rx_FirstTime = true;
+
+void termios_test_driver_set_rx(
+ const void *p,
+ size_t len
+)
+{
+ Rx_Buffer = p;
+ Rx_Length = len;
+ Rx_Index = 0;
+}
+
+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++ ];
+}
+
+void termios_test_driver_outbyte_polled(
+ int port,
+ char ch
+)
+{
+ Tx_Buffer[Tx_Index++] = (uint8_t) ch;
+}
+
+ssize_t termios_test_driver_write_support (int minor, const char *buf, size_t len)
+{
+ size_t nwrite = 0;
+
+ while (nwrite < len) {
+ termios_test_driver_outbyte_polled( minor, *buf++ );
+ nwrite++;
+ }
+ return nwrite;
+}
+
+
+/*
+ * 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;
+}
+
+rtems_device_driver termios_test_driver_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+)
+{
+ rtems_status_code sc;
+ static const rtems_termios_callbacks Callbacks = {
+ NULL, /* firstOpen */
+ NULL, /* lastClose */
+ termios_test_driver_inbyte_nonblocking, /* pollRead */
+ termios_test_driver_write_support, /* write */
+ termios_test_driver_set_attributes, /* setAttributes */
+ NULL, /* stopRemoteTx */
+ NULL, /* startRemoteTx */
+ TERMIOS_TASK_DRIVEN /* outputUsesInterrupts */
+ };
+
+ if ( minor > 2 ) {
+ puts( "ERROR - Termios_testdriver - only 1 minor supported" );
+ rtems_test_exit(0);
+ }
+
+ sc = rtems_termios_open (major, minor, arg, &Callbacks);
+
+ 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/termios05/termios_testdriver_taskdriven.h b/testsuites/libtests/termios05/termios_testdriver_taskdriven.h
new file mode 100644
index 0000000000..ba280e6946
--- /dev/null
+++ b/testsuites/libtests/termios05/termios_testdriver_taskdriven.h
@@ -0,0 +1,164 @@
+/**
+ * @file termios_testdriver.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * 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.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _TERMIOS_TESTDRIVER_H
+#define _TERMIOS_TESTDRIVER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void termios_test_driver_set_rx(
+ const void *p,
+ size_t len
+);
+
+void termios_test_driver_dump_tx(const char *c);
+
+/**
+ * This macro defines the standard name for the Termios Test device
+ * that is available to applications.
+ */
+#define TERMIOS_TEST_DRIVER_DEVICE_NAME "/dev/test"
+
+/**
+ * This macro defines the standard device driver table entry for
+ * a Termios Test device driver.
+ */
+#define TERMIOS_TEST_DRIVER_TABLE_ENTRY \
+ { termios_test_driver_initialize, termios_test_driver_open, \
+ termios_test_driver_close, termios_test_driver_read, \
+ termios_test_driver_write, termios_test_driver_control }
+
+/**
+ * @brief Console Initialization Entry Point
+ *
+ * This method initializes the Termios Test device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device driver is successfully initialized.
+ */
+rtems_device_driver termios_test_driver_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Console Open Entry Point
+ *
+ * This method opens a specific device supported by the
+ * Termios Test device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device driver is successfully opened.
+ */
+rtems_device_driver termios_test_driver_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Console Close Entry Point
+ *
+ * This method closes a specific device supported by the
+ * Termios Test device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device is successfully closed.
+ */
+rtems_device_driver termios_test_driver_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Console Read Entry Point
+ *
+ * This method reads from a specific device supported by the
+ * Termios Test device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device is successfully read from.
+ */
+rtems_device_driver termios_test_driver_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Console Write Entry Point
+ *
+ * This method writes to a specific device supported by the
+ * Termios Test device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device is successfully written.
+ */
+rtems_device_driver termios_test_driver_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Console IO Control Entry Point
+ *
+ * This method performs an IO Control operation on a
+ * specific device supported by the Termios Test device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device driver IO control operation is
+ * successfully performed.
+ */
+rtems_device_driver termios_test_driver_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */