source: rtems/testsuites/libtests/termios07/init.c @ 53b6484

5
Last change on this file since 53b6484 was 53b6484, checked in by Sebastian Huber <sebastian.huber@…>, on 02/05/18 at 08:57:45

termios: Remove obsolete configuration options

Update #2843.

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