File indexing completed on 2025-05-11 08:24:37
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
0030
0031
0032
0033
0034
0035 #define _POSIX_26_C_SOURCE
0036
0037 #ifdef HAVE_CONFIG_H
0038 #include "config.h"
0039 #endif
0040
0041 #include "tmacros.h"
0042 #include <errno.h>
0043 #include <sys/ioctl.h>
0044 #include <stdlib.h>
0045
0046 #include <devctl.h>
0047
0048 #include <unistd.h>
0049 #include <fcntl.h>
0050
0051 const char rtems_test_name[] = "PSXDEVCTL 1";
0052
0053
0054 int test_main(void);
0055
0056
0057
0058
0059
0060 #if defined(__rtems__)
0061 int test_main(void)
0062 #else
0063 int main(
0064 int argc,
0065 char **argv
0066 )
0067 #endif
0068 {
0069 int status;
0070 int fd;
0071 int dcmd;
0072 int dev_data;
0073 void *dev_data_ptr;
0074 size_t nbyte;
0075
0076 TEST_BEGIN();
0077
0078 puts( "posix_devctl() SOCKCLOSE on invalid file descriptor -- EBADF" );
0079 fd = -1;
0080 dcmd = SOCKCLOSE;
0081 dev_data_ptr = NULL;
0082 nbyte = 0;
0083 status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
0084 rtems_test_assert( status == EBADF );
0085
0086
0087
0088
0089
0090 puts( "posix_devctl() SOCKCLOSE on valid file descriptor -- OK" );
0091 fd = open("tmp_for_close", O_CREAT | O_RDWR, S_IRWXU );
0092 rtems_test_assert( fd != -1 );
0093
0094 dcmd = SOCKCLOSE;
0095 dev_data_ptr = NULL;
0096 nbyte = 0;
0097 status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
0098 rtems_test_assert( status == 0 );
0099
0100 status = close( fd );
0101 rtems_test_assert( status == -1 );
0102 rtems_test_assert( errno == EBADF );
0103
0104 puts( "posix_devctl() FIONBIO with invalid nbyte -- EINVAL" );
0105 fd = 0;
0106 dcmd = FIONBIO;
0107 dev_data_ptr = NULL;
0108 nbyte = 0;
0109 status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
0110 rtems_test_assert( status == EINVAL );
0111
0112 puts( "posix_devctl() FIONBIO with invalid file descriptor -- EBADF" );
0113 fd = -1;
0114 dcmd = FIONBIO;
0115 dev_data_ptr = NULL;
0116 nbyte = sizeof(int);
0117 status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
0118 rtems_test_assert( status == EBADF );
0119
0120 puts( "posix_devctl() FIONBIO flag not zero -- 0" );
0121 fd = 0;
0122 dcmd = FIONBIO;
0123 dev_data = 1;
0124 dev_data_ptr = &dev_data;
0125 nbyte = sizeof(int);
0126 status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
0127 rtems_test_assert( status == 0 );
0128
0129 puts( "posix_devctl() FIONBIO flag is zero -- 0" );
0130 fd = 0;
0131 dcmd = FIONBIO;
0132 dev_data = 0;
0133 dev_data_ptr = &dev_data;
0134 nbyte = sizeof(int);
0135 status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
0136 rtems_test_assert( status == 0 );
0137
0138 puts( "posix_devctl() dcmd not valid value -- EBADF" );
0139 fd = 0;
0140 dcmd = 1;
0141 dev_data = 0;
0142 dev_data_ptr = &dev_data;
0143 nbyte = sizeof(int);
0144 status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
0145 rtems_test_assert( status == EBADF );
0146
0147 TEST_END();
0148 exit(0);
0149 }