[4d5b156] | 1 | /* |
---|
[8cd0bb0f] | 2 | * COPYRIGHT (c) 1989-2010. |
---|
[4d5b156] | 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 |
---|
[c499856] | 7 | * http://www.rtems.org/license/LICENSE. |
---|
[4d5b156] | 8 | */ |
---|
| 9 | |
---|
[7d3f9c6] | 10 | #ifdef HAVE_CONFIG_H |
---|
| 11 | #include "config.h" |
---|
| 12 | #endif |
---|
| 13 | |
---|
[4d5b156] | 14 | #include "tmacros.h" |
---|
[1c6926c1] | 15 | #define TTYDEFCHARS |
---|
[4d5b156] | 16 | #include <termios.h> |
---|
[ef8c00bc] | 17 | #include <rtems/libcsupport.h> |
---|
| 18 | #include <rtems/malloc.h> |
---|
[4d5b156] | 19 | #include <rtems/termiostypes.h> |
---|
| 20 | #include <fcntl.h> |
---|
[a9127a2e] | 21 | #include <limits.h> |
---|
[55e0be36] | 22 | #include <unistd.h> |
---|
[4d5b156] | 23 | #include <sys/errno.h> |
---|
[55e0be36] | 24 | #include <sys/stat.h> |
---|
[4d5b156] | 25 | |
---|
[f8b2eb03] | 26 | const char rtems_test_name[] = "TERMIOS 1"; |
---|
| 27 | |
---|
[1466425] | 28 | /* rtems_termios_baud_t is a typedefs to int32_t */ |
---|
| 29 | #define PRIdrtems_termios_baud_t PRId32 |
---|
| 30 | |
---|
[4d5b156] | 31 | /* |
---|
| 32 | * Termios Test Driver |
---|
| 33 | */ |
---|
| 34 | #include "termios_testdriver.h" |
---|
| 35 | |
---|
[f55595e] | 36 | static const rtems_driver_address_table test_driver = |
---|
| 37 | TERMIOS_TEST_DRIVER_TABLE_ENTRY; |
---|
[4d5b156] | 38 | |
---|
| 39 | /* |
---|
| 40 | * Baud Rate Constant Mapping Entry |
---|
| 41 | */ |
---|
| 42 | typedef struct { |
---|
[f55595e] | 43 | tcflag_t constant; |
---|
[009dfd0] | 44 | rtems_termios_baud_t baud; |
---|
[4d5b156] | 45 | } termios_baud_test_r; |
---|
| 46 | |
---|
[f55595e] | 47 | #define INVALID_CONSTANT ((tcflag_t) -2) |
---|
| 48 | |
---|
| 49 | #define INVALID_BAUD ((rtems_termios_baud_t) -2) |
---|
[4d5b156] | 50 | /* |
---|
| 51 | * Baud Rate Constant Mapping Table |
---|
| 52 | */ |
---|
[f55595e] | 53 | static const termios_baud_test_r baud_table[] = { |
---|
[4d5b156] | 54 | { B0, 0 }, |
---|
| 55 | { B50, 50 }, |
---|
| 56 | { B75, 75 }, |
---|
| 57 | { B110, 110 }, |
---|
| 58 | { B134, 134 }, |
---|
| 59 | { B150, 150 }, |
---|
| 60 | { B200, 200 }, |
---|
| 61 | { B300, 300 }, |
---|
| 62 | { B600, 600 }, |
---|
| 63 | { B1200, 1200 }, |
---|
| 64 | { B1800, 1800 }, |
---|
| 65 | { B2400, 2400 }, |
---|
| 66 | { B4800, 4800 }, |
---|
| 67 | { B9600, 9600 }, |
---|
| 68 | { B19200, 19200 }, |
---|
| 69 | { B38400, 38400 }, |
---|
[1c6926c1] | 70 | { B7200, 7200 }, |
---|
| 71 | { B14400, 14400 }, |
---|
| 72 | { B28800, 28800 }, |
---|
[4d5b156] | 73 | { B57600, 57600 }, |
---|
[1c6926c1] | 74 | { B76800, 76800 }, |
---|
[4d5b156] | 75 | { B115200, 115200 }, |
---|
| 76 | { B230400, 230400 }, |
---|
| 77 | { B460800, 460800 }, |
---|
[1c6926c1] | 78 | { B921600, 921600 }, |
---|
[f55595e] | 79 | { INVALID_CONSTANT, INVALID_BAUD } |
---|
[4d5b156] | 80 | }; |
---|
| 81 | |
---|
| 82 | /* |
---|
| 83 | * Character Size Constant Mapping Entry |
---|
| 84 | */ |
---|
| 85 | typedef struct { |
---|
[f55595e] | 86 | tcflag_t constant; |
---|
[4d5b156] | 87 | int bits; |
---|
| 88 | } termios_character_size_test_r; |
---|
| 89 | |
---|
| 90 | /* |
---|
| 91 | * Character Size Constant Mapping Table |
---|
| 92 | */ |
---|
[f55595e] | 93 | static const termios_character_size_test_r char_size_table[] = { |
---|
[4d5b156] | 94 | { CS5, 5 }, |
---|
| 95 | { CS6, 6 }, |
---|
| 96 | { CS7, 7 }, |
---|
| 97 | { CS8, 8 }, |
---|
[f55595e] | 98 | { INVALID_CONSTANT, -1 } |
---|
[4d5b156] | 99 | }; |
---|
| 100 | |
---|
| 101 | /* |
---|
| 102 | * Parity Constant Mapping Entry |
---|
| 103 | */ |
---|
| 104 | typedef struct { |
---|
[f55595e] | 105 | tcflag_t constant; |
---|
[1466425] | 106 | const char *parity; |
---|
[4d5b156] | 107 | } termios_parity_test_r; |
---|
| 108 | |
---|
| 109 | /* |
---|
| 110 | * Parity Constant Mapping Table |
---|
| 111 | */ |
---|
[f55595e] | 112 | static const termios_parity_test_r parity_table[] = { |
---|
[4d5b156] | 113 | { 0, "none" }, |
---|
| 114 | { PARENB, "even" }, |
---|
| 115 | { PARENB | PARODD, "odd" }, |
---|
[f55595e] | 116 | { INVALID_CONSTANT, NULL } |
---|
[4d5b156] | 117 | }; |
---|
| 118 | |
---|
| 119 | /* |
---|
| 120 | * Stop Bit Constant Mapping Entry |
---|
| 121 | */ |
---|
| 122 | typedef struct { |
---|
[f55595e] | 123 | tcflag_t constant; |
---|
| 124 | int stop; |
---|
[4d5b156] | 125 | } termios_stop_bits_test_r; |
---|
| 126 | |
---|
| 127 | /* |
---|
| 128 | * Stop Bit Constant Mapping Table |
---|
| 129 | */ |
---|
[f55595e] | 130 | static const termios_stop_bits_test_r stop_bits_table[] = { |
---|
[4d5b156] | 131 | { 0, 1 }, |
---|
| 132 | { CSTOPB, 2 }, |
---|
[f55595e] | 133 | { INVALID_CONSTANT, -1 } |
---|
[4d5b156] | 134 | }; |
---|
| 135 | |
---|
| 136 | /* |
---|
| 137 | * Test converting baud rate into an index |
---|
| 138 | */ |
---|
[f55595e] | 139 | static void test_termios_baud2index(void) |
---|
[4d5b156] | 140 | { |
---|
| 141 | int i; |
---|
| 142 | int index; |
---|
| 143 | |
---|
[8cd0bb0f] | 144 | puts( "Test termios_baud2index..." ); |
---|
[e958d79b] | 145 | puts( "termios_baud_to_index(-2) - NOT OK" ); |
---|
[f55595e] | 146 | i = rtems_termios_baud_to_index( INVALID_CONSTANT ); |
---|
[500fcd5] | 147 | rtems_test_assert( i == -1 ); |
---|
[e958d79b] | 148 | |
---|
[f55595e] | 149 | for (i=0 ; baud_table[i].constant != INVALID_CONSTANT ; i++ ) { |
---|
[ab59de45] | 150 | printf( |
---|
| 151 | "termios_baud_to_index(B%" PRIdrtems_termios_baud_t ") - OK\n", |
---|
| 152 | baud_table[i].baud |
---|
| 153 | ); |
---|
| 154 | index = rtems_termios_baud_to_index( baud_table[i].constant ); |
---|
| 155 | if ( index != i ) { |
---|
| 156 | printf( "ERROR - returned %d should be %d\n", index, i ); |
---|
| 157 | rtems_test_exit(0); |
---|
[4d5b156] | 158 | } |
---|
[ab59de45] | 159 | } |
---|
[4d5b156] | 160 | } |
---|
| 161 | |
---|
| 162 | /* |
---|
| 163 | * Test converting termios baud constant to baud number |
---|
| 164 | */ |
---|
[f55595e] | 165 | static void test_termios_baud2number(void) |
---|
[4d5b156] | 166 | { |
---|
| 167 | int i; |
---|
[f55595e] | 168 | rtems_termios_baud_t number; |
---|
[4d5b156] | 169 | |
---|
| 170 | puts( |
---|
| 171 | "\n" |
---|
| 172 | "Test termios_baud2number..." |
---|
| 173 | ); |
---|
[e958d79b] | 174 | puts( "termios_baud_to_number(-2) - NOT OK" ); |
---|
[f55595e] | 175 | number = rtems_termios_baud_to_number( INVALID_CONSTANT ); |
---|
| 176 | rtems_test_assert( number == 0 ); |
---|
[e958d79b] | 177 | |
---|
[f55595e] | 178 | for (i=0 ; baud_table[i].constant != INVALID_CONSTANT ; i++ ) { |
---|
[8cd0bb0f] | 179 | printf( |
---|
| 180 | "termios_baud_to_number(B%" PRIdrtems_termios_baud_t ") - OK\n", |
---|
| 181 | baud_table[i].baud |
---|
| 182 | ); |
---|
[009dfd0] | 183 | number = rtems_termios_baud_to_number( baud_table[i].constant ); |
---|
[4d5b156] | 184 | if ( number != baud_table[i].baud ) { |
---|
| 185 | printf( |
---|
[f55595e] | 186 | "ERROR - returned %" PRIdrtems_termios_baud_t |
---|
| 187 | " should be %" PRIdrtems_termios_baud_t "\n", |
---|
[4d5b156] | 188 | number, |
---|
| 189 | baud_table[i].baud |
---|
| 190 | ); |
---|
| 191 | rtems_test_exit(0); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | /* |
---|
| 197 | * Test converting baud number to termios baud constant |
---|
| 198 | */ |
---|
[f55595e] | 199 | static void test_termios_number_to_baud(void) |
---|
[4d5b156] | 200 | { |
---|
| 201 | int i; |
---|
[f55595e] | 202 | tcflag_t termios_baud; |
---|
[4d5b156] | 203 | |
---|
| 204 | puts( |
---|
| 205 | "\n" |
---|
| 206 | "Test termios_number_to_baud..." |
---|
| 207 | ); |
---|
[e958d79b] | 208 | puts( "termios_number_to_baud(-2) - NOT OK" ); |
---|
[f55595e] | 209 | termios_baud = rtems_termios_number_to_baud( INVALID_BAUD ); |
---|
| 210 | rtems_test_assert( termios_baud == 0 ); |
---|
[e958d79b] | 211 | |
---|
[f55595e] | 212 | for (i=0 ; baud_table[i].constant != INVALID_CONSTANT ; i++ ) { |
---|
[8cd0bb0f] | 213 | printf( |
---|
| 214 | "termios_number_to_baud(B%" PRIdrtems_termios_baud_t ") - OK\n", |
---|
| 215 | baud_table[i].baud |
---|
| 216 | ); |
---|
[009dfd0] | 217 | termios_baud = rtems_termios_number_to_baud( baud_table[i].baud ); |
---|
[4d5b156] | 218 | if ( termios_baud != baud_table[i].constant ) { |
---|
| 219 | printf( |
---|
| 220 | "ERROR - returned %d should be %d\n", |
---|
| 221 | termios_baud, |
---|
| 222 | baud_table[i].constant |
---|
| 223 | ); |
---|
| 224 | rtems_test_exit(0); |
---|
| 225 | } |
---|
| 226 | } |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | /* |
---|
| 230 | * Test all the baud rate options |
---|
| 231 | */ |
---|
[f55595e] | 232 | static void test_termios_set_baud( |
---|
[4d5b156] | 233 | int test |
---|
| 234 | ) |
---|
| 235 | { |
---|
| 236 | int sc; |
---|
| 237 | int i; |
---|
| 238 | struct termios attr; |
---|
| 239 | |
---|
| 240 | puts( "Test termios setting device baud rate..." ); |
---|
[f55595e] | 241 | for (i=0 ; baud_table[i].constant != INVALID_CONSTANT ; i++ ) { |
---|
[4d5b156] | 242 | sc = tcgetattr( test, &attr ); |
---|
| 243 | if ( sc != 0 ) { |
---|
| 244 | printf( "ERROR - return %d\n", sc ); |
---|
| 245 | rtems_test_exit(0); |
---|
| 246 | } |
---|
| 247 | |
---|
[1c6926c1] | 248 | attr.c_ispeed = baud_table[i].constant; |
---|
| 249 | attr.c_ospeed = baud_table[i].constant; |
---|
[4d5b156] | 250 | |
---|
[8cd0bb0f] | 251 | printf( |
---|
| 252 | "tcsetattr(TCSANOW, B%" PRIdrtems_termios_baud_t ") - OK\n", |
---|
| 253 | baud_table[i].baud |
---|
| 254 | ); |
---|
[4d5b156] | 255 | sc = tcsetattr( test, TCSANOW, &attr ); |
---|
| 256 | if ( sc != 0 ) { |
---|
| 257 | printf( "ERROR - return %d\n", sc ); |
---|
| 258 | rtems_test_exit(0); |
---|
| 259 | } |
---|
| 260 | |
---|
[8cd0bb0f] | 261 | printf( |
---|
| 262 | "tcsetattr(TCSADRAIN, B%" PRIdrtems_termios_baud_t ") - OK\n", |
---|
| 263 | baud_table[i].baud |
---|
| 264 | ); |
---|
[1c6926c1] | 265 | sc = tcsetattr( test, TCSADRAIN, &attr ); |
---|
| 266 | if ( sc != 0 ) { |
---|
| 267 | printf( "ERROR - return %d\n", sc ); |
---|
| 268 | rtems_test_exit(0); |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | printf( |
---|
| 272 | "tcsetattr(TCSAFLUSH, B%" PRIdrtems_termios_baud_t ") - OK\n", |
---|
| 273 | baud_table[i].baud |
---|
| 274 | ); |
---|
| 275 | sc = tcsetattr( test, TCSAFLUSH, &attr ); |
---|
[4d5b156] | 276 | if ( sc != 0 ) { |
---|
| 277 | printf( "ERROR - return %d\n", sc ); |
---|
| 278 | rtems_test_exit(0); |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | /* |
---|
| 284 | * Test all the character size options |
---|
| 285 | */ |
---|
[f55595e] | 286 | static void test_termios_set_charsize( |
---|
[4d5b156] | 287 | int test |
---|
| 288 | ) |
---|
| 289 | { |
---|
| 290 | int sc; |
---|
| 291 | int i; |
---|
| 292 | struct termios attr; |
---|
| 293 | |
---|
| 294 | puts( |
---|
| 295 | "\n" |
---|
| 296 | "Test termios setting device character size ..." |
---|
| 297 | ); |
---|
[f55595e] | 298 | for (i=0 ; char_size_table[i].constant != INVALID_CONSTANT ; i++ ) { |
---|
| 299 | tcflag_t csize = CSIZE; |
---|
| 300 | |
---|
[4d5b156] | 301 | sc = tcgetattr( test, &attr ); |
---|
| 302 | if ( sc != 0 ) { |
---|
| 303 | printf( "ERROR - return %d\n", sc ); |
---|
| 304 | rtems_test_exit(0); |
---|
| 305 | } |
---|
| 306 | |
---|
[f55595e] | 307 | attr.c_cflag &= ~csize; |
---|
[4d5b156] | 308 | attr.c_cflag |= char_size_table[i].constant; |
---|
| 309 | |
---|
| 310 | printf( "tcsetattr(TCSANOW, CS%d) - OK\n", char_size_table[i].bits ); |
---|
| 311 | sc = tcsetattr( test, TCSANOW, &attr ); |
---|
| 312 | if ( sc != 0 ) { |
---|
| 313 | printf( "ERROR - return %d\n", sc ); |
---|
| 314 | rtems_test_exit(0); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | printf( "tcsetattr(TCSADRAIN, CS%d) - OK\n", char_size_table[i].bits ); |
---|
[1c6926c1] | 318 | sc = tcsetattr( test, TCSADRAIN, &attr ); |
---|
| 319 | if ( sc != 0 ) { |
---|
| 320 | printf( "ERROR - return %d\n", sc ); |
---|
| 321 | rtems_test_exit(0); |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | printf( "tcsetattr(TCSAFLUSH, CS%d) - OK\n", char_size_table[i].bits ); |
---|
| 325 | sc = tcsetattr( test, TCSAFLUSH, &attr ); |
---|
| 326 | if ( sc != 0 ) { |
---|
| 327 | printf( "ERROR - return %d\n", sc ); |
---|
| 328 | rtems_test_exit(0); |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | printf( "tcsetattr(TCSASOFT, CS%d) - OK\n", char_size_table[i].bits ); |
---|
| 332 | sc = tcsetattr( test, TCSASOFT, &attr ); |
---|
[4d5b156] | 333 | if ( sc != 0 ) { |
---|
| 334 | printf( "ERROR - return %d\n", sc ); |
---|
| 335 | rtems_test_exit(0); |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | /* |
---|
| 341 | * Test all the parity options |
---|
| 342 | */ |
---|
[f55595e] | 343 | static void test_termios_set_parity( |
---|
[4d5b156] | 344 | int test |
---|
| 345 | ) |
---|
| 346 | { |
---|
| 347 | int sc; |
---|
| 348 | int i; |
---|
| 349 | struct termios attr; |
---|
| 350 | |
---|
| 351 | puts( |
---|
| 352 | "\n" |
---|
| 353 | "Test termios setting device parity ..." |
---|
| 354 | ); |
---|
[f55595e] | 355 | for (i=0 ; parity_table[i].constant != INVALID_CONSTANT ; i++ ) { |
---|
| 356 | tcflag_t par = PARENB | PARODD; |
---|
| 357 | |
---|
[4d5b156] | 358 | sc = tcgetattr( test, &attr ); |
---|
| 359 | if ( sc != 0 ) { |
---|
| 360 | printf( "ERROR - return %d\n", sc ); |
---|
| 361 | rtems_test_exit(0); |
---|
| 362 | } |
---|
| 363 | |
---|
[f55595e] | 364 | attr.c_cflag &= ~par; |
---|
[4d5b156] | 365 | attr.c_cflag |= parity_table[i].constant; |
---|
| 366 | |
---|
| 367 | printf( "tcsetattr(TCSANOW, %s) - OK\n", parity_table[i].parity ); |
---|
| 368 | sc = tcsetattr( test, TCSANOW, &attr ); |
---|
| 369 | if ( sc != 0 ) { |
---|
| 370 | printf( "ERROR - return %d\n", sc ); |
---|
| 371 | rtems_test_exit(0); |
---|
| 372 | } |
---|
| 373 | |
---|
| 374 | printf( "tcsetattr(TCSADRAIN, %s) - OK\n", parity_table[i].parity ); |
---|
[1c6926c1] | 375 | sc = tcsetattr( test, TCSADRAIN, &attr ); |
---|
| 376 | if ( sc != 0 ) { |
---|
| 377 | printf( "ERROR - return %d\n", sc ); |
---|
| 378 | rtems_test_exit(0); |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | printf( "tcsetattr(TCSAFLUSH, %s) - OK\n", parity_table[i].parity ); |
---|
| 382 | sc = tcsetattr( test, TCSAFLUSH, &attr ); |
---|
| 383 | if ( sc != 0 ) { |
---|
| 384 | printf( "ERROR - return %d\n", sc ); |
---|
| 385 | rtems_test_exit(0); |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | printf( "tcsetattr(TCSASOFT, %s) - OK\n", parity_table[i].parity ); |
---|
| 389 | sc = tcsetattr( test, TCSASOFT, &attr ); |
---|
[4d5b156] | 390 | if ( sc != 0 ) { |
---|
| 391 | printf( "ERROR - return %d\n", sc ); |
---|
| 392 | rtems_test_exit(0); |
---|
| 393 | } |
---|
| 394 | } |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | /* |
---|
| 398 | * Test all the stop bit options |
---|
| 399 | */ |
---|
[f55595e] | 400 | static void test_termios_set_stop_bits( |
---|
[4d5b156] | 401 | int test |
---|
| 402 | ) |
---|
| 403 | { |
---|
| 404 | int sc; |
---|
| 405 | int i; |
---|
| 406 | struct termios attr; |
---|
| 407 | |
---|
| 408 | puts( |
---|
| 409 | "\n" |
---|
| 410 | "Test termios setting device character size ..." |
---|
| 411 | ); |
---|
[f55595e] | 412 | for (i=0 ; stop_bits_table[i].constant != INVALID_CONSTANT ; i++ ) { |
---|
| 413 | tcflag_t cstopb = CSTOPB; |
---|
| 414 | |
---|
[4d5b156] | 415 | sc = tcgetattr( test, &attr ); |
---|
| 416 | if ( sc != 0 ) { |
---|
| 417 | printf( "ERROR - return %d\n", sc ); |
---|
| 418 | rtems_test_exit(0); |
---|
| 419 | } |
---|
| 420 | |
---|
[f55595e] | 421 | attr.c_cflag &= ~cstopb; |
---|
[4d5b156] | 422 | attr.c_cflag |= stop_bits_table[i].constant; |
---|
| 423 | |
---|
| 424 | printf( "tcsetattr(TCSANOW, %d bit%s) - OK\n", |
---|
| 425 | stop_bits_table[i].stop, |
---|
| 426 | ((stop_bits_table[i].stop == 1) ? "" : "s") |
---|
| 427 | ); |
---|
| 428 | sc = tcsetattr( test, TCSANOW, &attr ); |
---|
| 429 | if ( sc != 0 ) { |
---|
| 430 | printf( "ERROR - return %d\n", sc ); |
---|
| 431 | rtems_test_exit(0); |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | printf( "tcsetattr(TCSADRAIN, %d bits) - OK\n", stop_bits_table[i].stop ); |
---|
[1c6926c1] | 435 | sc = tcsetattr( test, TCSADRAIN, &attr ); |
---|
| 436 | if ( sc != 0 ) { |
---|
| 437 | printf( "ERROR - return %d\n", sc ); |
---|
| 438 | rtems_test_exit(0); |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | printf( "tcsetattr(TCSAFLUSH, %d bits) - OK\n", stop_bits_table[i].stop ); |
---|
| 442 | sc = tcsetattr( test, TCSAFLUSH, &attr ); |
---|
| 443 | if ( sc != 0 ) { |
---|
| 444 | printf( "ERROR - return %d\n", sc ); |
---|
| 445 | rtems_test_exit(0); |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | printf( "tcsetattr(TCSASOFT, %d bits) - OK\n", stop_bits_table[i].stop ); |
---|
| 449 | sc = tcsetattr( test, TCSASOFT, &attr ); |
---|
[4d5b156] | 450 | if ( sc != 0 ) { |
---|
| 451 | printf( "ERROR - return %d\n", sc ); |
---|
| 452 | rtems_test_exit(0); |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | } |
---|
| 456 | |
---|
[f55595e] | 457 | static void test_termios_cfoutspeed(void) |
---|
[9f5f6f53] | 458 | { |
---|
| 459 | int i; |
---|
| 460 | int sc; |
---|
| 461 | speed_t speed; |
---|
| 462 | struct termios term; |
---|
[1c6926c1] | 463 | speed_t bad; |
---|
[9f5f6f53] | 464 | |
---|
[1c6926c1] | 465 | bad = B921600 << 1; |
---|
[9f5f6f53] | 466 | memset( &term, '\0', sizeof(term) ); |
---|
| 467 | puts( "cfsetospeed(BAD BAUD) - EINVAL" ); |
---|
| 468 | sc = cfsetospeed( &term, bad ); |
---|
| 469 | rtems_test_assert( sc == -1 ); |
---|
| 470 | rtems_test_assert( errno == EINVAL ); |
---|
| 471 | |
---|
[f55595e] | 472 | for (i=0 ; baud_table[i].constant != INVALID_CONSTANT ; i++ ) { |
---|
[9f5f6f53] | 473 | memset( &term, '\0', sizeof(term) ); |
---|
| 474 | printf( |
---|
| 475 | "cfsetospeed(B%" PRIdrtems_termios_baud_t ") - OK\n", |
---|
| 476 | baud_table[i].baud |
---|
| 477 | ); |
---|
| 478 | sc = cfsetospeed( &term, baud_table[i].constant ); |
---|
| 479 | rtems_test_assert( !sc ); |
---|
| 480 | printf( |
---|
| 481 | "cfgetospeed(B%" PRIdrtems_termios_baud_t ") - OK\n", |
---|
| 482 | baud_table[i].baud |
---|
| 483 | ); |
---|
| 484 | speed = cfgetospeed( &term ); |
---|
| 485 | rtems_test_assert( speed == baud_table[i].constant ); |
---|
| 486 | } |
---|
| 487 | } |
---|
| 488 | |
---|
[f55595e] | 489 | static void test_termios_cfinspeed(void) |
---|
[9f5f6f53] | 490 | { |
---|
| 491 | int i; |
---|
| 492 | int sc; |
---|
| 493 | speed_t speed; |
---|
| 494 | struct termios term; |
---|
[1c6926c1] | 495 | speed_t bad; |
---|
[9f5f6f53] | 496 | |
---|
[1c6926c1] | 497 | bad = B921600 << 1; |
---|
[9f5f6f53] | 498 | memset( &term, '\0', sizeof(term) ); |
---|
| 499 | puts( "cfsetispeed(BAD BAUD) - EINVAL" ); |
---|
| 500 | sc = cfsetispeed( &term, bad ); |
---|
| 501 | rtems_test_assert( sc == -1 ); |
---|
| 502 | rtems_test_assert( errno == EINVAL ); |
---|
| 503 | |
---|
[f55595e] | 504 | for (i=0 ; baud_table[i].constant != INVALID_CONSTANT ; i++ ) { |
---|
[9f5f6f53] | 505 | memset( &term, '\0', sizeof(term) ); |
---|
| 506 | printf( |
---|
| 507 | "cfsetispeed(B%" PRIdrtems_termios_baud_t ") - OK\n", |
---|
| 508 | baud_table[i].baud |
---|
| 509 | ); |
---|
| 510 | sc = cfsetispeed( &term, baud_table[i].constant ); |
---|
| 511 | rtems_test_assert( !sc ); |
---|
| 512 | |
---|
| 513 | printf( |
---|
| 514 | "cfgetispeed(B%" PRIdrtems_termios_baud_t ") - OK\n", |
---|
| 515 | baud_table[i].baud |
---|
| 516 | ); |
---|
| 517 | speed = cfgetispeed( &term ); |
---|
| 518 | rtems_test_assert( speed == baud_table[i].constant ); |
---|
| 519 | } |
---|
| 520 | } |
---|
| 521 | |
---|
[3096f5c9] | 522 | static void test_termios_cfsetspeed(void) |
---|
| 523 | { |
---|
| 524 | int i; |
---|
| 525 | int status; |
---|
| 526 | speed_t speed; |
---|
| 527 | struct termios term; |
---|
[1c6926c1] | 528 | speed_t bad; |
---|
[3096f5c9] | 529 | |
---|
[1c6926c1] | 530 | bad = B921600 << 1; |
---|
[3096f5c9] | 531 | memset( &term, '\0', sizeof(term) ); |
---|
| 532 | puts( "cfsetspeed(BAD BAUD) - EINVAL" ); |
---|
| 533 | status = cfsetspeed( &term, bad ); |
---|
| 534 | rtems_test_assert( status == -1 ); |
---|
| 535 | rtems_test_assert( errno == EINVAL ); |
---|
| 536 | |
---|
| 537 | for (i=0 ; baud_table[i].constant != INVALID_CONSTANT ; i++ ) { |
---|
| 538 | memset( &term, '\0', sizeof(term) ); |
---|
| 539 | printf( |
---|
| 540 | "cfsetspeed(B%" PRIdrtems_termios_baud_t ") - OK\n", |
---|
| 541 | baud_table[i].baud |
---|
| 542 | ); |
---|
| 543 | status = cfsetspeed( &term, baud_table[i].constant ); |
---|
| 544 | rtems_test_assert( !status ); |
---|
| 545 | |
---|
| 546 | printf( |
---|
| 547 | "cfgetspeed(B%" PRIdrtems_termios_baud_t ") - checking both inspeed and outspeed - OK\n", |
---|
| 548 | baud_table[i].baud |
---|
| 549 | ); |
---|
| 550 | speed = cfgetispeed( &term ); |
---|
| 551 | rtems_test_assert( speed == baud_table[i].constant ); |
---|
| 552 | |
---|
| 553 | speed = cfgetospeed( &term ); |
---|
| 554 | rtems_test_assert( speed == baud_table[i].constant ); |
---|
| 555 | } |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | static void test_termios_cfmakeraw(void) |
---|
| 559 | { |
---|
| 560 | struct termios term; |
---|
| 561 | |
---|
| 562 | memset( &term, '\0', sizeof(term) ); |
---|
| 563 | cfmakeraw( &term ); |
---|
| 564 | puts( "cfmakeraw - OK" ); |
---|
| 565 | |
---|
| 566 | /* Check that all of the flags were set correctly */ |
---|
[1c6926c1] | 567 | rtems_test_assert( ~(term.c_iflag & (IMAXBEL|IXOFF|INPCK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IGNPAR)) ); |
---|
| 568 | |
---|
| 569 | rtems_test_assert( term.c_iflag & (IGNBRK) ); |
---|
[3096f5c9] | 570 | |
---|
| 571 | rtems_test_assert( ~(term.c_oflag & OPOST) ); |
---|
| 572 | |
---|
[1c6926c1] | 573 | rtems_test_assert( ~(term.c_lflag & (ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|IEXTEN|NOFLSH|TOSTOP|PENDIN)) ); |
---|
[3096f5c9] | 574 | |
---|
| 575 | rtems_test_assert( ~(term.c_cflag & (CSIZE|PARENB)) ); |
---|
| 576 | |
---|
[1c6926c1] | 577 | rtems_test_assert( term.c_cflag & (CS8|CREAD) ); |
---|
| 578 | |
---|
| 579 | rtems_test_assert( term.c_cc[VMIN] == 1 ); |
---|
| 580 | |
---|
| 581 | rtems_test_assert( term.c_cc[VTIME] == 0 ); |
---|
| 582 | } |
---|
| 583 | |
---|
| 584 | static void test_termios_cfmakesane(void) |
---|
| 585 | { |
---|
| 586 | struct termios term; |
---|
| 587 | |
---|
| 588 | memset( &term, '\0', sizeof(term) ); |
---|
| 589 | cfmakesane( &term ); |
---|
| 590 | puts( "cfmakesane - OK" ); |
---|
| 591 | |
---|
| 592 | /* Check that all of the flags were set correctly */ |
---|
| 593 | rtems_test_assert( term.c_iflag == TTYDEF_IFLAG ); |
---|
| 594 | |
---|
| 595 | rtems_test_assert( term.c_oflag == TTYDEF_OFLAG ); |
---|
| 596 | |
---|
| 597 | rtems_test_assert( term.c_lflag == TTYDEF_LFLAG ); |
---|
| 598 | |
---|
| 599 | rtems_test_assert( term.c_cflag == TTYDEF_CFLAG ); |
---|
| 600 | |
---|
| 601 | rtems_test_assert( term.c_ispeed == TTYDEF_SPEED ); |
---|
| 602 | |
---|
| 603 | rtems_test_assert( term.c_ospeed == TTYDEF_SPEED ); |
---|
| 604 | |
---|
| 605 | rtems_test_assert( memcmp(&term.c_cc, ttydefchars, sizeof(term.c_cc)) == 0 ); |
---|
[3096f5c9] | 606 | } |
---|
| 607 | |
---|
[7fd5e89] | 608 | typedef struct { |
---|
| 609 | rtems_termios_device_context base; |
---|
| 610 | bool done; |
---|
| 611 | } device_context; |
---|
| 612 | |
---|
[55e0be36] | 613 | static rtems_status_code test_early_device_install( |
---|
[ef8c00bc] | 614 | rtems_device_major_number major, |
---|
| 615 | rtems_device_minor_number minor, |
---|
| 616 | void *arg |
---|
| 617 | ) |
---|
| 618 | { |
---|
[55e0be36] | 619 | static const rtems_termios_device_handler handler; |
---|
| 620 | static const char dev[] = "/foobar"; |
---|
| 621 | |
---|
[ef8c00bc] | 622 | rtems_resource_snapshot snapshot; |
---|
| 623 | rtems_status_code sc; |
---|
[55e0be36] | 624 | int fd; |
---|
| 625 | int rv; |
---|
[ef8c00bc] | 626 | |
---|
| 627 | rtems_resource_snapshot_take( &snapshot ); |
---|
| 628 | |
---|
[55e0be36] | 629 | sc = rtems_termios_device_install( &dev[0], &handler, NULL, NULL ); |
---|
| 630 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
| 631 | |
---|
| 632 | errno = 0; |
---|
| 633 | fd = open( &dev[0], O_RDWR ); |
---|
| 634 | rtems_test_assert( fd == -1 ); |
---|
| 635 | rtems_test_assert( errno == ENXIO ); |
---|
[ef8c00bc] | 636 | |
---|
[55e0be36] | 637 | rv = unlink( &dev[0] ); |
---|
| 638 | rtems_test_assert( rv == 0 ); |
---|
[ef8c00bc] | 639 | |
---|
| 640 | rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); |
---|
[93726e5] | 641 | |
---|
| 642 | return RTEMS_SUCCESSFUL; |
---|
[ef8c00bc] | 643 | } |
---|
| 644 | |
---|
| 645 | static void test_device_install_remove(void) |
---|
| 646 | { |
---|
| 647 | static const rtems_termios_device_handler handler; |
---|
| 648 | static const char dev[] = "/foobar"; |
---|
| 649 | |
---|
| 650 | rtems_resource_snapshot snapshot; |
---|
| 651 | rtems_status_code sc; |
---|
| 652 | void *greedy; |
---|
[55e0be36] | 653 | int rv; |
---|
[ef8c00bc] | 654 | |
---|
| 655 | rtems_resource_snapshot_take( &snapshot ); |
---|
| 656 | |
---|
| 657 | greedy = rtems_heap_greedy_allocate( NULL, 0 ); |
---|
| 658 | |
---|
[55e0be36] | 659 | sc = rtems_termios_device_install( "/", &handler, NULL, NULL ); |
---|
[ef8c00bc] | 660 | rtems_test_assert( sc == RTEMS_NO_MEMORY ); |
---|
| 661 | |
---|
| 662 | rtems_heap_greedy_free( greedy ); |
---|
| 663 | |
---|
| 664 | rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); |
---|
| 665 | |
---|
[55e0be36] | 666 | sc = rtems_termios_device_install( "/", &handler, NULL, NULL ); |
---|
[ef8c00bc] | 667 | rtems_test_assert( sc == RTEMS_UNSATISFIED ); |
---|
| 668 | |
---|
| 669 | rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); |
---|
| 670 | |
---|
[55e0be36] | 671 | sc = rtems_termios_device_install( &dev[0], &handler, NULL, NULL ); |
---|
[ef8c00bc] | 672 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
| 673 | |
---|
[55e0be36] | 674 | rv = unlink( &dev[0] ); |
---|
| 675 | rtems_test_assert( rv == 0 ); |
---|
[ef8c00bc] | 676 | |
---|
| 677 | rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); |
---|
| 678 | } |
---|
| 679 | |
---|
[a0fb29f] | 680 | static bool first_open_error( |
---|
| 681 | rtems_termios_tty *tty, |
---|
[7fd5e89] | 682 | rtems_termios_device_context *base, |
---|
| 683 | struct termios *term, |
---|
[a0fb29f] | 684 | rtems_libio_open_close_args_t *args |
---|
| 685 | ) |
---|
| 686 | { |
---|
[7fd5e89] | 687 | device_context *ctx = (device_context *) base; |
---|
[a0fb29f] | 688 | |
---|
[7fd5e89] | 689 | (void) tty; |
---|
| 690 | (void) term; |
---|
[a0fb29f] | 691 | (void) args; |
---|
| 692 | |
---|
[7fd5e89] | 693 | ctx->done = true; |
---|
[a0fb29f] | 694 | |
---|
| 695 | return false; |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | static void test_first_open_error(void) |
---|
| 699 | { |
---|
| 700 | static const rtems_termios_device_handler handler = { |
---|
| 701 | .first_open = first_open_error |
---|
| 702 | }; |
---|
| 703 | static const char dev[] = "/foobar"; |
---|
| 704 | |
---|
| 705 | rtems_resource_snapshot snapshot; |
---|
| 706 | rtems_status_code sc; |
---|
[55e0be36] | 707 | int fd; |
---|
| 708 | int rv; |
---|
[7fd5e89] | 709 | device_context ctx = { |
---|
| 710 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "abc" ), |
---|
| 711 | .done = false |
---|
| 712 | }; |
---|
[a0fb29f] | 713 | |
---|
| 714 | rtems_resource_snapshot_take( &snapshot ); |
---|
| 715 | |
---|
[55e0be36] | 716 | sc = rtems_termios_device_install( &dev[0], &handler, NULL, &ctx.base ); |
---|
[a0fb29f] | 717 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
| 718 | |
---|
[7fd5e89] | 719 | rtems_test_assert( !ctx.done ); |
---|
[55e0be36] | 720 | errno = 0; |
---|
| 721 | fd = open( &dev[0], O_RDWR ); |
---|
| 722 | rtems_test_assert( fd == -1 ); |
---|
| 723 | rtems_test_assert( errno == ENOMEM ); |
---|
[7fd5e89] | 724 | rtems_test_assert( ctx.done ); |
---|
[a0fb29f] | 725 | |
---|
[55e0be36] | 726 | rv = unlink( &dev[0] ); |
---|
| 727 | rtems_test_assert( rv == 0 ); |
---|
[a0fb29f] | 728 | |
---|
| 729 | rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); |
---|
| 730 | } |
---|
| 731 | |
---|
[32fc6a3] | 732 | static bool set_attributes_error( |
---|
[7fd5e89] | 733 | rtems_termios_device_context *base, |
---|
[32fc6a3] | 734 | const struct termios *term |
---|
| 735 | ) |
---|
| 736 | { |
---|
[7fd5e89] | 737 | device_context *ctx = (device_context *) base; |
---|
[32fc6a3] | 738 | |
---|
| 739 | (void) term; |
---|
| 740 | |
---|
[7fd5e89] | 741 | ctx->done = true; |
---|
[32fc6a3] | 742 | |
---|
| 743 | return false; |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | static void test_set_attributes_error(void) |
---|
| 747 | { |
---|
| 748 | static const rtems_termios_device_handler handler = { |
---|
| 749 | .set_attributes = set_attributes_error |
---|
| 750 | }; |
---|
| 751 | static const char dev[] = "/foobar"; |
---|
| 752 | |
---|
| 753 | rtems_resource_snapshot snapshot; |
---|
| 754 | rtems_status_code sc; |
---|
| 755 | struct termios term; |
---|
[7fd5e89] | 756 | device_context ctx = { |
---|
| 757 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "abc" ), |
---|
| 758 | .done = false |
---|
| 759 | }; |
---|
[55e0be36] | 760 | int fd; |
---|
| 761 | int rv; |
---|
[32fc6a3] | 762 | |
---|
| 763 | rtems_resource_snapshot_take( &snapshot ); |
---|
| 764 | |
---|
[55e0be36] | 765 | sc = rtems_termios_device_install( &dev[0], &handler, NULL, &ctx.base ); |
---|
[32fc6a3] | 766 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
| 767 | |
---|
[55e0be36] | 768 | fd = open( &dev[0], O_RDWR ); |
---|
| 769 | rtems_test_assert( fd >= 0 ); |
---|
[32fc6a3] | 770 | |
---|
[7fd5e89] | 771 | rtems_test_assert( !ctx.done ); |
---|
[55e0be36] | 772 | errno = 0; |
---|
[1c6926c1] | 773 | rv = ioctl( fd, TIOCSETA, &term ); |
---|
[55e0be36] | 774 | rtems_test_assert( rv == -1 ); |
---|
| 775 | rtems_test_assert( errno == EIO ); |
---|
[7fd5e89] | 776 | rtems_test_assert( ctx.done ); |
---|
[32fc6a3] | 777 | |
---|
[55e0be36] | 778 | rv = close( fd ); |
---|
| 779 | rtems_test_assert( rv == 0 ); |
---|
[32fc6a3] | 780 | |
---|
[55e0be36] | 781 | rv = unlink( &dev[0] ); |
---|
| 782 | rtems_test_assert( rv == 0 ); |
---|
[32fc6a3] | 783 | |
---|
| 784 | rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) ); |
---|
| 785 | } |
---|
| 786 | |
---|
[93726e5] | 787 | static void test_set_best_baud(void) |
---|
| 788 | { |
---|
| 789 | static const struct { |
---|
| 790 | uint32_t baud; |
---|
[1c6926c1] | 791 | speed_t speed; |
---|
| 792 | } baud_to_speed_table[] = { |
---|
[93726e5] | 793 | { 0, B0 }, |
---|
| 794 | { 25, B0 }, |
---|
| 795 | { 26, B50 }, |
---|
| 796 | { 50, B50 }, |
---|
| 797 | { 62, B50 }, |
---|
| 798 | { 63, B75 }, |
---|
| 799 | { 75, B75 }, |
---|
| 800 | { 110, B110 }, |
---|
| 801 | { 134, B134 }, |
---|
| 802 | { 150, B150 }, |
---|
| 803 | { 200, B200 }, |
---|
| 804 | { 300, B300 }, |
---|
| 805 | { 600, B600 }, |
---|
| 806 | { 1200, B1200 }, |
---|
| 807 | { 1800, B1800 }, |
---|
| 808 | { 2400, B2400 }, |
---|
| 809 | { 4800, B4800 }, |
---|
| 810 | { 9600, B9600 }, |
---|
| 811 | { 19200, B19200 }, |
---|
| 812 | { 38400, B38400 }, |
---|
| 813 | { 57600, B57600 }, |
---|
| 814 | { 115200, B115200 }, |
---|
| 815 | { 230400, B230400 }, |
---|
| 816 | { 460800, B460800 }, |
---|
| 817 | { 0xffffffff, B460800 } |
---|
| 818 | }; |
---|
| 819 | |
---|
[1c6926c1] | 820 | size_t n = RTEMS_ARRAY_SIZE(baud_to_speed_table); |
---|
[93726e5] | 821 | size_t i; |
---|
| 822 | |
---|
| 823 | for ( i = 0; i < n; ++i ) { |
---|
[7fd5e89] | 824 | struct termios term; |
---|
[93726e5] | 825 | |
---|
[7fd5e89] | 826 | memset( &term, 0xff, sizeof( term ) ); |
---|
[1c6926c1] | 827 | rtems_termios_set_best_baud( &term, baud_to_speed_table[ i ].baud ); |
---|
[93726e5] | 828 | |
---|
[1c6926c1] | 829 | rtems_test_assert( term.c_ispeed == baud_to_speed_table[ i ].speed ); |
---|
| 830 | rtems_test_assert( term.c_ospeed == baud_to_speed_table[ i ].speed ); |
---|
[93726e5] | 831 | } |
---|
| 832 | } |
---|
| 833 | |
---|
[f55595e] | 834 | static rtems_task Init( |
---|
[4d5b156] | 835 | rtems_task_argument ignored |
---|
| 836 | ) |
---|
| 837 | { |
---|
| 838 | int rc; |
---|
| 839 | rtems_status_code sc; |
---|
| 840 | rtems_device_major_number registered; |
---|
| 841 | int test; |
---|
[8cd0bb0f] | 842 | struct termios t; |
---|
[d539f2b] | 843 | int index = 0; |
---|
[4d5b156] | 844 | |
---|
[f8b2eb03] | 845 | TEST_BEGIN(); |
---|
[4d5b156] | 846 | |
---|
| 847 | test_termios_baud2index(); |
---|
| 848 | test_termios_baud2number(); |
---|
| 849 | test_termios_number_to_baud(); |
---|
| 850 | |
---|
[c8615dcf] | 851 | sc = rtems_termios_bufsize( 256, 128, 64 ); |
---|
[2e54cdc4] | 852 | directive_failed( sc, "rtems_termios_bufsize" ); |
---|
| 853 | |
---|
[8cd0bb0f] | 854 | /* |
---|
| 855 | * Register a driver |
---|
| 856 | */ |
---|
[4d5b156] | 857 | puts( |
---|
| 858 | "\n" |
---|
| 859 | "Init - rtems_io_register_driver - Termios Test Driver - OK" |
---|
| 860 | ); |
---|
| 861 | sc = rtems_io_register_driver( 0, &test_driver, ®istered ); |
---|
| 862 | printf( "Init - Major slot returned = %d\n", (int) registered ); |
---|
| 863 | directive_failed( sc, "rtems_io_register_driver" ); |
---|
| 864 | |
---|
| 865 | /* |
---|
| 866 | * Test baud rate |
---|
| 867 | */ |
---|
| 868 | puts( "Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); |
---|
| 869 | test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); |
---|
| 870 | if ( test == -1 ) { |
---|
| 871 | printf( "ERROR - baud opening test device (%d)\n", test ); |
---|
| 872 | rtems_test_exit(0); |
---|
| 873 | } |
---|
| 874 | |
---|
[2e54cdc4] | 875 | /* |
---|
| 876 | * tcsetattr - ERROR invalid operation |
---|
| 877 | */ |
---|
[1c6926c1] | 878 | puts( "tcsetattr - invalid operation - EINVAL" ); |
---|
[a263ce5c] | 879 | rc = tcsetattr( test, INT_MAX, &t ); |
---|
[2e54cdc4] | 880 | rtems_test_assert( rc == -1 ); |
---|
[1c6926c1] | 881 | rtems_test_assert( errno == EINVAL ); |
---|
[3096f5c9] | 882 | |
---|
| 883 | test_termios_cfmakeraw(); |
---|
[1c6926c1] | 884 | test_termios_cfmakesane(); |
---|
| 885 | |
---|
[2e54cdc4] | 886 | /* |
---|
| 887 | * tcsetattr - TCSADRAIN |
---|
| 888 | */ |
---|
| 889 | puts( "\ntcsetattr - drain - OK" ); |
---|
| 890 | rc = tcsetattr( test, TCSADRAIN, &t ); |
---|
| 891 | rtems_test_assert( rc == 0 ); |
---|
| 892 | |
---|
[4d5b156] | 893 | test_termios_set_baud(test); |
---|
| 894 | |
---|
| 895 | puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); |
---|
| 896 | rc = close( test ); |
---|
| 897 | if ( rc != 0 ) { |
---|
| 898 | printf( "ERROR - baud close test device (%d) %s\n", test, strerror(errno) ); |
---|
| 899 | rtems_test_exit(0); |
---|
| 900 | } |
---|
| 901 | |
---|
| 902 | /* |
---|
| 903 | * Test character size |
---|
[b1274bd9] | 904 | */ |
---|
[4d5b156] | 905 | puts( |
---|
| 906 | "\n" |
---|
| 907 | "Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" |
---|
| 908 | ); |
---|
| 909 | test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); |
---|
| 910 | if ( test == -1 ) { |
---|
| 911 | printf( "ERROR - size open test device (%d) %s\n", test, strerror(errno) ); |
---|
| 912 | rtems_test_exit(0); |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | test_termios_set_charsize(test); |
---|
| 916 | |
---|
| 917 | puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); |
---|
| 918 | rc = close( test ); |
---|
| 919 | if ( rc != 0 ) { |
---|
| 920 | printf( "ERROR - size close test device (%d) %s\n", test, strerror(errno) ); |
---|
| 921 | rtems_test_exit(0); |
---|
| 922 | } |
---|
| 923 | |
---|
| 924 | /* |
---|
| 925 | * Test parity |
---|
[b1274bd9] | 926 | */ |
---|
[4d5b156] | 927 | puts( |
---|
| 928 | "\n" |
---|
| 929 | "Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" |
---|
| 930 | ); |
---|
| 931 | test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); |
---|
| 932 | if ( test == -1 ) { |
---|
| 933 | printf( "ERROR - parity open test device (%d) %s\n", |
---|
| 934 | test, strerror(errno) ); |
---|
| 935 | rtems_test_exit(0); |
---|
| 936 | } |
---|
| 937 | |
---|
| 938 | test_termios_set_parity(test); |
---|
| 939 | |
---|
| 940 | puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); |
---|
| 941 | rc = close( test ); |
---|
| 942 | if ( rc != 0 ) { |
---|
| 943 | printf( "ERROR - parity close test device (%d) %s\n", |
---|
| 944 | test, strerror(errno) ); |
---|
| 945 | rtems_test_exit(0); |
---|
| 946 | } |
---|
| 947 | |
---|
| 948 | /* |
---|
| 949 | * Test stop bits |
---|
[b1274bd9] | 950 | */ |
---|
[4d5b156] | 951 | puts( |
---|
| 952 | "\n" |
---|
| 953 | "Init - open - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" |
---|
| 954 | ); |
---|
| 955 | test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); |
---|
| 956 | if ( test == -1 ) { |
---|
| 957 | printf( "ERROR - stop bits open test device (%d) %s\n", |
---|
| 958 | test, strerror(errno) ); |
---|
| 959 | rtems_test_exit(0); |
---|
| 960 | } |
---|
| 961 | |
---|
| 962 | test_termios_set_stop_bits(test); |
---|
| 963 | |
---|
[9f5f6f53] | 964 | test_termios_cfoutspeed(); |
---|
| 965 | |
---|
| 966 | test_termios_cfinspeed(); |
---|
| 967 | |
---|
[3096f5c9] | 968 | test_termios_cfsetspeed(); |
---|
| 969 | |
---|
[4d5b156] | 970 | puts( "Init - close - " TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK" ); |
---|
| 971 | rc = close( test ); |
---|
| 972 | if ( rc != 0 ) { |
---|
| 973 | printf( "ERROR - stop bits close test device (%d) %s\n", |
---|
| 974 | test, strerror(errno) ); |
---|
| 975 | rtems_test_exit(0); |
---|
| 976 | } |
---|
| 977 | |
---|
[2e54cdc4] | 978 | |
---|
| 979 | puts( "Multiple open of the device" ); |
---|
| 980 | for( ; index < 26; ++index ) { |
---|
| 981 | test = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); |
---|
| 982 | rtems_test_assert( test != -1 ); |
---|
| 983 | rc = close( test ); |
---|
| 984 | rtems_test_assert( rc == 0 ); |
---|
| 985 | } |
---|
| 986 | puts( "" ); |
---|
[d539f2b] | 987 | |
---|
[ef8c00bc] | 988 | test_device_install_remove(); |
---|
[a0fb29f] | 989 | test_first_open_error(); |
---|
[32fc6a3] | 990 | test_set_attributes_error(); |
---|
[93726e5] | 991 | test_set_best_baud(); |
---|
[ef8c00bc] | 992 | |
---|
[f8b2eb03] | 993 | TEST_END(); |
---|
[4d5b156] | 994 | rtems_test_exit(0); |
---|
| 995 | } |
---|
| 996 | |
---|
| 997 | /* configuration information */ |
---|
| 998 | |
---|
[ef8c00bc] | 999 | #define CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \ |
---|
[55e0be36] | 1000 | { .initialization_entry = test_early_device_install } |
---|
[ef8c00bc] | 1001 | |
---|
[4d5b156] | 1002 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 1003 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 1004 | |
---|
| 1005 | /* include an extra slot for registering the termios one dynamically */ |
---|
[ef8c00bc] | 1006 | #define CONFIGURE_MAXIMUM_DRIVERS 4 |
---|
[4d5b156] | 1007 | |
---|
| 1008 | /* one for the console and one for the test port */ |
---|
[e8e38481] | 1009 | #define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 3 |
---|
[4d5b156] | 1010 | |
---|
| 1011 | /* we need to be able to open the test device */ |
---|
| 1012 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 |
---|
| 1013 | |
---|
| 1014 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
[f8b2eb03] | 1015 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
| 1016 | |
---|
[4d5b156] | 1017 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 1018 | |
---|
| 1019 | #define CONFIGURE_INIT |
---|
| 1020 | #include <rtems/confdefs.h> |
---|
| 1021 | |
---|
| 1022 | /* global variables */ |
---|