source: rtems/testsuites/fstests/fslink/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.7 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#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <unistd.h>
17#include <fcntl.h>
18#include <limits.h>
19#include <stdio.h>
20#include <unistd.h>
21#include <errno.h>
22#include <sys/stat.h>
23#include <time.h>
24#include <stdint.h>
25#include <math.h>
26
27#include "fstest.h"
28#include "pmacros.h"
29
30/*
31 * Test if the successful call works as expect
32 */
33void link_test01 (void)
34{
35  char *name0 = "t0";
36  char *name1 = "t1";
37  char *name2 = "t2";
38
39
40  int status;
41  int fd;
42
43  mode_t mode = 0644;
44  struct stat statbuf;
45
46
47  puts ("link creates hardlinks");
48  fd = creat (name0, mode);
49  status = close (fd);
50  rtems_test_assert (status == 0);
51
52  status = stat (name0, &statbuf);
53  rtems_test_assert (status == 0);
54  rtems_test_assert (statbuf.st_nlink == 1);
55
56  puts ("test if the stat is the same");
57  status = link (name0, name1);
58  rtems_test_assert (status == 0);
59
60  status = stat (name0, &statbuf);
61  rtems_test_assert (status == 0);
62
63  rtems_test_assert (S_ISREG (statbuf.st_mode));
64  rtems_test_assert (statbuf.st_nlink == 2);
65
66  status = stat (name1, &statbuf);
67  rtems_test_assert (status == 0);
68
69  rtems_test_assert (S_ISREG (statbuf.st_mode));
70  rtems_test_assert (statbuf.st_nlink == 2);
71
72  /*
73   * link the file and check the nlink
74   */
75  status = link (name1, name2);
76  rtems_test_assert (status == 0);
77
78  status = stat (name0, &statbuf);
79  rtems_test_assert (status == 0);
80
81  rtems_test_assert (S_ISREG (statbuf.st_mode));
82  rtems_test_assert (statbuf.st_nlink == 3);
83
84  status = stat (name1, &statbuf);
85  rtems_test_assert (status == 0);
86
87  rtems_test_assert (S_ISREG (statbuf.st_mode));
88  rtems_test_assert (statbuf.st_nlink == 3);
89
90  status = stat (name2, &statbuf);
91  rtems_test_assert (status == 0);
92
93  rtems_test_assert (S_ISREG (statbuf.st_mode));
94  rtems_test_assert (statbuf.st_nlink == 3);
95
96  /*
97   *  call chmod and chown and test.
98   */
99  puts ("chmod and chown");
100
101  chown (name1, 65534, 65533);
102
103  status = stat (name0, &statbuf);
104  rtems_test_assert (status == 0);
105
106  rtems_test_assert (S_ISREG (statbuf.st_mode));
107  rtems_test_assert (statbuf.st_nlink == 3);
108  rtems_test_assert (statbuf.st_uid = 65534);
109  rtems_test_assert (statbuf.st_gid = 65533);
110
111  status = stat (name1, &statbuf);
112  rtems_test_assert (status == 0);
113
114  rtems_test_assert (S_ISREG (statbuf.st_mode));
115  rtems_test_assert (statbuf.st_nlink == 3);
116  rtems_test_assert (statbuf.st_uid = 65534);
117  rtems_test_assert (statbuf.st_gid = 65533);
118
119  status = stat (name2, &statbuf);
120  rtems_test_assert (status == 0);
121
122  rtems_test_assert (S_ISREG (statbuf.st_mode));
123  rtems_test_assert (statbuf.st_nlink == 3);
124  rtems_test_assert (statbuf.st_uid = 65534);
125  rtems_test_assert (statbuf.st_gid = 65533);
126
127  /*
128   *
129   *  unlink then test if the nlink changes
130   */
131  puts ("unlink then stat the file ");
132
133  status = unlink (name0);
134  rtems_test_assert (status == 0);
135
136  status = stat (name0, &statbuf);
137  rtems_test_assert (status == -1);
138  rtems_test_assert (errno = ENOENT);
139
140  status = stat (name1, &statbuf);
141  rtems_test_assert (status == 0);
142  rtems_test_assert (S_ISREG (statbuf.st_mode));
143  rtems_test_assert (statbuf.st_nlink == 2);
144
145  status = stat (name2, &statbuf);
146  rtems_test_assert (status == 0);
147  rtems_test_assert (S_ISREG (statbuf.st_mode));
148  rtems_test_assert (statbuf.st_nlink == 2);
149
150  status = unlink (name1);
151  rtems_test_assert (status == 0);
152
153  status = unlink (name2);
154  rtems_test_assert (status == 0);
155
156}
157
158void test (void)
159{
160  puts ("\n\n*** LINK TEST ***");
161  link_test01 ();
162  puts ("*** END OF LINK TEST ***");
163}
Note: See TracBrowser for help on using the repository browser.