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 | |
---|
26 | const char rtems_test_name[] = "TERMIOS 8"; |
---|
27 | |
---|
28 | /* forward declarations to avoid warnings */ |
---|
29 | rtems_task Init(rtems_task_argument argument); |
---|
30 | void open_it(void); |
---|
31 | void close_it(void); |
---|
32 | void write_it(void); |
---|
33 | void change_lflag( const char *desc, int mask, int new ); |
---|
34 | void change_vmin_vtime( const char *desc, int min, int time ); |
---|
35 | void read_it(ssize_t expected); |
---|
36 | |
---|
37 | int Test_fd; |
---|
38 | |
---|
39 | void 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 | |
---|
47 | void 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 | |
---|
56 | void 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 | |
---|
66 | uint8_t read_helper_buffer[256]; |
---|
67 | |
---|
68 | void 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 | |
---|
84 | void 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 | |
---|
100 | void 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 | |
---|
114 | rtems_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 */ |
---|