source: rtems/testsuites/fstests/fssymlink/test.c @ 32448524

4.115
Last change on this file since 32448524 was 32448524, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/30/11 at 03:07:21

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

  • fserror/test.c, fslink/test.c, fspatheval/test.c, fspermission/test.c, fsrdwr/init.c, fssymlink/test.c, fstime/test.c, support/fstest_support.c, support/ramdisk_support.c: Explicitly include "pmacros.h".
  • support/fstest.h: Don't include "pmacros.h".
  • Property mode set to 100644
File size: 3.9 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#ifdef HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <sys/stat.h>
18#include <fcntl.h>
19#include <errno.h>
20#include <stdio.h>
21#include <stdint.h>
22#include <unistd.h>
23#include <stdlib.h>
24#include <string.h>
25#include <unistd.h>
26#include <dirent.h>
27
28#include "fstest.h"
29#include "pmacros.h"
30
31/*
32 * Test the function of symlink
33 */
34
35void symlink_test01(void )
36{
37  int   fd;
38  char* file01="file";
39  char* symlink_file01="symlink";
40  char name[20];
41  int   status;
42  struct stat statbuf;
43  size_t   len=strlen(file01);
44  size_t   name_len;
45
46
47  printf("Create a file named %s\n",file01);
48  fd=creat(file01,0777);
49  status=close(fd);
50  rtems_test_assert(status==0);
51
52  printf("Create a symlink named %s to %s\n",symlink_file01,file01);
53  status=symlink(file01,symlink_file01);
54  rtems_test_assert(status==0);
55
56  status=stat(file01,&statbuf);
57  rtems_test_assert(status==0);
58  rtems_test_assert(S_ISREG(statbuf.st_mode));
59  rtems_test_assert(0==statbuf.st_size);
60
61  status=lstat(symlink_file01,&statbuf);
62  rtems_test_assert(status==0);
63  rtems_test_assert(S_ISLNK(statbuf.st_mode));
64  rtems_test_assert(len==statbuf.st_size);
65
66
67  puts("call readlink ");
68  name_len=readlink(symlink_file01,name,sizeof(name)-1);
69  rtems_test_assert(name_len!=-1);
70  name[name_len]='\0';
71  rtems_test_assert(!strncmp(name,file01,name_len));
72  puts(name);
73
74  puts("Unlink the file");
75
76  status=unlink(file01);
77  rtems_test_assert(status==0);
78
79  status=lstat(symlink_file01,&statbuf);
80  rtems_test_assert(status==0);
81  rtems_test_assert(S_ISLNK(statbuf.st_mode));
82  rtems_test_assert(len==statbuf.st_size);
83
84  puts("call readlink ");
85  name_len=readlink(symlink_file01,name,sizeof(name)-1);
86  rtems_test_assert(name_len!=-1);
87  name[name_len]='\0';
88  rtems_test_assert(!strncmp(name,file01,name_len));
89  status=unlink(symlink_file01);
90  rtems_test_assert(status==0);
91
92  printf("Create a dir named %s\n",file01);
93  status=mkdir (file01,0777);
94
95  printf("Create a symlink named %s to %s\n",symlink_file01,file01);
96  status=symlink(file01,symlink_file01);
97  rtems_test_assert(status==0);
98
99  status=lstat(symlink_file01,&statbuf);
100  rtems_test_assert(status==0);
101  rtems_test_assert(S_ISLNK(statbuf.st_mode));
102  rtems_test_assert(len==statbuf.st_size);
103
104
105  puts("call readlink ");
106  name_len=readlink(symlink_file01,name,sizeof(name)-1);
107  rtems_test_assert(name_len!=-1);
108  name[name_len]='\0';
109  rtems_test_assert(!strncmp(name,file01,name_len));
110
111  name_len=readlink(symlink_file01,name,3);
112  rtems_test_assert(name_len!=-1);
113  name[name_len]='\0';
114  rtems_test_assert(!strncmp(name,file01,name_len));
115
116  puts("rmdir the dir");
117  status=rmdir(file01);
118  rtems_test_assert(status==0);
119
120  status=lstat(symlink_file01,&statbuf);
121  rtems_test_assert(status==0);
122  rtems_test_assert(S_ISLNK(statbuf.st_mode));
123
124  status=unlink(symlink_file01);
125  rtems_test_assert(status==0);
126
127}
128/*
129 *  symlink loop error test
130 */
131void symlink_loop_error_test(void )
132{
133  char* file01="file01";
134  char* file02="file02";
135
136  char* file04="file04";
137  char* path="file01/t";
138
139  int   status;
140
141  mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
142
143  puts("symlink loop erro test");
144
145  status=symlink(file01,file02);
146  rtems_test_assert(status==0);
147  status=symlink(file02,file01);
148  rtems_test_assert(status==0);
149
150
151  EXPECT_ERROR(ELOOP,creat,path,mode);
152  EXPECT_ERROR(ELOOP,open,path,O_CREAT|O_WRONLY,mode);
153  EXPECT_ERROR(ELOOP,truncate,path,0);
154  EXPECT_ERROR(ELOOP,rename,path,file04);
155  EXPECT_ERROR(ELOOP,unlink,path);
156  EXPECT_ERROR(ELOOP,mkdir,path,mode);
157  EXPECT_ERROR(ELOOP,rmdir,path);
158}
159
160void test(void )
161{
162
163  puts( "\n\n*** SYMLINK TEST ***" );
164  symlink_test01();
165  symlink_loop_error_test();
166  puts( "*** END OF SYMLINK TEST ***" );
167
168}
169
Note: See TracBrowser for help on using the repository browser.