static rtems_task Init( rtems_task_argument ignored ) { int rc; rtems_status_code sc; rtems_device_major_number registered; int test; struct termios t; int index = 0; TEST_BEGIN(); test_termios_baud2index(); test_termios_baud2number(); test_termios_number_to_baud(); sc = rtems_termios_bufsize( 256, 128, 64 ); directive_failed( sc, "rtems_termios_bufsize" ); /* * Register a driver */ 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); } /* * tcsetattr - ERROR invalid operation */ puts( "tcsetattr - invalid operation - ENOTSUP" ); rc = tcsetattr( test, INT_MAX, &t ); rtems_test_assert( rc == -1 ); rtems_test_assert( errno == ENOTSUP ); test_termios_cfmakeraw(); /* * tcsetattr - TCSADRAIN */ puts( "\ntcsetattr - drain - OK" ); rc = tcsetattr( test, TCSADRAIN, &t ); rtems_test_assert( rc == 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); test_termios_cfoutspeed(); test_termios_cfinspeed(); test_termios_cfsetspeed(); 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( "Multiple open of the device" ); for( ; index < 26; ++index ) { test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); rtems_test_assert( test != -1 ); rc = close( test ); rtems_test_assert( rc == 0 ); } puts( "" ); TEST_END(); rtems_test_exit(0); }
static void test_set_attributes_error(void) { static const rtems_termios_device_handler handler = { .set_attributes = set_attributes_error }; static const char dev[] = "/foobar"; rtems_resource_snapshot snapshot; rtems_status_code sc; struct termios term; device_context ctx = { .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "abc" ), .done = false }; int fd; int rv; rtems_resource_snapshot_take( &snapshot ); sc = rtems_termios_device_install( &dev[0], &handler, NULL, &ctx.base ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); fd = open( &dev[0], O_RDWR ); rtems_test_assert( fd >= 0 ); rtems_test_assert( !ctx.done ); errno = 0; rv = ioctl( fd, TIOCSETA, &term ); rtems_test_assert( rv == -1 ); rtems_test_assert( errno == EIO ); rtems_test_assert( ctx.done ); rv = close( fd ); rtems_test_assert( rv == 0 ); rv = unlink( &dev[0] ); rtems_test_assert( rv == 0 ); rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); } static void test_set_best_baud(void) { static const struct { uint32_t baud; speed_t speed; } baud_to_speed_table[] = { { 0, B0 }, { 25, B0 }, { 26, B50 }, { 50, B50 }, { 62, B50 }, { 63, B75 }, { 75, B75 }, { 110, B110 }, { 134, B134 }, { 150, B150 }, { 200, B200 }, { 300, B300 }, { 600, B600 }, { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 }, { 4800, B4800 }, { 9600, B9600 }, { 19200, B19200 }, { 38400, B38400 }, { 57600, B57600 }, { 115200, B115200 }, { 230400, B230400 }, { 460800, B460800 }, { 0xffffffff, B460800 } }; size_t n = RTEMS_ARRAY_SIZE(baud_to_speed_table); size_t i; for ( i = 0; i < n; ++i ) { struct termios term; memset( &term, 0xff, sizeof( term ) ); rtems_termios_set_best_baud( &term, baud_to_speed_table[ i ].baud ); rtems_test_assert( term.c_ispeed == baud_to_speed_table[ i ].speed ); rtems_test_assert( term.c_ospeed == baud_to_speed_table[ i ].speed ); } } static rtems_task Init( rtems_task_argument ignored ) { int rc; rtems_status_code sc; rtems_device_major_number registered; int test; struct termios t; int index = 0; TEST_BEGIN(); test_termios_baud2index(); test_termios_baud2number(); test_termios_number_to_baud(); sc = rtems_termios_bufsize( 256, 128, 64 ); directive_failed( sc, "rtems_termios_bufsize" ); /* * Register a driver */ 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); } /* * tcsetattr - ERROR invalid operation */ puts( "tcsetattr - invalid operation - EINVAL" ); rc = tcsetattr( test, INT_MAX, &t ); rtems_test_assert( rc == -1 ); rtems_test_assert( errno == EINVAL ); test_termios_cfmakeraw(); test_termios_cfmakesane(); /* * tcsetattr - TCSADRAIN */ puts( "\ntcsetattr - drain - OK" ); rc = tcsetattr( test, TCSADRAIN, &t ); rtems_test_assert( rc == 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); test_termios_cfoutspeed(); test_termios_cfinspeed(); test_termios_cfsetspeed(); 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( "Multiple open of the device" ); for( ; index < 26; ++index ) { test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); rtems_test_assert( test != -1 ); rc = close( test ); rtems_test_assert( rc == 0 ); } puts( "" ); test_device_install_remove(); test_first_open_error(); test_set_attributes_error(); test_set_best_baud(); TEST_END(); rtems_test_exit(0); }