source: rtems/testsuites/fstests/fssymlink/test.c @ 858e013f

4.115
Last change on this file since 858e013f was 858e013f, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 1, 2011 at 8:54:15 PM

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

  • Makefile.am, configure.ac, fslink/fslink.doc, fslink/test.c, fssymlink/test.c, imfs_fslink/Makefile.am, imfs_fssymlink/Makefile.am, imfs_support/fs_config.h, imfs_support/fs_support.c, mdosfs_support/fs_config.h, mdosfs_support/fs_support.c, mimfs_fslink/Makefile.am, mimfs_fssymlink/Makefile.am, mimfs_support/fs_config.h, mimfs_support/fs_support.c, mrfs_fslink/Makefile.am, mrfs_fssymlink/Makefile.am, 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: Submit correct tarball of current work.
  • fs01/init.c, fsfchx/fsfchx.doc, fsfchx/init.c, fsfile01/fsfile01.doc, fsfile01/test.c, fsfile01/test_cat.c, fsfile01/test_extend.c, fsfile01/test_write.c, fsfile02/fsfile02.doc, fsfile02/init.c, fsfstest/fs-test.c, fsfstest/fsfstest.doc, fsimfs01/fsimfs01.doc, fsimfs01/init.c, fsimfs02/fsimfs02.doc, fsimfs02/init.c, fsmkdir/fsmkdir.doc, fsmkdir/test.c, fsopen/fsopen.doc, fsopen/test.c, fsrdwrv/fsrdwrv.doc, fsrdwrv/test.c, fsreaddir/fsreaddir.doc, fsreaddir/test.c, fsrename/fsrename.doc, fsrename/test.c, fsrmdir/test.c, fsrwfile/fsrwfile.doc, fsrwfile/init.c, fsstat/fsstat.doc, fsstat/test.c, fstruncate/fstruncate.doc, fstruncate/test.c, imfs_fs01/.cvsignore, imfs_fs01/Makefile.am, imfs_fs01/imfs_fs01.scn, imfs_fsfchx/.cvsignore, imfs_fsfchx/Makefile.am, imfs_fsfile01/.cvsignore, imfs_fsfile01/Makefile.am, imfs_fsfile02/.cvsignore, imfs_fsfile02/Makefile.am, imfs_fsfstest/.cvsignore, imfs_fsfstest/Makefile.am, imfs_fsimfs01/.cvsignore, imfs_fsimfs01/Makefile.am, imfs_fsimfs02/.cvsignore, imfs_fsimfs02/Makefile.am, imfs_fslink/.cvsignore, imfs_fsmkdir/.cvsignore, imfs_fsmkdir/Makefile.am, imfs_fsopen/.cvsignore, imfs_fsopen/Makefile.am, imfs_fsrdwrv/.cvsignore, imfs_fsrdwrv/Makefile.am, imfs_fsreaddir/.cvsignore, imfs_fsreaddir/Makefile.am, imfs_fsrename/.cvsignore, imfs_fsrename/Makefile.am, imfs_fsrmdir/.cvsignore, imfs_fsrmdir/Makefile.am, imfs_fsrwfile/.cvsignore, imfs_fsrwfile/Makefile.am, imfs_fsstat/.cvsignore, imfs_fsstat/Makefile.am, imfs_fssymlink/.cvsignore, imfs_fstruncate/.cvsignore, imfs_fstruncate/Makefile.am, mdosfs_fsfchx/.cvsignore, mdosfs_fsfchx/Makefile.am, mdosfs_fsfile01/.cvsignore, mdosfs_fsfile01/Makefile.am, mdosfs_fsfile02/.cvsignore, mdosfs_fsfile02/Makefile.am, mdosfs_fsfstest/.cvsignore, mdosfs_fsfstest/Makefile.am, mdosfs_fsimfs01/.cvsignore, mdosfs_fsimfs01/Makefile.am, mdosfs_fsimfs02/.cvsignore, mdosfs_fsimfs02/Makefile.am, mdosfs_fslink/.cvsignore, mdosfs_fslink/Makefile.am, mdosfs_fsmkdir/.cvsignore, mdosfs_fsmkdir/Makefile.am, mdosfs_fsopen/.cvsignore, mdosfs_fsopen/Makefile.am, mdosfs_fsrdwrv/.cvsignore, mdosfs_fsrdwrv/Makefile.am, mdosfs_fsreaddir/.cvsignore, mdosfs_fsreaddir/Makefile.am, mdosfs_fsrename/.cvsignore, mdosfs_fsrename/Makefile.am, mdosfs_fsrmdir/.cvsignore, mdosfs_fsrmdir/Makefile.am, mdosfs_fsrwfile/.cvsignore, mdosfs_fsrwfile/Makefile.am, mdosfs_fsstat/.cvsignore, mdosfs_fsstat/Makefile.am, mdosfs_fssymlink/.cvsignore, mdosfs_fssymlink/Makefile.am, mdosfs_fstruncate/.cvsignore, mdosfs_fstruncate/Makefile.am, mimfs_fs01/.cvsignore, mimfs_fs01/Makefile.am, mimfs_fs01/mimfs_fs01.scn, mimfs_fsfchx/.cvsignore, mimfs_fsfchx/Makefile.am, mimfs_fsfile01/.cvsignore, mimfs_fsfile01/Makefile.am, mimfs_fsfile02/.cvsignore, mimfs_fsfile02/Makefile.am, mimfs_fsfstest/.cvsignore, mimfs_fsfstest/Makefile.am, mimfs_fsimfs01/.cvsignore, mimfs_fsimfs01/Makefile.am, mimfs_fsimfs02/.cvsignore, mimfs_fsimfs02/Makefile.am, mimfs_fslink/.cvsignore, mimfs_fsmkdir/.cvsignore, mimfs_fsmkdir/Makefile.am, mimfs_fsopen/.cvsignore, mimfs_fsopen/Makefile.am, mimfs_fsrdwrv/.cvsignore, mimfs_fsrdwrv/Makefile.am, mimfs_fsreaddir/.cvsignore, mimfs_fsreaddir/Makefile.am, mimfs_fsrename/.cvsignore, mimfs_fsrename/Makefile.am, mimfs_fsrmdir/.cvsignore, mimfs_fsrmdir/Makefile.am, mimfs_fsrwfile/.cvsignore, mimfs_fsrwfile/Makefile.am, mimfs_fsstat/.cvsignore, mimfs_fsstat/Makefile.am, mimfs_fssymlink/.cvsignore, mimfs_fstruncate/.cvsignore, mimfs_fstruncate/Makefile.am, mrfs_fsfchx/.cvsignore, mrfs_fsfchx/Makefile.am, mrfs_fsfile01/.cvsignore, mrfs_fsfile01/Makefile.am, mrfs_fsfile02/.cvsignore, mrfs_fsfile02/Makefile.am, mrfs_fsfstest/.cvsignore, mrfs_fsfstest/Makefile.am, mrfs_fsimfs01/.cvsignore, mrfs_fsimfs01/Makefile.am, mrfs_fsimfs02/.cvsignore, mrfs_fsimfs02/Makefile.am, mrfs_fslink/.cvsignore, mrfs_fsmkdir/.cvsignore, mrfs_fsmkdir/Makefile.am, mrfs_fsopen/.cvsignore, mrfs_fsopen/Makefile.am, mrfs_fsrdwrv/.cvsignore, mrfs_fsrdwrv/Makefile.am, mrfs_fsreaddir/.cvsignore, mrfs_fsreaddir/Makefile.am, mrfs_fsrename/.cvsignore, mrfs_fsrename/Makefile.am, mrfs_fsrmdir/.cvsignore, mrfs_fsrmdir/Makefile.am, mrfs_fsrwfile/.cvsignore, mrfs_fsrwfile/Makefile.am, mrfs_fsstat/.cvsignore, mrfs_fsstat/Makefile.am, mrfs_fssymlink/.cvsignore, mrfs_fstruncate/.cvsignore, mrfs_fstruncate/Makefile.am: Removed.
  • 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 Exp $
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.