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 <termios.h> |
---|
23 | #include <rtems/dumpbuf.h> |
---|
24 | #include <rtems/termiostypes.h> |
---|
25 | |
---|
26 | const char rtems_test_name[] = "TERMIOS 3"; |
---|
27 | |
---|
28 | /* forward declarations to avoid warnings */ |
---|
29 | rtems_task Init(rtems_task_argument argument); |
---|
30 | void write_helper(int fd, const char *c); |
---|
31 | void read_helper(int fd, const char *expected); |
---|
32 | void open_it(void); |
---|
33 | void close_it(void); |
---|
34 | void change_iflag(const char *desc, int mask, int new); |
---|
35 | |
---|
36 | void write_helper( |
---|
37 | int fd, |
---|
38 | const char *c |
---|
39 | ) |
---|
40 | { |
---|
41 | size_t len; |
---|
42 | int rc; |
---|
43 | |
---|
44 | len = strlen( c ); |
---|
45 | printf( "Writing: %s", c ); |
---|
46 | |
---|
47 | rc = write( fd, c, len ); |
---|
48 | rtems_test_assert( rc == len ); |
---|
49 | |
---|
50 | termios_test_driver_dump_tx("Transmitted"); |
---|
51 | } |
---|
52 | |
---|
53 | uint8_t read_helper_buffer[256]; |
---|
54 | |
---|
55 | void read_helper( |
---|
56 | int fd, |
---|
57 | const char *expected |
---|
58 | ) |
---|
59 | { |
---|
60 | int rc; |
---|
61 | size_t len; |
---|
62 | |
---|
63 | len = strlen( expected ); |
---|
64 | |
---|
65 | termios_test_driver_set_rx( expected, len ); |
---|
66 | printf( "\nReading (expected):\n" ); |
---|
67 | rtems_print_buffer( (unsigned char *)expected, len-1 ); |
---|
68 | |
---|
69 | rc = read( fd, read_helper_buffer, sizeof(read_helper_buffer) ); |
---|
70 | rtems_test_assert( rc != -1 ); |
---|
71 | |
---|
72 | printf( "Read %d bytes from read(2)\n", rc ); |
---|
73 | rtems_print_buffer( read_helper_buffer, rc ); |
---|
74 | |
---|
75 | termios_test_driver_dump_tx("Echoed"); |
---|
76 | } |
---|
77 | |
---|
78 | int Test_fd; |
---|
79 | |
---|
80 | void open_it(void) |
---|
81 | { |
---|
82 | /* open the file */ |
---|
83 | puts( "open(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " ); |
---|
84 | Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); |
---|
85 | rtems_test_assert( Test_fd != -1 ); |
---|
86 | } |
---|
87 | |
---|
88 | void close_it(void) |
---|
89 | { |
---|
90 | int rc; |
---|
91 | |
---|
92 | puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " ); |
---|
93 | rc = close( Test_fd ); |
---|
94 | rtems_test_assert( rc == 0 ); |
---|
95 | } |
---|
96 | |
---|
97 | void change_iflag( const char *desc, int mask, int new ) |
---|
98 | { |
---|
99 | int rc; |
---|
100 | struct termios attr; |
---|
101 | |
---|
102 | printf( "Changing c_iflag to: %s\n", desc ); |
---|
103 | rc = tcgetattr( Test_fd, &attr ); |
---|
104 | rtems_test_assert( rc == 0 ); |
---|
105 | |
---|
106 | attr.c_iflag &= ~mask; |
---|
107 | attr.c_iflag |= new; |
---|
108 | |
---|
109 | rc = tcsetattr( Test_fd, TCSANOW, &attr ); |
---|
110 | rtems_test_assert( rc == 0 ); |
---|
111 | } |
---|
112 | |
---|
113 | const char ExpectedOutput_1[] = "This is test output.\n"; |
---|
114 | const char ExpectedInput_1[] = "Test input this is.\n"; |
---|
115 | const char ExpectedInput_2[] = "1235\b456.\n"; |
---|
116 | const char ExpectedInput_3[] = "tab\ttab.\n"; |
---|
117 | const char ExpectedInput_4[] = "cr\r."; |
---|
118 | const char ExpectedInput_5[] = "aBcDeFgH.\n"; |
---|
119 | const char ExpectedInput_6[] = "Testing VERASE\177.\n"; |
---|
120 | const char ExpectedInput_7[] = "Testing VKILL\025.\n"; |
---|
121 | const char ExpectedInput_8[] = "\177Testing VERASE in column 1.\n"; |
---|
122 | const char ExpectedInput_9[] = "\t tab \tTesting VKILL after tab.\025\n"; |
---|
123 | |
---|
124 | rtems_task Init( |
---|
125 | rtems_task_argument argument |
---|
126 | ) |
---|
127 | { |
---|
128 | TEST_BEGIN(); |
---|
129 | |
---|
130 | open_it(); |
---|
131 | |
---|
132 | /* some basic cases */ |
---|
133 | write_helper( Test_fd, ExpectedOutput_1 ); |
---|
134 | read_helper( Test_fd, ExpectedInput_1 ); |
---|
135 | read_helper( Test_fd, ExpectedInput_2 ); |
---|
136 | read_helper( Test_fd, ExpectedInput_3 ); |
---|
137 | read_helper( Test_fd, ExpectedInput_4 ); |
---|
138 | |
---|
139 | /* test to lower case input mapping */ |
---|
140 | read_helper( Test_fd, ExpectedInput_5 ); |
---|
141 | change_iflag( "Enable to lower case mapping on input", IUCLC, IUCLC ); |
---|
142 | read_helper( Test_fd, ExpectedInput_5 ); |
---|
143 | change_iflag( "Disable to lower case mapping on input", IUCLC, 0 ); |
---|
144 | |
---|
145 | read_helper( Test_fd, ExpectedInput_6 ); |
---|
146 | read_helper( Test_fd, ExpectedInput_7 ); |
---|
147 | read_helper( Test_fd, ExpectedInput_8 ); |
---|
148 | read_helper( Test_fd, ExpectedInput_9 ); |
---|
149 | |
---|
150 | puts( "" ); |
---|
151 | close_it(); |
---|
152 | |
---|
153 | TEST_END(); |
---|
154 | |
---|
155 | rtems_test_exit(0); |
---|
156 | } |
---|
157 | |
---|
158 | /* configuration information */ |
---|
159 | |
---|
160 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
161 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
162 | #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \ |
---|
163 | TERMIOS_TEST_DRIVER_TABLE_ENTRY |
---|
164 | |
---|
165 | /* include an extra slot for registering the termios one dynamically */ |
---|
166 | #define CONFIGURE_MAXIMUM_DRIVERS 3 |
---|
167 | |
---|
168 | /* we need to be able to open the test device */ |
---|
169 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 |
---|
170 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
171 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
172 | |
---|
173 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
174 | |
---|
175 | #define CONFIGURE_INIT |
---|
176 | |
---|
177 | #include <rtems/confdefs.h> |
---|
178 | /* end of file */ |
---|