Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:35

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <tmacros.h>
0034 #include "test_support.h"
0035 #include "../termios04/termios_testdriver_intr.h"
0036 
0037 #include <sys/types.h>
0038 #include <sys/stat.h>
0039 #include <fcntl.h>
0040 #include <unistd.h>
0041 #include <termios.h>
0042 #include <rtems/dumpbuf.h>
0043 #include <rtems/libio.h>
0044 
0045 const char rtems_test_name[] = "TERMIOS 7";
0046 
0047 /* forward declarations to avoid warnings */
0048 rtems_task Init(rtems_task_argument argument);
0049 void write_helper(int fd, const char *c);
0050 void read_helper(int fd, const char *expected);
0051 void open_it(void);
0052 void close_it(void);
0053 void change_iflag(const char *desc, int mask, int new);
0054 
0055 void write_helper(
0056   int        fd,
0057   const char *c
0058 )
0059 {
0060   size_t   len;
0061   int      rc;
0062   
0063   len = strlen( c );
0064   printf( "Writing: %s", c );
0065 
0066   rc = write( fd, c, len );
0067   rtems_test_assert( rc == len );
0068 
0069   termios_test_driver_dump_tx("Transmitted");
0070 }
0071 
0072 uint8_t read_helper_buffer[256];
0073 
0074 void read_helper(
0075   int         fd,
0076   const char *expected
0077 )
0078 {
0079   int    rc;
0080   size_t len;
0081 
0082   len = strlen( expected );
0083 
0084   termios_test_driver_set_rx( expected, len );
0085   printf( "\nReading (expected):\n" );
0086   rtems_print_buffer( (unsigned char *)expected, len-1 );
0087 
0088   rc = read( fd, read_helper_buffer, sizeof(read_helper_buffer) );
0089   rtems_test_assert( rc != -1 );
0090 
0091   printf( "Read %d bytes from read(2)\n", rc );
0092   rtems_print_buffer( read_helper_buffer, rc );
0093 
0094   termios_test_driver_dump_tx("As Read");
0095 }
0096 
0097 int Test_fd;
0098 
0099 void open_it(void)
0100 {
0101   /* open the file */
0102   puts( "open(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
0103   Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
0104   rtems_test_assert( Test_fd != -1 );
0105 }
0106 
0107 void close_it(void)
0108 {
0109   int rc;
0110 
0111   puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
0112   rc = close( Test_fd );
0113   rtems_test_assert( rc == 0 );
0114 }
0115 
0116 void change_iflag( const char *desc, int mask, int new )
0117 {
0118   int            rc;
0119   struct termios attr;
0120 
0121   printf( "Changing c_iflag to: %s\n", desc );
0122   rc = tcgetattr( Test_fd, &attr );
0123   rtems_test_assert( rc == 0 );
0124 
0125   attr.c_iflag &= ~mask;
0126   attr.c_iflag |= new;
0127 
0128   rc = tcsetattr( Test_fd, TCSANOW, &attr );
0129   rtems_test_assert( rc == 0 );
0130 }
0131 
0132 const char XON_String[] = "\021";
0133 const char XOFF_String[] = "\023";
0134 
0135 const char ExpectedOutput_1[] =
0136 "0123456789012345678901234567890123456789"
0137 "0123456789012345678901234567890123456789"
0138 "0123456789012345678901234567890123456789"
0139 "0123456789012345678901234567890123456789"
0140 "0123456789012345678901234567890123456789";
0141 #if 0
0142 const char ExpectedInput_1[] = "Blocking interrupt driven read.\n";
0143 const char ExpectedInput_2[] = "Non-Blocking interrupt driven read.\n";
0144 #endif
0145 
0146 rtems_task Init(
0147   rtems_task_argument argument
0148 )
0149 {
0150   rtems_status_code sc;
0151 
0152   TEST_BEGIN();
0153 
0154   puts( "rtems_termios_bufsize( 64, 64, 64 ) - OK" );
0155   sc = rtems_termios_bufsize ( 64, 64, 64 );
0156   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0157 
0158   open_it();
0159 
0160   change_iflag( "Set XON/XOFF", IXON|IXOFF, IXON|IXOFF );
0161 
0162   termios_test_driver_set_rx( XOFF_String, 1 );
0163   sc = rtems_task_wake_after( 2 * rtems_clock_get_ticks_per_second() );
0164   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0165 
0166   write_helper( Test_fd, ExpectedOutput_1 );
0167 
0168 #if 0
0169   /* some basic cases */
0170   write_helper( Test_fd, ExpectedOutput_1 );
0171   read_helper( Test_fd, ExpectedInput_1 );
0172   termios_test_driver_set_rx_enqueue_now( true );
0173   read_helper( Test_fd, ExpectedInput_2 );
0174 #endif
0175 
0176   close_it();
0177 
0178   TEST_END();
0179 
0180   rtems_test_exit(0);
0181 }
0182 
0183 /* configuration information */
0184 
0185 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0186 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0187 #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
0188   TERMIOS_TEST_DRIVER_TABLE_ENTRY
0189 
0190 /* we need to be able to open the test device */
0191 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0192 #define CONFIGURE_MAXIMUM_TASKS                  1
0193 #define CONFIGURE_MAXIMUM_TIMERS                 2
0194 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0195 
0196 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0197 
0198 #define CONFIGURE_INIT
0199 
0200 #include <rtems/confdefs.h>
0201 /* end of file */