forked from Imagelibrary/rtems
2009-08-15 Joel Sherrill <joel.sherrill@oarcorp.com>
* Makefile.am, configure.ac: Add new test to exercise tcgetattr and tcsetattr. Does a variety of baud, parity, stop bits, and bits per character with the assistance of a special test driver which prints the requests. * termios01/.cvsignore, termios01/Makefile.am, termios01/init.c, termios01/termios01.doc, termios01/termios01.scn, termios01/termios_testdriver.c, termios01/termios_testdriver.h: New files.
This commit is contained in:
@@ -1,3 +1,13 @@
|
||||
2009-08-15 Joel Sherrill <joel.sherrill@oarcorp.com>
|
||||
|
||||
* Makefile.am, configure.ac: Add new test to exercise tcgetattr and
|
||||
tcsetattr. Does a variety of baud, parity, stop bits, and bits per
|
||||
character with the assistance of a special test driver which prints
|
||||
the requests.
|
||||
* termios01/.cvsignore, termios01/Makefile.am, termios01/init.c,
|
||||
termios01/termios01.doc, termios01/termios01.scn,
|
||||
termios01/termios_testdriver.c, termios01/termios_testdriver.h: New files.
|
||||
|
||||
2009-08-12 Joel Sherrill <joel.sherrill@oarcorp.com>
|
||||
|
||||
* malloctest/task1.c, stackchk/task1.c: Eliminate test routines
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
ACLOCAL_AMFLAGS = -I ../aclocal
|
||||
|
||||
SUBDIRS = bspcmdline01 cpuuse malloctest heapwalk putenvtest monitor \
|
||||
monitor02 rtmonuse stackchk termios rtems++ tztest
|
||||
monitor02 rtmonuse stackchk termios termios01 rtems++ tztest
|
||||
|
||||
include $(top_srcdir)/../automake/subdirs.am
|
||||
include $(top_srcdir)/../automake/local.am
|
||||
|
||||
@@ -44,6 +44,7 @@ rtems++/Makefile
|
||||
rtmonuse/Makefile
|
||||
stackchk/Makefile
|
||||
termios/Makefile
|
||||
termios01/Makefile
|
||||
tztest/Makefile
|
||||
])
|
||||
AC_OUTPUT
|
||||
|
||||
2
testsuites/libtests/termios01/.cvsignore
Normal file
2
testsuites/libtests/termios01/.cvsignore
Normal file
@@ -0,0 +1,2 @@
|
||||
Makefile
|
||||
Makefile.in
|
||||
29
testsuites/libtests/termios01/Makefile.am
Normal file
29
testsuites/libtests/termios01/Makefile.am
Normal file
@@ -0,0 +1,29 @@
|
||||
##
|
||||
## $Id$
|
||||
##
|
||||
|
||||
MANAGERS = all
|
||||
|
||||
rtems_tests_PROGRAMS = termios01
|
||||
termios01_SOURCES = init.c termios_testdriver.c
|
||||
|
||||
dist_rtems_tests_DATA = termios01.scn
|
||||
dist_rtems_tests_DATA += termios01.doc
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
|
||||
include $(top_srcdir)/../automake/compile.am
|
||||
include $(top_srcdir)/../automake/leaf.am
|
||||
|
||||
termios01_LDADD = $(MANAGERS_NOT_WANTED:%=$(PROJECT_LIB)/no-%.rel)
|
||||
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/include
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
|
||||
|
||||
LINK_OBJS = $(termios01_OBJECTS) $(termios01_LDADD)
|
||||
LINK_LIBS = $(termios01_LDLIBS)
|
||||
|
||||
termios01$(EXEEXT): $(termios01_OBJECTS) $(termios01_DEPENDENCIES)
|
||||
@rm -f termios01$(EXEEXT)
|
||||
$(make-exe)
|
||||
|
||||
include $(top_srcdir)/../automake/local.am
|
||||
493
testsuites/libtests/termios01/init.c
Normal file
493
testsuites/libtests/termios01/init.c
Normal file
@@ -0,0 +1,493 @@
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
#include "tmacros.h"
|
||||
#include <assert.h>
|
||||
#include <termios.h>
|
||||
#include <rtems/termiostypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
/*
|
||||
* Termios Test Driver
|
||||
*/
|
||||
#include "termios_testdriver.h"
|
||||
|
||||
rtems_driver_address_table test_driver = TERMIOS_TEST_DRIVER_TABLE_ENTRY;
|
||||
|
||||
/*
|
||||
* Baud Rate Constant Mapping Entry
|
||||
*/
|
||||
typedef struct {
|
||||
int constant;
|
||||
int baud;
|
||||
} termios_baud_test_r;
|
||||
|
||||
/*
|
||||
* Baud Rate Constant Mapping Table
|
||||
*/
|
||||
termios_baud_test_r baud_table[] = {
|
||||
{ B0, 0 },
|
||||
{ B50, 50 },
|
||||
{ B75, 75 },
|
||||
{ B110, 110 },
|
||||
{ B134, 134 },
|
||||
{ B150, 150 },
|
||||
{ B200, 200 },
|
||||
{ B300, 300 },
|
||||
{ B600, 600 },
|
||||
{ B1200, 1200 },
|
||||
{ B1800, 1800 },
|
||||
{ B2400, 2400 },
|
||||
{ B4800, 4800 },
|
||||
{ B9600, 9600 },
|
||||
{ B19200, 19200 },
|
||||
{ B38400, 38400 },
|
||||
{ B57600, 57600 },
|
||||
{ B115200, 115200 },
|
||||
{ B230400, 230400 },
|
||||
{ B460800, 460800 },
|
||||
{ -1, -1 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Character Size Constant Mapping Entry
|
||||
*/
|
||||
typedef struct {
|
||||
int constant;
|
||||
int bits;
|
||||
} termios_character_size_test_r;
|
||||
|
||||
/*
|
||||
* Character Size Constant Mapping Table
|
||||
*/
|
||||
termios_character_size_test_r char_size_table[] = {
|
||||
{ CS5, 5 },
|
||||
{ CS6, 6 },
|
||||
{ CS7, 7 },
|
||||
{ CS8, 8 },
|
||||
{ -1, -1 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Parity Constant Mapping Entry
|
||||
*/
|
||||
typedef struct {
|
||||
int constant;
|
||||
const char parity[5];
|
||||
} termios_parity_test_r;
|
||||
|
||||
/*
|
||||
* Parity Constant Mapping Table
|
||||
*/
|
||||
termios_parity_test_r parity_table[] = {
|
||||
{ 0, "none" },
|
||||
{ PARENB, "even" },
|
||||
{ PARENB | PARODD, "odd" },
|
||||
{ -1, -1 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Stop Bit Constant Mapping Entry
|
||||
*/
|
||||
typedef struct {
|
||||
int constant;
|
||||
int stop;
|
||||
} termios_stop_bits_test_r;
|
||||
|
||||
/*
|
||||
* Stop Bit Constant Mapping Table
|
||||
*/
|
||||
termios_stop_bits_test_r stop_bits_table[] = {
|
||||
{ 0, 1 },
|
||||
{ CSTOPB, 2 },
|
||||
{ -1, -1 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Test converting baud rate into an index
|
||||
*/
|
||||
void test_termios_baud2index(void)
|
||||
{
|
||||
int i;
|
||||
int index;
|
||||
|
||||
puts(
|
||||
"\n"
|
||||
"Test termios_baud2index..."
|
||||
);
|
||||
for (i=0 ; baud_table[i].constant != -1 ; i++ ) {
|
||||
printf( "termios_baud_to_index(B%d) - OK\n", baud_table[i].baud );
|
||||
index = termios_baud_to_index( baud_table[i].constant );
|
||||
if ( index != i ) {
|
||||
printf( "ERROR - returned %d should be %d\n", index, i );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test converting termios baud constant to baud number
|
||||
*/
|
||||
void test_termios_baud2number(void)
|
||||
{
|
||||
int i;
|
||||
int number;
|
||||
|
||||
puts(
|
||||
"\n"
|
||||
"Test termios_baud2number..."
|
||||
);
|
||||
for (i=0 ; baud_table[i].constant != -1 ; i++ ) {
|
||||
printf( "termios_baud_to_number(B%d) - OK\n", baud_table[i].baud );
|
||||
number = termios_baud_to_number( baud_table[i].constant );
|
||||
if ( number != baud_table[i].baud ) {
|
||||
printf(
|
||||
"ERROR - returned %d should be %d\n",
|
||||
number,
|
||||
baud_table[i].baud
|
||||
);
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test converting baud number to termios baud constant
|
||||
*/
|
||||
void test_termios_number_to_baud(void)
|
||||
{
|
||||
int i;
|
||||
int termios_baud;
|
||||
|
||||
puts(
|
||||
"\n"
|
||||
"Test termios_number_to_baud..."
|
||||
);
|
||||
for (i=0 ; baud_table[i].constant != -1 ; i++ ) {
|
||||
printf( "termios_number_to_baud(B%d) - OK\n", baud_table[i].baud );
|
||||
termios_baud = termios_number_to_baud( baud_table[i].baud );
|
||||
if ( termios_baud != baud_table[i].constant ) {
|
||||
printf(
|
||||
"ERROR - returned %d should be %d\n",
|
||||
termios_baud,
|
||||
baud_table[i].constant
|
||||
);
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test all the baud rate options
|
||||
*/
|
||||
void test_termios_set_baud(
|
||||
int test
|
||||
)
|
||||
{
|
||||
int sc;
|
||||
int i;
|
||||
int number;
|
||||
struct termios attr;
|
||||
|
||||
puts( "Test termios setting device baud rate..." );
|
||||
for (i=0 ; baud_table[i].constant != -1 ; i++ ) {
|
||||
sc = tcgetattr( test, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
attr.c_cflag &= ~CBAUD;
|
||||
attr.c_cflag |= baud_table[i].constant;
|
||||
|
||||
printf( "tcsetattr(TCSANOW, B%d) - OK\n", baud_table[i].baud );
|
||||
sc = tcsetattr( test, TCSANOW, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
printf( "tcsetattr(TCSADRAIN, B%d) - OK\n", baud_table[i].baud );
|
||||
sc = tcsetattr( test, TCSANOW, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test all the character size options
|
||||
*/
|
||||
void test_termios_set_charsize(
|
||||
int test
|
||||
)
|
||||
{
|
||||
int sc;
|
||||
int i;
|
||||
int number;
|
||||
struct termios attr;
|
||||
|
||||
puts(
|
||||
"\n"
|
||||
"Test termios setting device character size ..."
|
||||
);
|
||||
for (i=0 ; char_size_table[i].constant != -1 ; i++ ) {
|
||||
sc = tcgetattr( test, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
attr.c_cflag &= ~CSIZE;
|
||||
attr.c_cflag |= char_size_table[i].constant;
|
||||
|
||||
printf( "tcsetattr(TCSANOW, CS%d) - OK\n", char_size_table[i].bits );
|
||||
sc = tcsetattr( test, TCSANOW, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
printf( "tcsetattr(TCSADRAIN, CS%d) - OK\n", char_size_table[i].bits );
|
||||
sc = tcsetattr( test, TCSANOW, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test all the parity options
|
||||
*/
|
||||
void test_termios_set_parity(
|
||||
int test
|
||||
)
|
||||
{
|
||||
int sc;
|
||||
int i;
|
||||
int number;
|
||||
struct termios attr;
|
||||
|
||||
puts(
|
||||
"\n"
|
||||
"Test termios setting device parity ..."
|
||||
);
|
||||
for (i=0 ; parity_table[i].constant != -1 ; i++ ) {
|
||||
sc = tcgetattr( test, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
attr.c_cflag &= ~(PARENB|PARODD);
|
||||
attr.c_cflag |= parity_table[i].constant;
|
||||
|
||||
printf( "tcsetattr(TCSANOW, %s) - OK\n", parity_table[i].parity );
|
||||
sc = tcsetattr( test, TCSANOW, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
printf( "tcsetattr(TCSADRAIN, %s) - OK\n", parity_table[i].parity );
|
||||
sc = tcsetattr( test, TCSANOW, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test all the stop bit options
|
||||
*/
|
||||
void test_termios_set_stop_bits(
|
||||
int test
|
||||
)
|
||||
{
|
||||
int sc;
|
||||
int i;
|
||||
int number;
|
||||
struct termios attr;
|
||||
|
||||
puts(
|
||||
"\n"
|
||||
"Test termios setting device character size ..."
|
||||
);
|
||||
for (i=0 ; stop_bits_table[i].constant != -1 ; i++ ) {
|
||||
sc = tcgetattr( test, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
attr.c_cflag &= ~CSTOPB;
|
||||
attr.c_cflag |= stop_bits_table[i].constant;
|
||||
|
||||
printf( "tcsetattr(TCSANOW, %d bit%s) - OK\n",
|
||||
stop_bits_table[i].stop,
|
||||
((stop_bits_table[i].stop == 1) ? "" : "s")
|
||||
);
|
||||
sc = tcsetattr( test, TCSANOW, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
printf( "tcsetattr(TCSADRAIN, %d bits) - OK\n", stop_bits_table[i].stop );
|
||||
sc = tcsetattr( test, TCSANOW, &attr );
|
||||
if ( sc != 0 ) {
|
||||
printf( "ERROR - return %d\n", sc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rtems_task Init(
|
||||
rtems_task_argument ignored
|
||||
)
|
||||
{
|
||||
int rc;
|
||||
rtems_status_code sc;
|
||||
rtems_device_major_number registered;
|
||||
int test;
|
||||
|
||||
puts( "\n\n*** TEST TERMIOS 01 ***" );
|
||||
|
||||
test_termios_baud2index();
|
||||
test_termios_baud2number();
|
||||
test_termios_number_to_baud();
|
||||
|
||||
puts(
|
||||
"\n"
|
||||
"Init - rtems_io_register_driver - Termios Test Driver - OK"
|
||||
);
|
||||
sc = rtems_io_register_driver( 0, &test_driver, ®istered );
|
||||
printf( "Init - Major slot returned = %d\n", (int) registered );
|
||||
directive_failed( sc, "rtems_io_register_driver" );
|
||||
|
||||
/*
|
||||
* Test baud rate
|
||||
*/
|
||||
puts( "Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" );
|
||||
test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
|
||||
if ( test == -1 ) {
|
||||
printf( "ERROR - baud opening test device (%d)\n", test );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
test_termios_set_baud(test);
|
||||
|
||||
puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" );
|
||||
rc = close( test );
|
||||
if ( rc != 0 ) {
|
||||
printf( "ERROR - baud close test device (%d) %s\n", test, strerror(errno) );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test character size
|
||||
*/
|
||||
puts(
|
||||
"\n"
|
||||
"Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK"
|
||||
);
|
||||
test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
|
||||
if ( test == -1 ) {
|
||||
printf( "ERROR - size open test device (%d) %s\n", test, strerror(errno) );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
test_termios_set_charsize(test);
|
||||
|
||||
puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" );
|
||||
rc = close( test );
|
||||
if ( rc != 0 ) {
|
||||
printf( "ERROR - size close test device (%d) %s\n", test, strerror(errno) );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test parity
|
||||
*/
|
||||
puts(
|
||||
"\n"
|
||||
"Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK"
|
||||
);
|
||||
test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
|
||||
if ( test == -1 ) {
|
||||
printf( "ERROR - parity open test device (%d) %s\n",
|
||||
test, strerror(errno) );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
test_termios_set_parity(test);
|
||||
|
||||
puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" );
|
||||
rc = close( test );
|
||||
if ( rc != 0 ) {
|
||||
printf( "ERROR - parity close test device (%d) %s\n",
|
||||
test, strerror(errno) );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test stop bits
|
||||
*/
|
||||
puts(
|
||||
"\n"
|
||||
"Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK"
|
||||
);
|
||||
test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
|
||||
if ( test == -1 ) {
|
||||
printf( "ERROR - stop bits open test device (%d) %s\n",
|
||||
test, strerror(errno) );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
test_termios_set_stop_bits(test);
|
||||
|
||||
puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" );
|
||||
rc = close( test );
|
||||
if ( rc != 0 ) {
|
||||
printf( "ERROR - stop bits close test device (%d) %s\n",
|
||||
test, strerror(errno) );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
puts( "*** END OF TEST TERMIOS 01 ***" );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
/* configuration information */
|
||||
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
|
||||
|
||||
/* 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 2
|
||||
|
||||
/* we need to be able to open the test device */
|
||||
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
|
||||
|
||||
#define CONFIGURE_MAXIMUM_TASKS 1
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
#include <rtems/confdefs.h>
|
||||
|
||||
/* global variables */
|
||||
30
testsuites/libtests/termios01/termios01.doc
Normal file
30
testsuites/libtests/termios01/termios01.doc
Normal file
@@ -0,0 +1,30 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
This file describes the directives and concepts tested by this test set.
|
||||
|
||||
test set name: termios01
|
||||
|
||||
directives:
|
||||
|
||||
open
|
||||
close
|
||||
tcgetattr
|
||||
tcsetattr
|
||||
rtems_termios_initialize
|
||||
rtems_termios_open
|
||||
rtems_termios_close
|
||||
rtems_termios_set_initial_baud
|
||||
|
||||
concepts:
|
||||
|
||||
+ Exercise termios ioctl for all baud, character size, parity and
|
||||
bits per character options.
|
||||
0
testsuites/libtests/termios01/termios01.scn
Normal file
0
testsuites/libtests/termios01/termios01.scn
Normal file
213
testsuites/libtests/termios01/termios_testdriver.c
Normal file
213
testsuites/libtests/termios01/termios_testdriver.c
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* This file contains a test fixture termios device driver
|
||||
*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
#include "tmacros.h"
|
||||
#include <rtems/libio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <termios.h>
|
||||
#include "termios_testdriver.h"
|
||||
|
||||
int termios_test_driver_inbyte_nonblocking( int port )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void termios_test_driver_outbyte_polled(
|
||||
int port,
|
||||
char ch
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
int termios_test_driver_write_support (int minor, const char *buf, int len)
|
||||
{
|
||||
int nwrite = 0;
|
||||
|
||||
while (nwrite < len) {
|
||||
#if (CONSOLE_USE_INTERRUPTS)
|
||||
termios_test_driver_outbyte_interrupt( minor, *buf++ );
|
||||
#else
|
||||
termios_test_driver_outbyte_polled( minor, *buf++ );
|
||||
#endif
|
||||
nwrite++;
|
||||
}
|
||||
return nwrite;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Set Attributes Handler
|
||||
*/
|
||||
int termios_test_driver_set_attributes(
|
||||
int minor,
|
||||
const struct termios *t
|
||||
)
|
||||
{
|
||||
uint32_t ulBaudDivisor;
|
||||
int baud_requested;
|
||||
int number;
|
||||
rtems_interrupt_level Irql;
|
||||
const char *parity = "NONE";
|
||||
const char *char_size = "5";
|
||||
const char *stop = "NONE";
|
||||
|
||||
baud_requested = t->c_cflag & CBAUD;
|
||||
|
||||
number = termios_baud_to_number( baud_requested );
|
||||
|
||||
/*
|
||||
* Parity
|
||||
*/
|
||||
if (t->c_cflag & PARENB) {
|
||||
parity = "EVEN";
|
||||
if (!(t->c_cflag & PARODD))
|
||||
parity = "ODD";
|
||||
}
|
||||
|
||||
/*
|
||||
* Character Size
|
||||
*/
|
||||
if (t->c_cflag & CSIZE) {
|
||||
switch (t->c_cflag & CSIZE) {
|
||||
case CS5: char_size = "5"; break;
|
||||
case CS6: char_size = "6"; break;
|
||||
case CS7: char_size = "7"; break;
|
||||
case CS8: char_size = "8"; break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Stop Bits
|
||||
*/
|
||||
if (t->c_cflag & CSTOPB)
|
||||
stop = "2";
|
||||
else
|
||||
stop = "1";
|
||||
|
||||
printf(
|
||||
"set_attributes - B%d %s-%s-%s\n",
|
||||
number,
|
||||
char_size,
|
||||
parity,
|
||||
stop
|
||||
);
|
||||
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_status_code sc;
|
||||
|
||||
rtems_termios_initialize();
|
||||
|
||||
/*
|
||||
* Register Device Names
|
||||
*/
|
||||
puts(
|
||||
"Termios_test_driver - rtems_io_register "
|
||||
TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK"
|
||||
);
|
||||
sc = rtems_io_register_name( TERMIOS_TEST_DRIVER_DEVICE_NAME, major, 0 );
|
||||
directive_failed( sc, "rtems_io_register_name" );
|
||||
|
||||
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;
|
||||
int rc;
|
||||
rtems_libio_open_close_args_t *args = arg;
|
||||
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 */
|
||||
0 /* outputUsesInterrupts */
|
||||
};
|
||||
|
||||
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, "rtems_termios_open" );
|
||||
|
||||
puts( "Termios_test_driver - rtems_set_initial_baud - bad baud - OK" );
|
||||
rc = rtems_termios_set_initial_baud( args->iop->data1, 5000 );
|
||||
if ( rc != -1 ) {
|
||||
printf( "ERROR - return %d\n", rc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
puts( "Termios_test_driver - rtems_set_initial_baud - 38400 - OK" );
|
||||
rc = rtems_termios_set_initial_baud( args->iop->data1, 38400 );
|
||||
if ( rc ) {
|
||||
printf( "ERROR - return %d\n", rc );
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
157
testsuites/libtests/termios01/termios_testdriver.h
Normal file
157
testsuites/libtests/termios01/termios_testdriver.h
Normal file
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* @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
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
Reference in New Issue
Block a user