source: rtems/testsuites/libtests/termios08/init.c @ 53b6484

5
Last change on this file since 53b6484 was 53b6484, checked in by Sebastian Huber <sebastian.huber@…>, on 02/05/18 at 08:57:45

termios: Remove obsolete configuration options

Update #2843.

  • Property mode set to 100644
File size: 3.7 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 8";
27
28/* forward declarations to avoid warnings */
29rtems_task Init(rtems_task_argument argument);
30void open_it(void);
31void close_it(void);
32void write_it(void);
33void change_lflag( const char *desc, int mask, int new );
34void change_vmin_vtime( const char *desc, int min, int time );
35void read_it(ssize_t expected);
36
37int Test_fd;
38
39void open_it(void)
40{
41  /* open the file */
42  puts( "open(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
43  Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
44  rtems_test_assert( Test_fd != -1 );
45}
46
47void close_it(void)
48{
49  int rc;
50
51  puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
52  rc = close( Test_fd );
53  rtems_test_assert( rc == 0 );
54}
55
56void write_it(void)
57{
58  ssize_t sc;
59  char    ch[10] = "PPPD TEST";
60
61  puts( "write(PPPD TEST) - OK " );
62  sc = write(Test_fd, ch, sizeof(ch));
63  rtems_test_assert( sc == sizeof(ch) );
64}
65
66uint8_t read_helper_buffer[256];
67
68void change_lflag( const char *desc, int mask, int new )
69{
70  int            rc;
71  struct termios attr;
72
73  printf( "Changing c_lflag to: %s\n", desc );
74  rc = tcgetattr( Test_fd, &attr );
75  rtems_test_assert( rc == 0 );
76
77  attr.c_lflag &= ~mask;
78  attr.c_lflag |= new;
79
80  rc = tcsetattr( Test_fd, TCSANOW, &attr );
81  rtems_test_assert( rc == 0 );
82}
83
84void change_vmin_vtime( const char *desc, int min, int time )
85{
86  int            rc;
87  struct termios attr;
88
89  printf( "Changing %s - VMIN=%d VTIME=%d\n", desc, min, time );
90  rc = tcgetattr( Test_fd, &attr );
91  rtems_test_assert( rc == 0 );
92
93  attr.c_cc[VMIN] = min;
94  attr.c_cc[VTIME] = time;
95
96  rc = tcsetattr( Test_fd, TCSANOW, &attr );
97  rtems_test_assert( rc == 0 );
98}
99
100void read_it( ssize_t expected )
101{
102  ssize_t rc;
103  char    buf[32];
104
105  rtems_test_assert( expected <= sizeof(buf) );
106
107  printf( "read - %zd expected\n", expected );
108  rc = read( Test_fd, buf, expected );
109  if ( expected != rc )
110    printf( "ERROR - expected=%zd rc=%zd\n", expected, rc );
111  rtems_test_assert( expected == rc );
112}
113
114rtems_task Init(
115  rtems_task_argument argument
116)
117{
118  TEST_BEGIN();
119
120  open_it();
121  change_lflag( "non-canonical", ICANON, 0 );
122
123  change_vmin_vtime( "to polling", 0, 0 );
124  read_it( 0 );
125
126  change_vmin_vtime( "to half-second timeout", 0, 5 );
127  read_it( 0 );
128
129  change_vmin_vtime( "to half-second timeout", 5, 3 );
130  puts( "Enqueue 2 characters" );
131  termios_test_driver_set_rx( "ab", 2 );
132  read_it( 2 );
133
134  change_vmin_vtime( "to half-second timeout", 5, 3 );
135  puts( "Enqueue 1 character" );
136  termios_test_driver_set_rx( "b", 1 );
137  read_it( 1 );
138
139  puts( "Enqueue 7 characters" );
140  termios_test_driver_set_rx( "1234567", 7 );
141  read_it( 5 );
142  read_it( 2 );
143
144  close_it();
145 
146  TEST_END();
147
148  rtems_test_exit(0);
149}
150
151/* configuration information */
152
153#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
154#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
155#define CONFIGURE_APPLICATION_EXTRA_DRIVERS TERMIOS_TEST_DRIVER_TABLE_ENTRY
156
157/* we need to be able to open the test device */
158#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
159
160#define CONFIGURE_MAXIMUM_TASKS             1
161#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
162
163#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
164
165#define CONFIGURE_INIT
166
167#include <rtems/confdefs.h>
168/* end of file */
Note: See TracBrowser for help on using the repository browser.