File indexing completed on 2025-05-11 08:24:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032
0033 #include <tmacros.h>
0034 #include "test_support.h"
0035 #include "../termios03/termios_testdriver_polled.h"
0036
0037 #include <sys/types.h>
0038 #include <sys/stat.h>
0039 #include <fcntl.h>
0040 #include <unistd.h>
0041 #include <sys/ioctl.h>
0042 #include <rtems/bspIo.h>
0043 #include <rtems/dumpbuf.h>
0044 #include <rtems/termiostypes.h>
0045
0046 const char rtems_test_name[] = "TERMIOS 6";
0047
0048
0049 rtems_task Init(rtems_task_argument argument);
0050 void open_it(void);
0051 void Rx_Wake(struct termios *tty, void *arg);
0052 void Tx_Wake(struct termios *tty, void *arg);
0053 void set_wakeups(void);
0054 void set_discipline(void);
0055 void ioctl_it(void);
0056 void close_it(void);
0057 void write_it(void);
0058 void read_helper(int fd, const char *expected);
0059 void read_it(void);
0060
0061 void pppasyncattach(void);
0062 void ppp_test_driver_set_rx( const char *expected, size_t len );
0063
0064 int Test_fd;
0065 int InitialDiscipline;
0066
0067 void open_it(void)
0068 {
0069
0070 puts( "open(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
0071 Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
0072 rtems_test_assert( Test_fd != -1 );
0073 }
0074
0075 void Rx_Wake(
0076 struct termios *tty,
0077 void *arg
0078 )
0079 {
0080 printk( "Rx_Wake - invoked\n" );
0081 }
0082
0083 void Tx_Wake(
0084 struct termios *tty,
0085 void *arg
0086 )
0087 {
0088 printk( "Tx_Wake - invoked\n" );
0089 }
0090
0091 struct ttywakeup RxWake = { Rx_Wake, NULL };
0092 struct ttywakeup TxWake = { Tx_Wake, NULL };
0093
0094 void set_wakeups(void)
0095 {
0096 int sc;
0097
0098 puts( "ioctl - RTEMS_IO_SNDWAKEUP - OK" );
0099 sc = ioctl( Test_fd, RTEMS_IO_SNDWAKEUP, &TxWake );
0100 rtems_test_assert( sc == 0 );
0101
0102 puts( "ioctl - RTEMS_IO_RCVWAKEUP - OK" );
0103 sc = ioctl( Test_fd, RTEMS_IO_RCVWAKEUP, &RxWake );
0104 rtems_test_assert( sc == 0 );
0105
0106 }
0107
0108 void set_discipline(void)
0109 {
0110 int pppdisc = PPPDISC;
0111 int sc;
0112
0113 puts( "ioctl - TIOCGETD - OK" );
0114 sc = ioctl(Test_fd, TIOCGETD, &InitialDiscipline);
0115 rtems_test_assert( sc == 0 );
0116
0117 puts( "ioctl - TIOCSETD - OK" );
0118 sc = ioctl(Test_fd, TIOCSETD, &pppdisc);
0119 rtems_test_assert( sc == 0 );
0120
0121 puts( "ioctl - TIOCSETD - OK" );
0122 sc = ioctl(Test_fd, TIOCSETD, &pppdisc);
0123 rtems_test_assert( sc == 0 );
0124 }
0125
0126 void ioctl_it(void)
0127 {
0128 int rc;
0129 struct termios t;
0130
0131 puts( "ioctl(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
0132 rc = ioctl( Test_fd, 0xFFFF, NULL );
0133 rtems_test_assert( rc == 0 );
0134
0135 puts( "tcgetattr(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
0136 rc = tcgetattr( Test_fd, &t );
0137 rtems_test_assert( rc == 0 );
0138
0139 puts( "Turn on flow control on output - OK" );
0140 t.c_iflag |= IXON;
0141 rc = tcsetattr( Test_fd, TCSANOW, &t );
0142 rtems_test_assert( rc == 0 );
0143
0144 puts( "Turn off flow control on output - OK" );
0145 t.c_iflag &= ~IXON;
0146 rc = tcsetattr( Test_fd, TCSANOW, &t );
0147 rtems_test_assert( rc == 0 );
0148
0149 puts( "Turn on flow control on input - OK" );
0150 t.c_iflag |= IXOFF;
0151 rc = tcsetattr( Test_fd, TCSANOW, &t );
0152 rtems_test_assert( rc == 0 );
0153
0154 puts( "Turn off flow control on input - OK" );
0155 t.c_iflag &= ~IXOFF;
0156 rc = tcsetattr( Test_fd, TCSANOW, &t );
0157 rtems_test_assert( rc == 0 );
0158 }
0159
0160 void close_it(void)
0161 {
0162 int rc;
0163
0164 puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
0165 rc = close( Test_fd );
0166 rtems_test_assert( rc == 0 );
0167 }
0168
0169 void write_it(void)
0170 {
0171 ssize_t sc;
0172 char ch[10] = "PPPD TEST";
0173
0174 puts( "write(PPPD TEST) - OK " );
0175 sc = write(Test_fd, ch, sizeof(ch));
0176 rtems_test_assert( sc == sizeof(ch) );
0177 }
0178
0179 uint8_t read_helper_buffer[256];
0180
0181 void read_helper(
0182 int fd,
0183 const char *expected
0184 )
0185 {
0186 int rc;
0187 size_t len;
0188
0189 len = strlen( expected );
0190
0191 ppp_test_driver_set_rx( expected, len );
0192 printf( "\nReading (expected):\n" );
0193 rtems_print_buffer( (unsigned char *)expected, len-1 );
0194
0195 rc = read( fd, read_helper_buffer, sizeof(read_helper_buffer) );
0196 rtems_test_assert( rc != -1 );
0197
0198 printf( "Read %d bytes from read(2)\n", rc );
0199 rtems_print_buffer( read_helper_buffer, rc );
0200 }
0201
0202 void read_it(void)
0203 {
0204 read_helper( Test_fd, "This is test PPP input." );
0205 }
0206
0207 rtems_task Init(
0208 rtems_task_argument argument
0209 )
0210 {
0211 TEST_BEGIN();
0212
0213 pppasyncattach();
0214 open_it();
0215 set_wakeups();
0216 set_discipline();
0217 write_it();
0218 ioctl_it();
0219 read_it();
0220 close_it();
0221
0222 TEST_END();
0223
0224 rtems_test_exit(0);
0225 }
0226
0227
0228
0229 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0230 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0231 #define CONFIGURE_APPLICATION_EXTRA_DRIVERS TERMIOS_TEST_DRIVER_TABLE_ENTRY
0232
0233
0234 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0235
0236 #define CONFIGURE_MAXIMUM_TASKS 1
0237 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0238
0239 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0240
0241 #define CONFIGURE_INIT
0242
0243 #include <rtems/confdefs.h>
0244