diff options
Diffstat (limited to 'testsuites/psxtests/psxfile02/init.c')
-rw-r--r-- | testsuites/psxtests/psxfile02/init.c | 90 |
1 files changed, 42 insertions, 48 deletions
diff --git a/testsuites/psxtests/psxfile02/init.c b/testsuites/psxtests/psxfile02/init.c index 778e033b04..6aa8a5ce35 100644 --- a/testsuites/psxtests/psxfile02/init.c +++ b/testsuites/psxtests/psxfile02/init.c @@ -18,6 +18,7 @@ #include <string.h> #include <ctype.h> #include <rtems/imfs.h> +#include <reent.h> #include <rtems.h> #include <rtems/libio.h> @@ -25,112 +26,105 @@ #include <tmacros.h> #include "test_support.h" -int _fcntl_r( - struct _reent *ptr __attribute__((unused)), - int fd, - int cmd, - int arg -); - -off_t _lseek_r( - struct _reent *ptr __attribute__((unused)), - int fd, - off_t offset, - int whence -); - - - -rtems_task Init( - rtems_task_argument argument +void do_with_fd( + int fd, + const char *description ) { - int fd; struct stat stat_buff; struct iovec vec[4]; off_t res; int status; - puts( "\n\n*** PSXFILE02 TEST ***" ); - - /* - * Simple open case where the file is created. - */ - puts( "mkdir /tmp" ); - status = mkdir( "/tmp", S_IRWXU ); - rtems_test_assert( !status ); - - puts( "open /tmp/j" ); - fd = open( "/tmp/j", O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO ); - rtems_test_assert( fd != -1 ); - printf( "open returned file descriptor %d\n", fd ); - - puts( "close /tmp/j" ); - status = close( fd ); - rtems_test_assert( !status ); - - puts("ftruncate an unopened file"); + printf("ftruncate %s\n", description); status = ftruncate(fd, 40); rtems_test_assert( status == -1 ); printf( "%d: %s\n", errno, strerror( errno ) ); rtems_test_assert( errno == EBADF ); - puts("_fcntl_r unopened file"); + printf("_fcntl_r %s\n", description); status = _fcntl_r( NULL, fd, F_SETFD, 1 ); rtems_test_assert( status == -1 ); printf( "%d: %s\n", errno, strerror( errno ) ); rtems_test_assert( errno == EBADF ); - puts("fdatasync unopened file"); + printf("fdatasync %s\n", description); status = fdatasync( fd ); rtems_test_assert( status == -1 ); printf( "%d: %s\n", errno, strerror( errno ) ); rtems_test_assert( errno == EBADF ); - puts("fstat unopened file"); + printf("fstat %s\n", description); status = fstat( fd, &stat_buff ); rtems_test_assert( status == -1 ); printf( "%d: %s\n", errno, strerror( errno ) ); rtems_test_assert( errno == EBADF ); - puts("fsync unopened file"); + printf("fsync %s\n", description); status = fsync( fd ); rtems_test_assert( status == -1 ); printf( "%d: %s\n", errno, strerror( errno ) ); rtems_test_assert( errno == EBADF ); - puts("ioctl unopened file"); + printf("ioctl %s\n", description); status = ioctl( fd, 0 ); rtems_test_assert( status == -1 ); printf( "%d: %s\n", errno, strerror( errno ) ); rtems_test_assert( errno == EBADF ); - puts("_lseek_r unopened file"); + printf("_lseek_r %s\n", description); res = _lseek_r (NULL, fd, 0, SEEK_SET); rtems_test_assert( res == -1 ); printf( "%d: %s\n", errno, strerror( errno ) ); rtems_test_assert( errno == EBADF ); - puts("readv unopened file"); + printf("readv %s\n", description); status = readv(fd, vec, 4); rtems_test_assert( status == -1 ); printf( "%d: %s\n", errno, strerror( errno ) ); rtems_test_assert( errno == EBADF ); - puts("writev unopened file"); + printf("writev %s\n", description); status = writev(fd, vec, 4); rtems_test_assert( status == -1 ); printf( "%d: %s\n", errno, strerror( errno ) ); rtems_test_assert( errno == EBADF ); - puts("write unopened file"); + printf("write %s\n", description); status = write(fd, "1234", 4); rtems_test_assert( status == -1 ); printf( "%d: %s\n", errno, strerror( errno ) ); rtems_test_assert( errno == EBADF ); +} + +rtems_task Init( + rtems_task_argument argument +) +{ + int status; + int fd; + puts( "\n\n*** PSXFILE02 TEST ***" ); + /* + * Simple open case where the file is created. + */ + puts( "mkdir /tmp" ); + status = mkdir( "/tmp", S_IRWXU ); + rtems_test_assert( !status ); + + puts( "open /tmp/j" ); + fd = open( "/tmp/j", O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO ); + rtems_test_assert( fd != -1 ); + printf( "open returned file descriptor %d\n", fd ); + + puts( "close /tmp/j" ); + status = close( fd ); + rtems_test_assert( !status ); + do_with_fd( fd, "an unopened file" ); + puts(""); + do_with_fd( 1000, "a too large file descriptor" ); puts( "*** END OF PSXFILE02 TEST ***" ); @@ -142,7 +136,7 @@ rtems_task Init( #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM -#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6 +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 #define CONFIGURE_MAXIMUM_TASKS 1 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |