source: rtems/testsuites/libtests/termios07/init.c @ 78da8ac3

4.115
Last change on this file since 78da8ac3 was 78da8ac3, checked in by Joel Sherrill <joel.sherrill@…>, on 07/19/10 at 13:54:47

2010-07-19 Joel Sherrill <joel.sherrill@…>

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