1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2010. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #include <tmacros.h> |
---|
13 | #include "test_support.h" |
---|
14 | #include "termios_testdriver_polled.h" |
---|
15 | |
---|
16 | #include <sys/types.h> |
---|
17 | #include <sys/stat.h> |
---|
18 | #include <fcntl.h> |
---|
19 | #include <unistd.h> |
---|
20 | #include <sys/ioctl.h> |
---|
21 | #include <rtems/dumpbuf.h> |
---|
22 | #include <rtems/termiostypes.h> |
---|
23 | |
---|
24 | void pppasyncattach(void); |
---|
25 | void ppp_test_driver_set_rx( const char *expected, size_t len ); |
---|
26 | |
---|
27 | int Test_fd; |
---|
28 | int InitialDiscipline; |
---|
29 | |
---|
30 | void open_it(void) |
---|
31 | { |
---|
32 | /* open the file */ |
---|
33 | puts( "open(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " ); |
---|
34 | Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); |
---|
35 | rtems_test_assert( Test_fd != -1 ); |
---|
36 | } |
---|
37 | |
---|
38 | void Rx_Wake( |
---|
39 | struct termios *tty, |
---|
40 | void *arg |
---|
41 | ) |
---|
42 | { |
---|
43 | printk( "Rx_Wake - invoked\n" ); |
---|
44 | } |
---|
45 | |
---|
46 | void Tx_Wake( |
---|
47 | struct termios *tty, |
---|
48 | void *arg |
---|
49 | ) |
---|
50 | { |
---|
51 | printk( "Tx_Wake - invoked\n" ); |
---|
52 | } |
---|
53 | |
---|
54 | struct ttywakeup RxWake = { Rx_Wake, NULL }; |
---|
55 | struct ttywakeup TxWake = { Tx_Wake, NULL }; |
---|
56 | |
---|
57 | void set_wakeups(void) |
---|
58 | { |
---|
59 | int sc; |
---|
60 | |
---|
61 | puts( "ioctl - RTEMS_IO_SNDWAKEUP - OK" ); |
---|
62 | sc = ioctl( Test_fd, RTEMS_IO_SNDWAKEUP, &TxWake ); |
---|
63 | rtems_test_assert( sc == 0 ); |
---|
64 | |
---|
65 | puts( "ioctl - RTEMS_IO_RCVWAKEUP - OK" ); |
---|
66 | sc = ioctl( Test_fd, RTEMS_IO_RCVWAKEUP, &RxWake ); |
---|
67 | rtems_test_assert( sc == 0 ); |
---|
68 | |
---|
69 | } |
---|
70 | |
---|
71 | void set_discipline(void) |
---|
72 | { |
---|
73 | int pppdisc = PPPDISC; |
---|
74 | int sc; |
---|
75 | |
---|
76 | puts( "ioctl - TIOCGETD - OK" ); |
---|
77 | sc = ioctl(Test_fd, TIOCGETD, &InitialDiscipline); |
---|
78 | rtems_test_assert( sc == 0 ); |
---|
79 | |
---|
80 | puts( "ioctl - TIOCSETD - OK" ); |
---|
81 | sc = ioctl(Test_fd, TIOCSETD, &pppdisc); |
---|
82 | rtems_test_assert( sc == 0 ); |
---|
83 | |
---|
84 | puts( "ioctl - TIOCSETD - OK" ); |
---|
85 | sc = ioctl(Test_fd, TIOCSETD, &pppdisc); |
---|
86 | rtems_test_assert( sc == 0 ); |
---|
87 | } |
---|
88 | |
---|
89 | void ioctl_it(void) |
---|
90 | { |
---|
91 | int rc; |
---|
92 | struct termios t; |
---|
93 | |
---|
94 | puts( "ioctl(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " ); |
---|
95 | rc = ioctl( Test_fd, 0xFFFF, NULL ); |
---|
96 | rtems_test_assert( rc == 0 ); |
---|
97 | |
---|
98 | puts( "tcgetattr(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " ); |
---|
99 | rc = tcgetattr( Test_fd, &t ); |
---|
100 | rtems_test_assert( rc == 0 ); |
---|
101 | |
---|
102 | puts( "Turn on flow control on output - OK" ); |
---|
103 | t.c_iflag |= IXON; |
---|
104 | rc = tcsetattr( Test_fd, TCSANOW, &t ); |
---|
105 | rtems_test_assert( rc == 0 ); |
---|
106 | |
---|
107 | puts( "Turn off flow control on output - OK" ); |
---|
108 | t.c_iflag &= ~IXON; |
---|
109 | rc = tcsetattr( Test_fd, TCSANOW, &t ); |
---|
110 | rtems_test_assert( rc == 0 ); |
---|
111 | |
---|
112 | puts( "Turn on flow control on input - OK" ); |
---|
113 | t.c_iflag |= IXOFF; |
---|
114 | rc = tcsetattr( Test_fd, TCSANOW, &t ); |
---|
115 | rtems_test_assert( rc == 0 ); |
---|
116 | |
---|
117 | puts( "Turn off flow control on input - OK" ); |
---|
118 | t.c_iflag &= ~IXOFF; |
---|
119 | rc = tcsetattr( Test_fd, TCSANOW, &t ); |
---|
120 | rtems_test_assert( rc == 0 ); |
---|
121 | } |
---|
122 | |
---|
123 | void close_it(void) |
---|
124 | { |
---|
125 | int rc; |
---|
126 | |
---|
127 | puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " ); |
---|
128 | rc = close( Test_fd ); |
---|
129 | rtems_test_assert( rc == 0 ); |
---|
130 | } |
---|
131 | |
---|
132 | void write_it(void) |
---|
133 | { |
---|
134 | ssize_t sc; |
---|
135 | char ch[10] = "PPPD TEST"; |
---|
136 | |
---|
137 | puts( "write(PPPD TEST) - OK " ); |
---|
138 | sc = write(Test_fd, ch, sizeof(ch)); |
---|
139 | rtems_test_assert( sc == sizeof(ch) ); |
---|
140 | } |
---|
141 | |
---|
142 | uint8_t read_helper_buffer[256]; |
---|
143 | |
---|
144 | void read_helper( |
---|
145 | int fd, |
---|
146 | const char *expected |
---|
147 | ) |
---|
148 | { |
---|
149 | int rc; |
---|
150 | size_t len; |
---|
151 | |
---|
152 | len = strlen( expected ); |
---|
153 | |
---|
154 | ppp_test_driver_set_rx( expected, len ); |
---|
155 | printf( "\nReading (expected):\n" ); |
---|
156 | rtems_print_buffer( (unsigned char *)expected, len-1 ); |
---|
157 | |
---|
158 | rc = read( fd, read_helper_buffer, sizeof(read_helper_buffer) ); |
---|
159 | rtems_test_assert( rc != -1 ); |
---|
160 | |
---|
161 | printf( "Read %d bytes from read(2)\n", rc ); |
---|
162 | rtems_print_buffer( read_helper_buffer, rc ); |
---|
163 | } |
---|
164 | |
---|
165 | void read_it(void) |
---|
166 | { |
---|
167 | read_helper( Test_fd, "This is test PPP input." ); |
---|
168 | } |
---|
169 | |
---|
170 | rtems_task Init( |
---|
171 | rtems_task_argument argument |
---|
172 | ) |
---|
173 | { |
---|
174 | puts( "\n\n*** TEST TERMIOS06 ***" ); |
---|
175 | |
---|
176 | pppasyncattach(); |
---|
177 | open_it(); |
---|
178 | set_wakeups(); |
---|
179 | set_discipline(); |
---|
180 | write_it(); |
---|
181 | ioctl_it(); |
---|
182 | read_it(); |
---|
183 | close_it(); |
---|
184 | |
---|
185 | puts( "*** END OF TEST TERMIOS06 ***" ); |
---|
186 | |
---|
187 | rtems_test_exit(0); |
---|
188 | } |
---|
189 | |
---|
190 | /* configuration information */ |
---|
191 | |
---|
192 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
193 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
194 | #define CONFIGURE_APPLICATION_EXTRA_DRIVERS TERMIOS_TEST_DRIVER_TABLE_ENTRY |
---|
195 | |
---|
196 | /* one for the console and one for the test port */ |
---|
197 | #define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 3 |
---|
198 | |
---|
199 | /* we need to be able to open the test device */ |
---|
200 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 |
---|
201 | |
---|
202 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
203 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
204 | |
---|
205 | #define CONFIGURE_INIT |
---|
206 | |
---|
207 | #include <rtems/confdefs.h> |
---|
208 | /* end of file */ |
---|