source: rtems/testsuites/fstests/fssymlink/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: 3.8 KB
Line 
1
2/*
3 *  COPYRIGHT (c) 1989-2011.
4 *  On-Line Applications Research Corporation (OAR).
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *  http://www.rtems.com/license/LICENSE.
9 *
10 *  $Id$
11 */
12
13#include <sys/stat.h>
14#include <fcntl.h>
15#include <errno.h>
16#include <stdio.h>
17#include <stdint.h>
18#include <unistd.h>
19#include <stdlib.h>
20#include <string.h>
21#include <unistd.h>
22#include <dirent.h>
23
24#include "fstest.h"
25
26/*
27 * Test the function of symlink
28 */
29
30void symlink_test01(void )
31{
32  int   fd;
33  char* file01="file";
34  char* symlink_file01="symlink";
35  char name[20];
36  int   status;
37  struct stat statbuf;
38  size_t   len=strlen(file01);
39  size_t   name_len;
40
41
42  printf("Create a file named %s\n",file01);
43  fd=creat(file01,0777);
44  status=close(fd);
45  rtems_test_assert(status==0);
46
47  printf("Create a symlink named %s to %s\n",symlink_file01,file01);
48  status=symlink(file01,symlink_file01);
49  rtems_test_assert(status==0);
50
51  status=stat(file01,&statbuf);
52  rtems_test_assert(status==0);
53  rtems_test_assert(S_ISREG(statbuf.st_mode));
54  rtems_test_assert(0==statbuf.st_size);
55
56  status=lstat(symlink_file01,&statbuf);
57  rtems_test_assert(status==0);
58  rtems_test_assert(S_ISLNK(statbuf.st_mode));
59  rtems_test_assert(len==statbuf.st_size);
60
61
62  puts("call readlink ");
63  name_len=readlink(symlink_file01,name,sizeof(name)-1);
64  rtems_test_assert(name_len!=-1);
65  name[name_len]='\0';
66  rtems_test_assert(!strncmp(name,file01,name_len));
67  puts(name);
68
69  puts("Unlink the file");
70
71  status=unlink(file01);
72  rtems_test_assert(status==0);
73
74  status=lstat(symlink_file01,&statbuf);
75  rtems_test_assert(status==0);
76  rtems_test_assert(S_ISLNK(statbuf.st_mode));
77  rtems_test_assert(len==statbuf.st_size);
78
79  puts("call readlink ");
80  name_len=readlink(symlink_file01,name,sizeof(name)-1);
81  rtems_test_assert(name_len!=-1);
82  name[name_len]='\0';
83  rtems_test_assert(!strncmp(name,file01,name_len));
84  status=unlink(symlink_file01);
85  rtems_test_assert(status==0);
86
87  printf("Create a dir named %s\n",file01);
88  status=mkdir (file01,0777);
89
90  printf("Create a symlink named %s to %s\n",symlink_file01,file01);
91  status=symlink(file01,symlink_file01);
92  rtems_test_assert(status==0);
93
94  status=lstat(symlink_file01,&statbuf);
95  rtems_test_assert(status==0);
96  rtems_test_assert(S_ISLNK(statbuf.st_mode));
97  rtems_test_assert(len==statbuf.st_size);
98
99
100  puts("call readlink ");
101  name_len=readlink(symlink_file01,name,sizeof(name)-1);
102  rtems_test_assert(name_len!=-1);
103  name[name_len]='\0';
104  rtems_test_assert(!strncmp(name,file01,name_len));
105
106  name_len=readlink(symlink_file01,name,3);
107  rtems_test_assert(name_len!=-1);
108  name[name_len]='\0';
109  rtems_test_assert(!strncmp(name,file01,name_len));
110
111  puts("rmdir the dir");
112  status=rmdir(file01);
113  rtems_test_assert(status==0);
114
115  status=lstat(symlink_file01,&statbuf);
116  rtems_test_assert(status==0);
117  rtems_test_assert(S_ISLNK(statbuf.st_mode));
118
119  status=unlink(symlink_file01);
120  rtems_test_assert(status==0);
121
122}
123/*
124 *  symlink loop error test
125 */
126void symlink_loop_error_test(void )
127{
128  char* file01="file01";
129  char* file02="file02";
130
131  char* file04="file04";
132  char* path="file01/t";
133
134  int   status;
135
136  mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
137
138  puts("symlink loop erro test");
139
140  status=symlink(file01,file02);
141  rtems_test_assert(status==0);
142  status=symlink(file02,file01);
143  rtems_test_assert(status==0);
144
145
146  EXPECT_ERROR(ELOOP,creat,path,mode);
147  EXPECT_ERROR(ELOOP,open,path,O_CREAT|O_WRONLY,mode);
148  EXPECT_ERROR(ELOOP,truncate,path,0);
149  EXPECT_ERROR(ELOOP,rename,path,file04);
150  EXPECT_ERROR(ELOOP,unlink,path);
151  EXPECT_ERROR(ELOOP,mkdir,path,mode);
152  EXPECT_ERROR(ELOOP,rmdir,path);
153}
154
155void test(void )
156{
157
158  puts( "\n\n*** SYMLINK TEST ***" );
159  symlink_test01();
160  symlink_loop_error_test();
161  puts( "*** END OF SYMLINK TEST ***" );
162
163}
164
Note: See TracBrowser for help on using the repository browser.