source: rtems/testsuites/libtests/termios04/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: 3.6 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
25/* forward declarations to avoid warnings */
26void write_helper(int fd, const char *c);
27void read_helper(int fd, const char *expected);
28void open_it(void);
29void close_it(void);
30void change_iflag(const char *desc, int mask, int new);
31rtems_task Init(rtems_task_argument argument);
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("As Read");
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 interrupt driven test output.\n";
111const char ExpectedInput_1[] = "Blocking interrupt driven read.\n";
112const char ExpectedInput_2[] = "Non-Blocking interrupt driven read.\n";
113
114rtems_task Init(
115  rtems_task_argument argument
116)
117{
118  puts( "\n\n*** TEST TERMIOS04 ***" );
119
120  open_it();
121
122  /* some basic cases */
123  write_helper( Test_fd, ExpectedOutput_1 );
124  read_helper( Test_fd, ExpectedInput_1 );
125  termios_test_driver_set_rx_enqueue_now( true );
126  read_helper( Test_fd, ExpectedInput_2 );
127
128  close_it();
129
130  puts( "*** END OF TEST TERMIOS04 ***" );
131
132  rtems_test_exit(0);
133}
134
135/* configuration information */
136
137#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
138#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
139#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
140  TERMIOS_TEST_DRIVER_TABLE_ENTRY
141
142/* include an extra slot for registering the termios one dynamically */
143#define CONFIGURE_MAXIMUM_DRIVERS 3
144
145/* one for the console and one for the test port */
146#define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 3
147
148/* we need to be able to open the test device */
149#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
150#define CONFIGURE_MAXIMUM_TASKS             1
151#define CONFIGURE_MAXIMUM_TIMERS            2
152#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
153
154#define CONFIGURE_INIT
155
156#include <rtems/confdefs.h>
157/* end of file */
Note: See TracBrowser for help on using the repository browser.