source: rtems/testsuites/libtests/termios04/init.c @ 1c6926c1

5
Last change on this file since 1c6926c1 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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