source: rtems/testsuites/fstests/fserror/test.c @ db6fbdf

4.115
Last change on this file since db6fbdf was db6fbdf, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/07/11 at 07:32:05

2011-09-07 Ralf Corsépius <ralf.corsepius@…>

  • fserror/fserror.doc, fserror/test.c, fslink/fslink.doc, fslink/test.c, fspatheval/patheval.doc, fspatheval/test.c, fspermission/fspermission.doc, fspermission/test.c, fsrdwr/fsrdwr.doc, fsrdwr/init.c, fssymlink/fssymlink.doc, fssymlink/test.c, fstime/fstime.doc, fstime/test.c, imfs_support/fs_config.h, imfs_support/fs_support.c, imfs_support/fs_supprot.h, mdosfs_support/fs_config.h, mdosfs_support/fs_support.c, mimfs_support/fs_config.h, mimfs_support/fs_support.c, mrfs_support/fs_config.h, mrfs_support/fs_support.c, support/fstest.h, support/fstest_support.c, support/fstest_support.h, support/ramdisk_support.c, support/ramdisk_support.h: Fix CVS-Ids.
  • Property mode set to 100644
File size: 8.3 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
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.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <sys/stat.h>
13#include <limits.h>
14#include <fcntl.h>
15#include <errno.h>
16#include <stdio.h>
17#include <stdint.h>
18#include <stdlib.h>
19#include <string.h>
20#include <unistd.h>
21
22#include "fstest.h"
23
24void open_mkdir_error (void)
25{
26  int fd;
27  int status;
28  char *name01 = "name01";
29  char *name02 = "name02";
30  char *name03 = "name03";
31
32  char name[20];
33
34  mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
35
36  const char *wd = __func__;
37
38  /*
39   * Create a new directory and change the current directory to  this
40   */
41  status = mkdir (wd, mode);
42  rtems_test_assert (status == 0);
43  status = chdir (wd);
44  rtems_test_assert (status == 0);
45
46
47  /*
48   * Create a file and a directory for test.
49   */
50  fd = creat (name01, mode);
51  status = close (fd);
52  rtems_test_assert (status == 0);
53  status = mkdir (name02, mode);
54  rtems_test_assert (status == 0);
55
56  /*
57   * O_CREAT and O_EXCL are set, and the named file exists.
58   */
59  EXPECT_ERROR (EEXIST, open, name01, O_CREAT | O_EXCL);
60
61  EXPECT_ERROR (EEXIST, mkdir, name01, mode);
62  /*
63   * The named file is a directory
64   * and oflag includes O_WRONLY or O_RDWR.
65   */
66  EXPECT_ERROR (EISDIR, open, name02, O_WRONLY);
67  EXPECT_ERROR (EISDIR, open, name02, O_RDWR);
68
69  /*
70   * O_CREAT is not set and the named file does not exist
71   * or O_CREAT is set and either the path prefix does not exist or
72   * the path argument points to an empty string.
73   */
74
75  sprintf (name, "%s/%s", name03, name02);
76  EXPECT_ERROR (ENOENT, open, name, O_WRONLY);
77  EXPECT_ERROR (ENOENT, open, "", O_WRONLY);
78  EXPECT_ERROR (ENOENT, open, name03, O_WRONLY);
79
80  EXPECT_ERROR (ENOENT, mkdir, name, mode);
81  EXPECT_ERROR (ENOENT, mkdir, "", mode);
82
83  /*
84   * A component of the path prefix is not a directory.
85   */
86
87  sprintf (name, "%s/%s", name01, name02);
88  EXPECT_ERROR (ENOTDIR, open, name, O_WRONLY);
89
90  EXPECT_ERROR (ENOTDIR, mkdir, name, mode);
91  /*
92   * The fildes argument is not a valid file descriptor.
93   */
94  EXPECT_ERROR (EBADF, close, -1);
95  EXPECT_ERROR (EBADF, close, 100);
96
97  /*
98   * Go back to parent directory
99   */
100  status = chdir ("..");
101  rtems_test_assert (status == 0);
102
103}
104
105void rename_error (void)
106{
107
108  int fd;
109  int status;
110  char *name01 = "name01";
111  char *name02 = "name02";
112  char *name03 = "name03";
113  char *nonexistence = "name04";
114
115  char name[20];
116
117  mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
118  const char *wd = __func__;
119
120  /*
121   *Create a new directory and change the current directory to  this
122   */
123
124  status = mkdir (wd, mode);
125  rtems_test_assert (status == 0);
126  status = chdir (wd);
127  rtems_test_assert (status == 0);
128
129
130  /*
131   * Create a new directory and a new directory in it
132   */
133
134  status = mkdir (name01, mode);
135  rtems_test_assert (status == 0);
136  status = mkdir (name02, mode);
137  rtems_test_assert (status == 0);
138  sprintf (name, "%s/%s", name01, name03);
139  status = mkdir (name, mode);
140  rtems_test_assert (status == 0);
141
142  /*
143   * The link named by new is a directory that is
144   *  not an empty directory.
145   */
146  status = rename (name02, name01);
147  rtems_test_assert (status != 0);
148  rtems_test_assert (errno == EEXIST || errno == ENOTEMPTY);
149  /*
150   * The new directory pathname contains a path prefix
151   *  that names the old directory.
152   */
153  EXPECT_ERROR (EINVAL, rename, name01, name);
154  /*
155   * The new argument points to a directory and
156   *  the old argument points to a file that is not a directory.
157   */
158  fd = creat (name03, mode);
159  status = close (fd);
160  rtems_test_assert (status == 0);
161  EXPECT_ERROR (EISDIR, rename, name03, name02);
162
163  /*
164   * The link named by old does not name an existing file,
165   *    or either old or new points to an empty string.
166   */
167
168  EXPECT_ERROR (ENOENT, rename, nonexistence, name01);
169  EXPECT_ERROR (ENOENT, rename, "", name01);
170  EXPECT_ERROR (ENOENT, rename, name01, "");
171
172  /*
173   * A component of either path prefix is not a directory;
174   * or the old argument names a directory and new argument names
175   *  a non-directory file.
176   */
177
178  sprintf (name, "%s/%s", name03, name01);
179  EXPECT_ERROR (ENOTDIR, rename, name, name03);
180  EXPECT_ERROR (ENOTDIR, rename, name03, name);
181  EXPECT_ERROR (ENOTDIR, rename, name02, name03);
182
183  /*
184   * Go back to parent directory
185   */
186  status = chdir ("..");
187  rtems_test_assert (status == 0);
188}
189
190void truncate_error (void)
191{
192
193  int fd;
194  int status;
195  char *file = "name";
196
197  mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
198
199  const char *wd = __func__;
200
201  /*
202   *Create a new directory and change the current directory to  this
203   */
204  status = mkdir (wd, mode);
205  rtems_test_assert (status == 0);
206  status = chdir (wd);
207  rtems_test_assert (status == 0);
208  /*
209   * Create a file
210   */
211  fd = creat (file, mode);
212  status = close (fd);
213  rtems_test_assert (status == 0);
214
215
216  /*
217   * The length argument was less than 0.
218   */
219  EXPECT_ERROR (EINVAL, truncate, file, -1);
220
221  /*
222   * Go back to parent directory
223   */
224  status = chdir ("..");
225  rtems_test_assert (status == 0);
226}
227
228
229void rmdir_unlink_error (void)
230{
231  int status;
232  int fd;
233  mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
234  char *nonexistence = "name04";
235
236  const char *wd = __func__;
237
238  /*
239   * Create a new directory and change the current directory to  this
240   */
241  status = mkdir (wd, mode);
242  rtems_test_assert (status == 0);
243  status = chdir (wd);
244  rtems_test_assert (status == 0);
245
246  /*
247   * Create a new directory and a file in it for test
248   */
249  status = mkdir ("tmp", mode);
250  rtems_test_assert (status == 0);
251  fd = creat ("tmp/file", mode);
252  status = close (fd);
253  rtems_test_assert (status == 0);
254
255
256
257  /*
258   * The path argument names a directory that is not an empty directory,
259   * or there are hard links to the directory other than
260   * dot or a single entry in dot-dot.
261   */
262
263  EXPECT_ERROR (ENOTEMPTY, rmdir, "..");
264  EXPECT_ERROR (ENOTEMPTY, rmdir, "tmp");
265
266
267  /*
268   * The path argument contains a last component that is dot.
269   */
270
271
272  EXPECT_ERROR (EINVAL, rmdir, ".");
273  EXPECT_ERROR (EINVAL, rmdir, "tmp/.");
274
275  /*
276   * A component of path does not name an existing file,
277   * or the path argument names a nonexistent directory or
278   * points to an empty string
279   */
280  EXPECT_ERROR (ENOENT, rmdir, "");
281  EXPECT_ERROR (ENOENT, rmdir, nonexistence);
282
283  EXPECT_ERROR (ENOENT, unlink, "");
284  EXPECT_ERROR (ENOENT, unlink, nonexistence);
285
286  /*
287   * component of path is not a directory.
288   */
289
290  EXPECT_ERROR (ENOTDIR, rmdir, "tmp/file");
291
292  EXPECT_ERROR (ENOTDIR, unlink, "tmp/file/dir");
293  /*
294   * Go back to parent directory
295   */
296  status = chdir ("..");
297  rtems_test_assert (status == 0);
298
299
300}
301
302void rdwr_error (void)
303{
304
305  int status;
306  int fd;
307  char *file01 = "name01";
308  char *databuf = "test";
309  char *readbuf[10];
310
311
312  mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
313  const char *wd = __func__;
314
315  /*
316   * Create a new directory and change the current directory to  this
317   */
318  status = mkdir (wd, mode);
319  rtems_test_assert (status == 0);
320  status = chdir (wd);
321  rtems_test_assert (status == 0);
322
323  fd = open (file01, O_WRONLY | O_CREAT, mode);
324
325  /*
326   * The fildes argument is not a valid file descriptor open for reading.
327   */
328
329  EXPECT_ERROR (EBADF, read, fd, readbuf, 10);
330  EXPECT_ERROR (EBADF, read, 100, readbuf, 10);
331
332  status = close (fd);
333  rtems_test_assert (status == 0);
334  /*
335   * The fildes argument is not a valid file descriptor open for writing.
336   */
337  fd = open (file01, O_RDONLY, mode);
338
339  EXPECT_ERROR (EBADF, write, fd, databuf, 10);
340  EXPECT_ERROR (EBADF, write, 100, readbuf, 10);
341
342  /*
343   * The whence argument is not a proper value,
344   * or the resulting file offset would be negative for a regular file,
345   * block special file, or directory.
346   */
347
348  EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_END);
349  EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_CUR);
350  EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_SET);
351
352  status = close (fd);
353  rtems_test_assert (status == 0);
354
355  EXPECT_ERROR (EBADF, lseek, fd, -100, SEEK_SET);
356  /*
357   * Go back to parent directory
358   */
359  status = chdir ("..");
360  rtems_test_assert (status == 0);
361
362}
363
364void test (void)
365{
366
367  puts ("\n\n*** ERROR TEST ***");
368  open_mkdir_error ();
369  rename_error ();
370  truncate_error ();
371  rmdir_unlink_error ();
372  rdwr_error ();
373  puts ("*** END OF ERROR TEST ***");
374}
Note: See TracBrowser for help on using the repository browser.