source: rtems/testsuites/libtests/termios03/init.c @ 4c86e3d

4.115
Last change on this file since 4c86e3d was 4c86e3d, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/12 at 17:20:47

libtmtests - Eliminate missing prototype warnings

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