1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <stdio.h> |
---|
15 | #include <sys/uio.h> |
---|
16 | #include <sys/types.h> |
---|
17 | #include <sys/stat.h> |
---|
18 | #include <fcntl.h> |
---|
19 | #include <unistd.h> |
---|
20 | #include <errno.h> |
---|
21 | #include <string.h> |
---|
22 | #include <ctype.h> |
---|
23 | #include <rtems/imfs.h> |
---|
24 | #include <reent.h> |
---|
25 | |
---|
26 | #include <rtems.h> |
---|
27 | #include <rtems/libio.h> |
---|
28 | |
---|
29 | #include <tmacros.h> |
---|
30 | #include "test_support.h" |
---|
31 | |
---|
32 | /* forward declarations to avoid warnings */ |
---|
33 | rtems_task Init(rtems_task_argument argument); |
---|
34 | void do_with_fd(int fd, const char *description); |
---|
35 | |
---|
36 | void do_with_fd( |
---|
37 | int fd, |
---|
38 | const char *description |
---|
39 | ) |
---|
40 | { |
---|
41 | struct stat stat_buff; |
---|
42 | struct iovec vec[4]; |
---|
43 | off_t res; |
---|
44 | int status; |
---|
45 | |
---|
46 | printf("ftruncate %s\n", description); |
---|
47 | status = ftruncate(fd, 40); |
---|
48 | rtems_test_assert( status == -1 ); |
---|
49 | printf( "%d: %s\n", errno, strerror( errno ) ); |
---|
50 | rtems_test_assert( errno == EBADF ); |
---|
51 | |
---|
52 | printf("_fcntl_r %s\n", description); |
---|
53 | status = _fcntl_r( NULL, fd, F_SETFD, 1 ); |
---|
54 | rtems_test_assert( status == -1 ); |
---|
55 | printf( "%d: %s\n", errno, strerror( errno ) ); |
---|
56 | rtems_test_assert( errno == EBADF ); |
---|
57 | |
---|
58 | printf("fdatasync %s\n", description); |
---|
59 | status = fdatasync( fd ); |
---|
60 | rtems_test_assert( status == -1 ); |
---|
61 | printf( "%d: %s\n", errno, strerror( errno ) ); |
---|
62 | rtems_test_assert( errno == EBADF ); |
---|
63 | |
---|
64 | printf("fstat %s\n", description); |
---|
65 | status = fstat( fd, &stat_buff ); |
---|
66 | rtems_test_assert( status == -1 ); |
---|
67 | printf( "%d: %s\n", errno, strerror( errno ) ); |
---|
68 | rtems_test_assert( errno == EBADF ); |
---|
69 | |
---|
70 | printf("fsync %s\n", description); |
---|
71 | status = fsync( fd ); |
---|
72 | rtems_test_assert( status == -1 ); |
---|
73 | printf( "%d: %s\n", errno, strerror( errno ) ); |
---|
74 | rtems_test_assert( errno == EBADF ); |
---|
75 | |
---|
76 | printf("ioctl %s\n", description); |
---|
77 | status = ioctl( fd, 0 ); |
---|
78 | rtems_test_assert( status == -1 ); |
---|
79 | printf( "%d: %s\n", errno, strerror( errno ) ); |
---|
80 | rtems_test_assert( errno == EBADF ); |
---|
81 | |
---|
82 | printf("_lseek_r %s\n", description); |
---|
83 | res = _lseek_r (NULL, fd, 0, SEEK_SET); |
---|
84 | rtems_test_assert( res == -1 ); |
---|
85 | printf( "%d: %s\n", errno, strerror( errno ) ); |
---|
86 | rtems_test_assert( errno == EBADF ); |
---|
87 | |
---|
88 | printf("readv %s\n", description); |
---|
89 | status = readv(fd, vec, 4); |
---|
90 | rtems_test_assert( status == -1 ); |
---|
91 | printf( "%d: %s\n", errno, strerror( errno ) ); |
---|
92 | rtems_test_assert( errno == EBADF ); |
---|
93 | |
---|
94 | printf("writev %s\n", description); |
---|
95 | status = writev(fd, vec, 4); |
---|
96 | rtems_test_assert( status == -1 ); |
---|
97 | printf( "%d: %s\n", errno, strerror( errno ) ); |
---|
98 | rtems_test_assert( errno == EBADF ); |
---|
99 | |
---|
100 | printf("write %s\n", description); |
---|
101 | status = write(fd, "1234", 4); |
---|
102 | rtems_test_assert( status == -1 ); |
---|
103 | printf( "%d: %s\n", errno, strerror( errno ) ); |
---|
104 | rtems_test_assert( errno == EBADF ); |
---|
105 | } |
---|
106 | |
---|
107 | rtems_task Init( |
---|
108 | rtems_task_argument argument |
---|
109 | ) |
---|
110 | { |
---|
111 | int status; |
---|
112 | int fd; |
---|
113 | |
---|
114 | puts( "\n\n*** PSXFILE02 TEST ***" ); |
---|
115 | |
---|
116 | /* |
---|
117 | * Simple open case where the file is created. |
---|
118 | */ |
---|
119 | puts( "mkdir /tmp" ); |
---|
120 | status = mkdir( "/tmp", S_IRWXU ); |
---|
121 | rtems_test_assert( !status ); |
---|
122 | |
---|
123 | puts( "open /tmp/j" ); |
---|
124 | fd = open( "/tmp/j", O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO ); |
---|
125 | rtems_test_assert( fd != -1 ); |
---|
126 | printf( "open returned file descriptor %d\n", fd ); |
---|
127 | |
---|
128 | puts( "close /tmp/j" ); |
---|
129 | status = close( fd ); |
---|
130 | rtems_test_assert( !status ); |
---|
131 | |
---|
132 | do_with_fd( fd, "an unopened file" ); |
---|
133 | puts(""); |
---|
134 | do_with_fd( 1000, "a too large file descriptor" ); |
---|
135 | |
---|
136 | puts( "*** END OF PSXFILE02 TEST ***" ); |
---|
137 | |
---|
138 | rtems_test_exit(0); |
---|
139 | } |
---|
140 | |
---|
141 | /* configuration information */ |
---|
142 | |
---|
143 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
144 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
145 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
146 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 |
---|
147 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
148 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
149 | |
---|
150 | #define CONFIGURE_INIT |
---|
151 | |
---|
152 | #include <rtems/confdefs.h> |
---|
153 | /* end of file */ |
---|