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_intr.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 | |
---|
25 | const char rtems_test_name[] = "TERMIOS 4"; |
---|
26 | |
---|
27 | /* forward declarations to avoid warnings */ |
---|
28 | void write_helper(int fd, const char *c); |
---|
29 | void read_helper(int fd, const char *expected); |
---|
30 | void open_it(void); |
---|
31 | void close_it(void); |
---|
32 | void change_iflag(const char *desc, int mask, int new); |
---|
33 | rtems_task Init(rtems_task_argument argument); |
---|
34 | |
---|
35 | void write_helper( |
---|
36 | int fd, |
---|
37 | const char *c |
---|
38 | ) |
---|
39 | { |
---|
40 | size_t len; |
---|
41 | int rc; |
---|
42 | |
---|
43 | len = strlen( c ); |
---|
44 | printf( "Writing: %s", c ); |
---|
45 | |
---|
46 | rc = write( fd, c, len ); |
---|
47 | rtems_test_assert( rc == len ); |
---|
48 | |
---|
49 | termios_test_driver_dump_tx("Transmitted"); |
---|
50 | } |
---|
51 | |
---|
52 | uint8_t read_helper_buffer[256]; |
---|
53 | |
---|
54 | void read_helper( |
---|
55 | int fd, |
---|
56 | const char *expected |
---|
57 | ) |
---|
58 | { |
---|
59 | int rc; |
---|
60 | size_t len; |
---|
61 | |
---|
62 | len = strlen( expected ); |
---|
63 | |
---|
64 | termios_test_driver_set_rx( expected, len ); |
---|
65 | printf( "\nReading (expected):\n" ); |
---|
66 | rtems_print_buffer( (unsigned char *)expected, len-1 ); |
---|
67 | |
---|
68 | rc = read( fd, read_helper_buffer, sizeof(read_helper_buffer) ); |
---|
69 | rtems_test_assert( rc != -1 ); |
---|
70 | |
---|
71 | printf( "Read %d bytes from read(2)\n", rc ); |
---|
72 | rtems_print_buffer( read_helper_buffer, rc ); |
---|
73 | |
---|
74 | termios_test_driver_dump_tx("As Read"); |
---|
75 | } |
---|
76 | |
---|
77 | int Test_fd; |
---|
78 | |
---|
79 | void open_it(void) |
---|
80 | { |
---|
81 | /* open the file */ |
---|
82 | puts( "open(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " ); |
---|
83 | Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR ); |
---|
84 | rtems_test_assert( Test_fd != -1 ); |
---|
85 | } |
---|
86 | |
---|
87 | void close_it(void) |
---|
88 | { |
---|
89 | int rc; |
---|
90 | |
---|
91 | puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " ); |
---|
92 | rc = close( Test_fd ); |
---|
93 | rtems_test_assert( rc == 0 ); |
---|
94 | } |
---|
95 | |
---|
96 | void change_iflag( const char *desc, int mask, int new ) |
---|
97 | { |
---|
98 | int rc; |
---|
99 | struct termios attr; |
---|
100 | |
---|
101 | printf( "Changing c_iflag to: %s\n", desc ); |
---|
102 | rc = tcgetattr( Test_fd, &attr ); |
---|
103 | rtems_test_assert( rc == 0 ); |
---|
104 | |
---|
105 | attr.c_iflag &= ~mask; |
---|
106 | attr.c_iflag |= new; |
---|
107 | |
---|
108 | rc = tcsetattr( Test_fd, TCSANOW, &attr ); |
---|
109 | rtems_test_assert( rc == 0 ); |
---|
110 | } |
---|
111 | |
---|
112 | const char ExpectedOutput_1[] = "This is interrupt driven test output.\n"; |
---|
113 | const char ExpectedInput_1[] = "Blocking interrupt driven read.\n"; |
---|
114 | const char ExpectedInput_2[] = "Non-Blocking interrupt driven read.\n"; |
---|
115 | |
---|
116 | rtems_task Init( |
---|
117 | rtems_task_argument argument |
---|
118 | ) |
---|
119 | { |
---|
120 | TEST_BEGIN(); |
---|
121 | |
---|
122 | open_it(); |
---|
123 | |
---|
124 | /* some basic cases */ |
---|
125 | write_helper( Test_fd, ExpectedOutput_1 ); |
---|
126 | read_helper( Test_fd, ExpectedInput_1 ); |
---|
127 | termios_test_driver_set_rx_enqueue_now( true ); |
---|
128 | read_helper( Test_fd, ExpectedInput_2 ); |
---|
129 | |
---|
130 | close_it(); |
---|
131 | |
---|
132 | TEST_END(); |
---|
133 | |
---|
134 | rtems_test_exit(0); |
---|
135 | } |
---|
136 | |
---|
137 | /* configuration information */ |
---|
138 | |
---|
139 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
140 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
141 | #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \ |
---|
142 | TERMIOS_TEST_DRIVER_TABLE_ENTRY |
---|
143 | |
---|
144 | /* we need to be able to open the test device */ |
---|
145 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 |
---|
146 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
147 | #define CONFIGURE_MAXIMUM_TIMERS 2 |
---|
148 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
149 | |
---|
150 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
151 | |
---|
152 | #define CONFIGURE_INIT |
---|
153 | |
---|
154 | #include <rtems/confdefs.h> |
---|
155 | /* end of file */ |
---|