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

4.115
Last change on this file since a7c39d3 was a7c39d3, checked in by Joel Sherrill <joel.sherrill@…>, on 08/01/11 at 21:54:19

2011-08-01 Xiang Cui <medivhc@…>

  • imfs_fslink/Makefile.am, imfs_fssymlink/Makefile.am, mimfs_fslink/Makefile.am, mimfs_fssymlink/Makefile.am, mrfs_fslink/Makefile.am, mrfs_fssymlink/Makefile.am, mrfs_support/fs_config.h: Correcting from previous commit of incorrect tarball.
  • fserror/fserror.doc, fserror/test.c, fspatheval/patheval.doc, fspatheval/test.c, fspermission/fspermission.doc, fspermission/test.c, fsrdwr/fsrdwr.doc, fsrdwr/init.c, fstime/fstime.doc, fstime/test.c, imfs_fserror/.cvsignore, imfs_fserror/Makefile.am, imfs_fslink/.cvsignore, imfs_fspatheval/.cvsignore, imfs_fspatheval/Makefile.am, imfs_fspermission/.cvsignore, imfs_fspermission/Makefile.am, imfs_fsrdwr/.cvsignore, imfs_fsrdwr/Makefile.am, imfs_fssymlink/.cvsignore, imfs_fstime/.cvsignore, imfs_fstime/Makefile.am, imfs_support/fs_supprot.h, mdosfs_fserror/.cvsignore, mdosfs_fserror/Makefile.am, mdosfs_fspatheval/.cvsignore, mdosfs_fspatheval/Makefile.am, mdosfs_fsrdwr/.cvsignore, mdosfs_fsrdwr/Makefile.am, mdosfs_fstime/.cvsignore, mdosfs_fstime/Makefile.am, mimfs_fserror/.cvsignore, mimfs_fserror/Makefile.am, mimfs_fslink/.cvsignore, mimfs_fspatheval/.cvsignore, mimfs_fspatheval/Makefile.am, mimfs_fspermission/.cvsignore, mimfs_fspermission/Makefile.am, mimfs_fsrdwr/.cvsignore, mimfs_fsrdwr/Makefile.am, mimfs_fssymlink/.cvsignore, mimfs_fstime/.cvsignore, mimfs_fstime/Makefile.am, mrfs_fserror/.cvsignore, mrfs_fserror/Makefile.am, mrfs_fslink/.cvsignore, mrfs_fspatheval/.cvsignore, mrfs_fspatheval/Makefile.am, mrfs_fspermission/.cvsignore, mrfs_fspermission/Makefile.am, mrfs_fsrdwr/.cvsignore, mrfs_fsrdwr/Makefile.am, mrfs_fssymlink/.cvsignore, mrfs_fstime/.cvsignore, mrfs_fstime/Makefile.am: New files.
  • Property mode set to 100644
File size: 8.3 KB
RevLine 
[a7c39d3]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 Exp $
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 dot or a single entry in dot-dot.
260   */
261
262  EXPECT_ERROR (ENOTEMPTY, rmdir, "..");
263  EXPECT_ERROR (ENOTEMPTY, rmdir, "tmp");
264
265
266  /*
267   * The path argument contains a last component that is dot.
268   */
269
270
271  EXPECT_ERROR (EINVAL, rmdir, ".");
272  EXPECT_ERROR (EINVAL, rmdir, "tmp/.");
273
274  /*
275   * A component of path does not name an existing file,
276   * or the path argument names a nonexistent directory or points to an empty string
277   */
278  EXPECT_ERROR (ENOENT, rmdir, "");
279  EXPECT_ERROR (ENOENT, rmdir, nonexistence);
280
281  EXPECT_ERROR (ENOENT, unlink, "");
282  EXPECT_ERROR (ENOENT, unlink, nonexistence);
283
284  /*
285   * component of path is not a directory.
286   */
287
288  EXPECT_ERROR (ENOTDIR, rmdir, "tmp/file");
289
290  EXPECT_ERROR (ENOTDIR, unlink, "tmp/file/dir");
291  /*
292   * Go back to parent directory
293   */
294  status = chdir ("..");
295  rtems_test_assert (status == 0);
296
297
298}
299
300void rdwr_error (void)
301{
302
303  int status;
304  int fd;
305  char *file01 = "name01";
306  char *databuf = "test";
307  char *readbuf[10];
308
309
310  mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
311  const char *wd = __func__;
312
313  /*
314   * Create a new directory and change the current directory to  this
315   */
316  status = mkdir (wd, mode);
317  rtems_test_assert (status == 0);
318  status = chdir (wd);
319  rtems_test_assert (status == 0);
320
321  fd = open (file01, O_WRONLY | O_CREAT, mode);
322
323  /*
324   * The fildes argument is not a valid file descriptor open for reading.
325   */
326
327  EXPECT_ERROR (EBADF, read, fd, readbuf, 10);
328  EXPECT_ERROR (EBADF, read, 100, readbuf, 10);
329
330  status = close (fd);
331  rtems_test_assert (status == 0);
332  /*
333   * The fildes argument is not a valid file descriptor open for writing.
334   */
335  fd = open (file01, O_RDONLY, mode);
336
337  EXPECT_ERROR (EBADF, write, fd, databuf, 10);
338  EXPECT_ERROR (EBADF, write, 100, readbuf, 10);
339
340  /*
341   * The whence argument is not a proper value,
342   * or the resulting file offset would be negative for a regular file,
343   * block special file, or directory.
344   */
345
346  EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_END);
347  EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_CUR);
348  EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_SET);
349
350  status = close (fd);
351  rtems_test_assert (status == 0);
352
353  EXPECT_ERROR (EBADF, lseek, fd, -100, SEEK_SET);
354  /*
355   * Go back to parent directory
356   */
357  status = chdir ("..");
358  rtems_test_assert (status == 0);
359
360}
361
362void test (void)
363{
364
365  puts ("\n\n*** ERROR TEST ***");
366  open_mkdir_error ();
367  rename_error ();
368  truncate_error ();
369  rmdir_unlink_error ();
370  rdwr_error ();
371  puts ("*** END OF ERROR TEST ***");
372}
Note: See TracBrowser for help on using the repository browser.