source: rtems/testsuites/libtests/termios06/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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