File indexing completed on 2025-05-11 08:24:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
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
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
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
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
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
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