forked from Imagelibrary/rtems
2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
* termios03/init.c, termios03/termios03.doc, termios03/termios03.scn, termios03/termios_testdriver_polled.c, termios03/termios_testdriver_polled.h: Add more test cases.
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
|
||||
|
||||
* 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 <joel.sherrill@oarcorp.com>
|
||||
|
||||
* malloc02/Makefile.am, malloc03/Makefile.am: Tests do not need spin.c
|
||||
|
||||
@@ -17,37 +17,115 @@
|
||||
#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;
|
||||
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
|
||||
)
|
||||
{
|
||||
int fd;
|
||||
int rc;
|
||||
|
||||
puts( "\n\n*** TEST TERMIOS03 ***" );
|
||||
|
||||
puts( "open(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
|
||||
fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
|
||||
rtems_test_assert( fd != -1 );
|
||||
open_it();
|
||||
|
||||
write_helper( fd, "This is a test\n" );
|
||||
/* 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 );
|
||||
|
||||
puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
|
||||
rc = close( fd );
|
||||
rtems_test_assert( rc == 0 );
|
||||
/* 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 ***" );
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ***
|
||||
|
||||
@@ -16,12 +16,44 @@
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <rtems/termiostypes.h>
|
||||
#include <rtems/dumpbuf.h>
|
||||
#include "termios_testdriver_polled.h"
|
||||
#include <unistd.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 )
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user