source: rtems/testsuites/libtests/termios07/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_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#include <rtems/libio.h>
25
26/* forward declarations to avoid warnings */
27rtems_task Init(rtems_task_argument argument);
28void write_helper(int fd, const char *c);
29void read_helper(int fd, const char *expected);
30void open_it(void);
31void close_it(void);
32void change_iflag(const char *desc, int mask, int new);
33
34void write_helper(
35  int        fd,
36  const char *c
37)
38{
39  size_t   len;
40  int      rc;
41 
42  len = strlen( c );
43  printf( "Writing: %s", c );
44
45  rc = write( fd, c, len );
46  rtems_test_assert( rc == len );
47
48  termios_test_driver_dump_tx("Transmitted");
49}
50
51uint8_t read_helper_buffer[256];
52
53void read_helper(
54  int         fd,
55  const char *expected
56)
57{
58  int    rc;
59  size_t len;
60
61  len = strlen( expected );
62
63  termios_test_driver_set_rx( expected, len );
64  printf( "\nReading (expected):\n" );
65  rtems_print_buffer( (unsigned char *)expected, len-1 );
66
67  rc = read( fd, read_helper_buffer, sizeof(read_helper_buffer) );
68  rtems_test_assert( rc != -1 );
69
70  printf( "Read %d bytes from read(2)\n", rc );
71  rtems_print_buffer( read_helper_buffer, rc );
72
73  termios_test_driver_dump_tx("As Read");
74}
75
76int Test_fd;
77
78void open_it(void)
79{
80  /* open the file */
81  puts( "open(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
82  Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
83  rtems_test_assert( Test_fd != -1 );
84}
85
86void close_it(void)
87{
88  int rc;
89
90  puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
91  rc = close( Test_fd );
92  rtems_test_assert( rc == 0 );
93}
94
95void change_iflag( const char *desc, int mask, int new )
96{
97  int            rc;
98  struct termios attr;
99
100  printf( "Changing c_iflag to: %s\n", desc );
101  rc = tcgetattr( Test_fd, &attr );
102  rtems_test_assert( rc == 0 );
103
104  attr.c_iflag &= ~mask;
105  attr.c_iflag |= new;
106
107  rc = tcsetattr( Test_fd, TCSANOW, &attr );
108  rtems_test_assert( rc == 0 );
109}
110
111const char XON_String[] = "\021";
112const char XOFF_String[] = "\023";
113
114const char ExpectedOutput_1[] =
115"0123456789012345678901234567890123456789"
116"0123456789012345678901234567890123456789"
117"0123456789012345678901234567890123456789"
118"0123456789012345678901234567890123456789"
119"0123456789012345678901234567890123456789";
120#if 0
121const char ExpectedInput_1[] = "Blocking interrupt driven read.\n";
122const char ExpectedInput_2[] = "Non-Blocking interrupt driven read.\n";
123#endif
124
125rtems_task Init(
126  rtems_task_argument argument
127)
128{
129  rtems_status_code sc;
130
131  puts( "\n\n*** TEST TERMIOS07 ***" );
132
133  puts( "rtems_termios_bufsize( 64, 64, 64 ) - OK" );
134  sc = rtems_termios_bufsize ( 64, 64, 64 );
135  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
136
137  open_it();
138
139  change_iflag( "Set XON/XOFF", IXON|IXOFF, IXON|IXOFF );
140
141  termios_test_driver_set_rx( XOFF_String, 1 );
142  sc = rtems_task_wake_after( 2 * rtems_clock_get_ticks_per_second() );
143  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
144
145  write_helper( Test_fd, ExpectedOutput_1 );
146
147#if 0
148  /* some basic cases */
149  write_helper( Test_fd, ExpectedOutput_1 );
150  read_helper( Test_fd, ExpectedInput_1 );
151  termios_test_driver_set_rx_enqueue_now( true );
152  read_helper( Test_fd, ExpectedInput_2 );
153#endif
154
155  close_it();
156
157  puts( "*** END OF TEST TERMIOS07 ***" );
158
159  rtems_test_exit(0);
160}
161
162/* configuration information */
163
164#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
165#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
166#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
167  TERMIOS_TEST_DRIVER_TABLE_ENTRY
168
169/* include an extra slot for registering the termios one dynamically */
170#define CONFIGURE_MAXIMUM_DRIVERS 3
171
172/* one for the console and one for the test port */
173#define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 3
174
175/* we need to be able to open the test device */
176#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
177#define CONFIGURE_MAXIMUM_TASKS                  1
178#define CONFIGURE_MAXIMUM_TIMERS                 2
179#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
180
181#define CONFIGURE_INIT
182
183#include <rtems/confdefs.h>
184/* end of file */
Note: See TracBrowser for help on using the repository browser.