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 "../termios03/termios_testdriver_polled.h"
0036 
0037 #include <sys/types.h>
0038 #include <sys/stat.h>
0039 #include <fcntl.h>
0040 #include <unistd.h>
0041 #include <sys/ioctl.h>
0042 #include <rtems/dumpbuf.h>
0043 #include <rtems/termiostypes.h>
0044 
0045 const char rtems_test_name[] = "TERMIOS 8";
0046 
0047 /* forward declarations to avoid warnings */
0048 rtems_task Init(rtems_task_argument argument);
0049 void open_it(void);
0050 void close_it(void);
0051 void write_it(void);
0052 void change_lflag( const char *desc, int mask, int new );
0053 void change_vmin_vtime( const char *desc, int min, int time );
0054 void read_it(ssize_t expected);
0055 
0056 int Test_fd;
0057 
0058 void open_it(void)
0059 {
0060   /* open the file */
0061   puts( "open(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
0062   Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
0063   rtems_test_assert( Test_fd != -1 );
0064 }
0065 
0066 void close_it(void)
0067 {
0068   int rc;
0069 
0070   puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
0071   rc = close( Test_fd );
0072   rtems_test_assert( rc == 0 );
0073 }
0074 
0075 void write_it(void)
0076 {
0077   ssize_t sc;
0078   char    ch[10] = "PPPD TEST";
0079 
0080   puts( "write(PPPD TEST) - OK " );
0081   sc = write(Test_fd, ch, sizeof(ch));
0082   rtems_test_assert( sc == sizeof(ch) );
0083 }
0084 
0085 uint8_t read_helper_buffer[256];
0086 
0087 void change_lflag( const char *desc, int mask, int new )
0088 {
0089   int            rc;
0090   struct termios attr;
0091 
0092   printf( "Changing c_lflag to: %s\n", desc );
0093   rc = tcgetattr( Test_fd, &attr );
0094   rtems_test_assert( rc == 0 );
0095 
0096   attr.c_lflag &= ~mask;
0097   attr.c_lflag |= new;
0098 
0099   rc = tcsetattr( Test_fd, TCSANOW, &attr );
0100   rtems_test_assert( rc == 0 );
0101 }
0102 
0103 void change_vmin_vtime( const char *desc, int min, int time )
0104 {
0105   int            rc;
0106   struct termios attr;
0107 
0108   printf( "Changing %s - VMIN=%d VTIME=%d\n", desc, min, time );
0109   rc = tcgetattr( Test_fd, &attr );
0110   rtems_test_assert( rc == 0 );
0111 
0112   attr.c_cc[VMIN] = min;
0113   attr.c_cc[VTIME] = time;
0114 
0115   rc = tcsetattr( Test_fd, TCSANOW, &attr );
0116   rtems_test_assert( rc == 0 );
0117 }
0118 
0119 void read_it( ssize_t expected )
0120 {
0121   ssize_t rc;
0122   char    buf[32];
0123 
0124   rtems_test_assert( expected <= sizeof(buf) );
0125 
0126   printf( "read - %zd expected\n", expected );
0127   rc = read( Test_fd, buf, expected ); 
0128   if ( expected != rc )
0129     printf( "ERROR - expected=%zd rc=%zd\n", expected, rc );
0130   rtems_test_assert( expected == rc );
0131 }
0132 
0133 rtems_task Init(
0134   rtems_task_argument argument
0135 )
0136 {
0137   TEST_BEGIN();
0138 
0139   open_it();
0140   change_lflag( "non-canonical", ICANON, 0 );
0141 
0142   change_vmin_vtime( "to polling", 0, 0 );
0143   read_it( 0 );
0144 
0145   change_vmin_vtime( "to half-second timeout", 0, 5 );
0146   read_it( 0 );
0147 
0148   change_vmin_vtime( "to half-second timeout", 5, 3 );
0149   puts( "Enqueue 2 characters" );
0150   termios_test_driver_set_rx( "ab", 2 );
0151   read_it( 2 );
0152 
0153   change_vmin_vtime( "to half-second timeout", 5, 3 );
0154   puts( "Enqueue 1 character" );
0155   termios_test_driver_set_rx( "b", 1 );
0156   read_it( 1 );
0157 
0158   puts( "Enqueue 7 characters" );
0159   termios_test_driver_set_rx( "1234567", 7 );
0160   read_it( 5 );
0161   read_it( 2 );
0162 
0163   close_it();
0164   
0165   TEST_END();
0166 
0167   rtems_test_exit(0);
0168 }
0169 
0170 /* configuration information */
0171 
0172 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0173 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0174 #define CONFIGURE_APPLICATION_EXTRA_DRIVERS TERMIOS_TEST_DRIVER_TABLE_ENTRY
0175 
0176 /* we need to be able to open the test device */
0177 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0178 
0179 #define CONFIGURE_MAXIMUM_TASKS             1
0180 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0181 
0182 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0183 
0184 #define CONFIGURE_INIT
0185 
0186 #include <rtems/confdefs.h>
0187 /* end of file */