source: rtems/testsuites/libtests/termios03/init.c @ 33ece501

4.115
Last change on this file since 33ece501 was 33ece501, checked in by Joel Sherrill <joel.sherrill@…>, on 06/28/10 at 17:05:25

2010-06-28 Joel Sherrill <joel.sherrill@…>

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