Back to home page

LXR

 
 

    


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

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 "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 
0044 const char rtems_test_name[] = "TERMIOS 4";
0045 
0046 /* forward declarations to avoid warnings */
0047 void write_helper(int fd, const char *c);
0048 void read_helper(int fd, const char *expected);
0049 void open_it(void);
0050 void close_it(void);
0051 rtems_task Init(rtems_task_argument argument);
0052 
0053 void write_helper(
0054   int        fd,
0055   const char *c
0056 )
0057 {
0058   size_t   len;
0059   int      rc;
0060   
0061   len = strlen( c );
0062   printf( "Writing: %s", c );
0063 
0064   rc = write( fd, c, len );
0065   rtems_test_assert( rc == len );
0066 
0067   termios_test_driver_dump_tx("Transmitted");
0068 }
0069 
0070 uint8_t read_helper_buffer[256];
0071 
0072 void read_helper(
0073   int         fd,
0074   const char *expected
0075 )
0076 {
0077   int    rc;
0078   size_t len;
0079 
0080   len = strlen( expected );
0081 
0082   termios_test_driver_set_rx( expected, len );
0083   printf( "\nReading (expected):\n" );
0084   rtems_print_buffer( (unsigned char *)expected, len-1 );
0085 
0086   rc = read( fd, read_helper_buffer, sizeof(read_helper_buffer) );
0087   rtems_test_assert( rc != -1 );
0088 
0089   printf( "Read %d bytes from read(2)\n", rc );
0090   rtems_print_buffer( read_helper_buffer, rc );
0091 
0092   termios_test_driver_dump_tx("As Read");
0093 }
0094 
0095 int Test_fd;
0096 
0097 void open_it(void)
0098 {
0099   /* open the file */
0100   puts( "open(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
0101   Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
0102   rtems_test_assert( Test_fd != -1 );
0103 }
0104 
0105 void close_it(void)
0106 {
0107   int rc;
0108 
0109   puts( "close(" TERMIOS_TEST_DRIVER_DEVICE_NAME ") - OK " );
0110   rc = close( Test_fd );
0111   rtems_test_assert( rc == 0 );
0112 }
0113 
0114 const char ExpectedOutput_1[] = "This is interrupt driven test output.\n";
0115 const char ExpectedInput_1[] = "Blocking interrupt driven read.\n";
0116 const char ExpectedInput_2[] = "Non-Blocking interrupt driven read.\n";
0117 
0118 rtems_task Init(
0119   rtems_task_argument argument
0120 )
0121 {
0122   TEST_BEGIN();
0123 
0124   open_it();
0125 
0126   /* some basic cases */
0127   write_helper( Test_fd, ExpectedOutput_1 );
0128   read_helper( Test_fd, ExpectedInput_1 );
0129   termios_test_driver_set_rx_enqueue_now( true );
0130   read_helper( Test_fd, ExpectedInput_2 );
0131 
0132   close_it();
0133 
0134   TEST_END();
0135 
0136   rtems_test_exit(0);
0137 }
0138 
0139 /* configuration information */
0140 
0141 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0142 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0143 #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
0144   TERMIOS_TEST_DRIVER_TABLE_ENTRY
0145 
0146 /* we need to be able to open the test device */
0147 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0148 #define CONFIGURE_MAXIMUM_TASKS             1
0149 #define CONFIGURE_MAXIMUM_TIMERS            2
0150 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0151 
0152 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0153 
0154 #define CONFIGURE_INIT
0155 
0156 #include <rtems/confdefs.h>
0157 /* end of file */