From 4b4cbdd68f958d219113d06837f043402d615359 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 28 Jun 2010 13:42:25 +0000 Subject: 2010-06-28 Joel Sherrill * termios03/init.c, termios03/termios03.doc, termios03/termios03.scn, termios03/termios_testdriver_polled.c, termios03/termios_testdriver_polled.h: Add more test cases. --- testsuites/libtests/ChangeLog | 6 ++ testsuites/libtests/termios03/init.c | 100 ++++++++++++++++++--- testsuites/libtests/termios03/termios03.doc | 4 +- testsuites/libtests/termios03/termios03.scn | 56 +++++++++++- .../libtests/termios03/termios_testdriver_polled.c | 38 +++++++- .../libtests/termios03/termios_testdriver_polled.h | 7 ++ 6 files changed, 195 insertions(+), 16 deletions(-) (limited to 'testsuites/libtests') diff --git a/testsuites/libtests/ChangeLog b/testsuites/libtests/ChangeLog index 57c7fd9b6c..0a475b8988 100644 --- a/testsuites/libtests/ChangeLog +++ b/testsuites/libtests/ChangeLog @@ -1,3 +1,9 @@ +2010-06-28 Joel Sherrill + + * termios03/init.c, termios03/termios03.doc, termios03/termios03.scn, + termios03/termios_testdriver_polled.c, + termios03/termios_testdriver_polled.h: Add more test cases. + 2010-06-28 Joel Sherrill * malloc02/Makefile.am, malloc03/Makefile.am: Tests do not need spin.c diff --git a/testsuites/libtests/termios03/init.c b/testsuites/libtests/termios03/init.c index 3cc8d768d4..555b7bdbc5 100644 --- a/testsuites/libtests/termios03/init.c +++ b/testsuites/libtests/termios03/init.c @@ -17,37 +17,115 @@ #include #include #include +#include +#include void write_helper( int fd, const char *c ) { - size_t len; - int rc; + 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"); } -rtems_task Init( - rtems_task_argument argument + +uint8_t read_helper_buffer[256]; + +void read_helper( + int fd, + const char *expected ) { - int fd; - int rc; + int rc; + size_t len; - puts( "\n\n*** TEST TERMIOS03 ***" ); + 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 " ); - fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); - rtems_test_assert( fd != -1 ); + Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); + rtems_test_assert( Test_fd != -1 ); +} - write_helper( fd, "This is a test\n" ); +void close_it(void) +{ + int rc; puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " ); - rc = close( fd ); + 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 TERMIOS03 ***" ); + + 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 TERMIOS03 ***" ); diff --git a/testsuites/libtests/termios03/termios03.doc b/testsuites/libtests/termios03/termios03.doc index ec479c8e8b..09d90d2976 100644 --- a/testsuites/libtests/termios03/termios03.doc +++ b/testsuites/libtests/termios03/termios03.doc @@ -15,8 +15,10 @@ test set name: termios03 directives: - + various termios services + + termios services for polled mode + + termios canonical input and output processing options concepts: + exercise termios polled support for input and output ++ exercise canonical IO processing options diff --git a/testsuites/libtests/termios03/termios03.scn b/testsuites/libtests/termios03/termios03.scn index a63612096b..bfd154b797 100644 --- a/testsuites/libtests/termios03/termios03.scn +++ b/testsuites/libtests/termios03/termios03.scn @@ -1 +1,55 @@ -XXX fill in with test output +*** TEST TERMIOS03 *** +open(/dev/test) - OK +Writing: This is test output. +Transmitted 22 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 0d 0a |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 21 characters +54 65 73 74 20 69 6e 70 75 74 20 74 68 69 73 20 |Test input this | +69 73 2e 0d 0a |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 12 characters +31 32 33 35 5e 48 34 35 36 2e 0d 0a |1235^H456... | + +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 14 characters +74 61 62 20 20 20 20 20 74 61 62 2e 0d 0a |tab tab... | + +Reading (expected): +63 72 0d |cr. | +Read 3 bytes from read(2) +63 72 0a |cr. | +Echoed 4 characters +63 72 0d 0a |cr.. | + +Reading (expected): +61 42 63 44 65 46 67 48 2e |aBcDeFgH. | +Read 10 bytes from read(2) +61 42 63 44 65 46 67 48 2e 0a |aBcDeFgH.. | +Echoed 11 characters +61 42 63 44 65 46 67 48 2e 0d 0a |aBcDeFgH... | +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 11 characters +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 TERMIOS03 *** diff --git a/testsuites/libtests/termios03/termios_testdriver_polled.c b/testsuites/libtests/termios03/termios_testdriver_polled.c index 76fde13944..3484f0401d 100644 --- a/testsuites/libtests/termios03/termios_testdriver_polled.c +++ b/testsuites/libtests/termios03/termios_testdriver_polled.c @@ -16,12 +16,44 @@ #include #include #include +#include #include "termios_testdriver_polled.h" -#include + +#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 ) { - return -1; + 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( @@ -29,7 +61,7 @@ void termios_test_driver_outbyte_polled( char ch ) { - write( 2, &ch, 1 ); + Tx_Buffer[Tx_Index++] = (uint8_t) ch; } ssize_t termios_test_driver_write_support (int minor, const char *buf, size_t len) diff --git a/testsuites/libtests/termios03/termios_testdriver_polled.h b/testsuites/libtests/termios03/termios_testdriver_polled.h index 2a17847f6a..ba280e6946 100644 --- a/testsuites/libtests/termios03/termios_testdriver_polled.h +++ b/testsuites/libtests/termios03/termios_testdriver_polled.h @@ -20,6 +20,13 @@ 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. -- cgit v1.2.3