File indexing completed on 2025-05-11 08:24:35
0001
0002
0003
0004
0005
0006
0007
0008 #ifdef HAVE_CONFIG_H
0009 #include "config.h"
0010 #endif
0011
0012 #include <tmacros.h>
0013 #include "test_support.h"
0014
0015 #ifdef INTERRUPT_DRIVEN
0016 #include "../termios04/termios_testdriver_intr.h"
0017 const char rtems_test_name[] = "TERMIOS 11 -- Interrupt driven";
0018 #else
0019 #include "../termios03/termios_testdriver_polled.h"
0020 const char rtems_test_name[] = "TERMIOS 10 -- Polled";
0021 #endif
0022
0023 #include <sys/types.h>
0024 #include <sys/stat.h>
0025 #include <errno.h>
0026 #include <fcntl.h>
0027 #include <unistd.h>
0028 #include <signal.h>
0029 #include <termios.h>
0030 #include <rtems/dumpbuf.h>
0031 #include <rtems/libio.h>
0032
0033 int Test_fd;
0034
0035 static void open_it(void)
0036 {
0037 Test_fd = open( TERMIOS_TEST_DRIVER_DEVICE_NAME, O_RDWR );
0038 rtems_test_assert( Test_fd != -1 );
0039 }
0040
0041 static void change_lflag( const char *desc, int mask, int new )
0042 {
0043 int rc;
0044 struct termios attr;
0045
0046 if (desc) {
0047 printf( "Changing c_lflag to: %s\n", desc );
0048 }
0049
0050 rc = tcgetattr( Test_fd, &attr );
0051 rtems_test_assert( rc == 0 );
0052
0053 attr.c_lflag &= ~mask;
0054 attr.c_lflag |= new;
0055
0056 rc = tcsetattr( Test_fd, TCSANOW, &attr );
0057 rtems_test_assert( rc == 0 );
0058 }
0059
0060
0061 static void read_it(ssize_t expected, int expected_intr)
0062 {
0063 ssize_t rc;
0064 char buf[32];
0065
0066 rtems_test_assert( expected <= sizeof(buf) );
0067
0068 rc = read( Test_fd, buf, expected );
0069 if (expected_intr) {
0070 rtems_test_assert( rc == -1 );
0071 rtems_test_assert( errno == EINTR );
0072 } else {
0073 if ( expected != rc )
0074 printf( "ERROR - expected=%zd rc=%zd\n", expected, rc );
0075 rtems_test_assert( expected == rc );
0076 }
0077 }
0078
0079 static void close_it(void)
0080 {
0081 int rc;
0082
0083 rc = close( Test_fd );
0084 rtems_test_assert( rc == 0 );
0085 }
0086
0087 volatile int sigint_occurred = 0;
0088 volatile int sigquit_occurred = 0;
0089
0090 static void sigint_handler(int signo)
0091 {
0092 rtems_test_assert(signo == SIGINT);
0093 sigint_occurred = 1;
0094 }
0095
0096 static void sigquit_handler(int signo)
0097 {
0098 rtems_test_assert(signo == SIGQUIT);
0099 sigquit_occurred = 1;
0100 }
0101
0102 static void test_read_for_signal(
0103 const char *description,
0104 int isig_value,
0105 char c,
0106 int sigint_expected,
0107 int sigquit_expected
0108 )
0109 {
0110 char expected[3];
0111
0112 printf("Test read for %s\n", description);
0113
0114 expected[0] = c;
0115 expected[1] = '\n';
0116 expected[2] = '\0';
0117
0118 sigint_occurred = 0;
0119 sigquit_occurred = 0;
0120
0121 open_it();
0122
0123 change_lflag(NULL, ISIG, isig_value);
0124
0125 termios_test_driver_set_rx( expected, 2 );
0126
0127 read_it(1, (sigint_expected || sigquit_expected));
0128
0129 rtems_test_assert(sigint_occurred == sigint_expected);
0130 rtems_test_assert(sigquit_occurred == sigquit_expected);
0131 close_it();
0132 }
0133
0134
0135
0136
0137 static void *POSIX_Init(void *argument)
0138 {
0139 int rc;
0140
0141 TEST_BEGIN();
0142
0143 signal(SIGINT, sigint_handler);
0144 signal(SIGQUIT, sigquit_handler);
0145
0146 puts( "Exercise default ISIG handler with ISIG enabled");
0147 test_read_for_signal("VKILL - no signals", ISIG, '\003', 0, 0);
0148 test_read_for_signal("VQUIT - no signals", ISIG, '\034', 0, 0);
0149
0150 puts( "Exercise POSIX ISIG handler with ISIG enabled");
0151 rc = rtems_termios_register_isig_handler(rtems_termios_posix_isig_handler);
0152 rtems_test_assert( rc == 0 );
0153 test_read_for_signal("VKILL - signal caught", ISIG, '\003', 1, 0);
0154 test_read_for_signal("VQUIT - signal caught", ISIG, '\034', 0, 1);
0155
0156 puts( "Exercise default ISIG handler with ISIG enabled");
0157 rc = rtems_termios_register_isig_handler(rtems_termios_default_isig_handler);
0158 rtems_test_assert( rc == 0 );
0159 test_read_for_signal("VKILL - signal caught", ISIG, '\003', 0, 0);
0160 test_read_for_signal("VQUIT - signal caught", ISIG, '\034', 0, 0);
0161
0162 puts( "Exercise POSIX ISIG handler with ISIG disabled");
0163 rc = rtems_termios_register_isig_handler(rtems_termios_posix_isig_handler);
0164 rtems_test_assert( rc == 0 );
0165 test_read_for_signal("VKILL - signal caught", 0, '\003', 0, 0);
0166 test_read_for_signal("VQUIT - signal caught", 0, '\034', 0, 0);
0167
0168 TEST_END();
0169
0170 rtems_test_exit(0);
0171 }
0172
0173
0174
0175 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0176 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0177 #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
0178 TERMIOS_TEST_DRIVER_TABLE_ENTRY
0179
0180
0181 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0182 #define CONFIGURE_MAXIMUM_POSIX_THREADS 1
0183 #define CONFIGURE_MAXIMUM_TIMERS 2
0184 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0185
0186 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0187
0188 #define CONFIGURE_INIT
0189
0190 #include <rtems/confdefs.h>
0191