Commit | Line | Data |
8d063cd8 |
1 | #!./perl |
2 | |
79072805 |
3 | # $RCSfile: fs.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:28 $ |
8d063cd8 |
4 | |
ea368a7c |
5 | BEGIN { |
6 | chdir 't' if -d 't'; |
20822f61 |
7 | @INC = '../lib'; |
ea368a7c |
8 | } |
9 | |
10 | use Config; |
11 | |
80252599 |
12 | $Is_Dosish = ($^O eq 'MSWin32' or $^O eq 'dos' or |
d493b042 |
13 | $^O eq 'os2' or $^O eq 'mint'); |
39e571d4 |
14 | |
6b980173 |
15 | if (defined &Win32::IsWinNT && Win32::IsWinNT()) { |
16 | $Is_Dosish = '' if Win32::FsType() eq 'NTFS'; |
17 | } |
18 | |
65cb15a1 |
19 | print "1..29\n"; |
8d063cd8 |
20 | |
68dc0745 |
21 | $wd = (($^O eq 'MSWin32') ? `cd` : `pwd`); |
378cc40b |
22 | chop($wd); |
23 | |
1d825fcc |
24 | if ($^O eq 'MSWin32') { `rmdir /s /q tmp 2>nul`; `mkdir tmp`; } |
68dc0745 |
25 | else { `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`; } |
378cc40b |
26 | chdir './tmp'; |
b8440792 |
27 | `/bin/rm -rf a b c x` if -x '/bin/rm'; |
8d063cd8 |
28 | |
29 | umask(022); |
30 | |
80252599 |
31 | if ($^O eq 'MSWin32') { print "ok 1 # skipped: bogus umask()\n"; } |
32 | elsif ((umask(0)&0777) == 022) {print "ok 1\n";} else {print "not ok 1\n";} |
8d063cd8 |
33 | open(fh,'>x') || die "Can't create x"; |
34 | close(fh); |
35 | open(fh,'>a') || die "Can't create a"; |
36 | close(fh); |
37 | |
a245ea2d |
38 | if ($Is_Dosish) {print "ok 2 # skipped: no link\n";} |
39 | elsif (eval {link('a','b')}) {print "ok 2\n";} |
40 | else {print "not ok 2\n";} |
8d063cd8 |
41 | |
a245ea2d |
42 | if ($Is_Dosish) {print "ok 3 # skipped: no link\n";} |
43 | elsif (eval {link('b','c')}) {print "ok 3\n";} |
44 | else {print "not ok 3\n";} |
8d063cd8 |
45 | |
46 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
47 | $blksize,$blocks) = stat('c'); |
48 | |
a245ea2d |
49 | if ($Config{dont_use_nlink} || $Is_Dosish) |
50 | {print "ok 4 # skipped: no link\n";} |
51 | elsif ($nlink == 3) |
52 | {print "ok 4\n";} |
53 | else {print "not ok 4\n";} |
ea368a7c |
54 | |
a245ea2d |
55 | if ($^O eq 'amigaos' || $Is_Dosish) |
56 | {print "ok 5 # skipped: no link\n";} |
57 | elsif (($mode & 0777) == 0666) |
58 | {print "ok 5\n";} |
59 | else {print "not ok 5\n";} |
8d063cd8 |
60 | |
6b980173 |
61 | $newmode = $^O eq 'MSWin32' ? 0444 : 0777; |
62 | if ((chmod $newmode,'a') == 1) {print "ok 6\n";} else {print "not ok 6\n";} |
8d063cd8 |
63 | |
64 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
65 | $blksize,$blocks) = stat('c'); |
a245ea2d |
66 | if ($Is_Dosish) {print "ok 7 # skipped: no link\n";} |
6b980173 |
67 | elsif (($mode & 0777) == $newmode) {print "ok 7\n";} |
a245ea2d |
68 | else {print "not ok 7\n";} |
8d063cd8 |
69 | |
6b980173 |
70 | $newmode = 0700; |
71 | if ($^O eq 'MSWin32') { |
72 | chmod 0444, 'x'; |
73 | $newmode = 0666; |
74 | } |
75 | |
a245ea2d |
76 | if ($Is_Dosish) {print "ok 8 # skipped: no link\n";} |
6b980173 |
77 | elsif ((chmod $newmode,'c','x') == 2) {print "ok 8\n";} |
a245ea2d |
78 | else {print "not ok 8\n";} |
8d063cd8 |
79 | |
80 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
81 | $blksize,$blocks) = stat('c'); |
a245ea2d |
82 | if ($Is_Dosish) {print "ok 9 # skipped: no link\n";} |
6b980173 |
83 | elsif (($mode & 0777) == $newmode) {print "ok 9\n";} |
a245ea2d |
84 | else {print "not ok 9\n";} |
85 | |
8d063cd8 |
86 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
87 | $blksize,$blocks) = stat('x'); |
a245ea2d |
88 | if ($Is_Dosish) {print "ok 10 # skipped: no link\n";} |
6b980173 |
89 | elsif (($mode & 0777) == $newmode) {print "ok 10\n";} |
a245ea2d |
90 | else {print "not ok 10\n";} |
8d063cd8 |
91 | |
a245ea2d |
92 | if ($Is_Dosish) {print "ok 11 # skipped: no link\n"; unlink 'b','x'; } |
93 | elsif ((unlink 'b','x') == 2) {print "ok 11\n";} |
94 | else {print "not ok 11\n";} |
8d063cd8 |
95 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
96 | $blksize,$blocks) = stat('b'); |
97 | if ($ino == 0) {print "ok 12\n";} else {print "not ok 12\n";} |
98 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
99 | $blksize,$blocks) = stat('x'); |
100 | if ($ino == 0) {print "ok 13\n";} else {print "not ok 13\n";} |
101 | |
102 | if (rename('a','b')) {print "ok 14\n";} else {print "not ok 14\n";} |
103 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
104 | $blksize,$blocks) = stat('a'); |
105 | if ($ino == 0) {print "ok 15\n";} else {print "not ok 15\n";} |
a245ea2d |
106 | $delta = $Is_Dosish ? 2 : 1; # Granularity of time on the filesystem |
1d825fcc |
107 | chmod 0777, 'b'; |
a245ea2d |
108 | $foo = (utime 500000000,500000000 + $delta,'b'); |
378cc40b |
109 | if ($foo == 1) {print "ok 16\n";} else {print "not ok 16 $foo\n";} |
8d063cd8 |
110 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
111 | $blksize,$blocks) = stat('b'); |
80252599 |
112 | if ($^O eq 'MSWin32') { print "ok 17 # skipped: bogus (stat)[1]\n"; } |
113 | elsif ($ino) {print "ok 17\n";} else {print "not ok 17\n";} |
114 | if ($wd =~ m#/afs/# || $^O eq 'amigaos' || $^O eq 'dos' || $^O eq 'MSWin32') |
a245ea2d |
115 | {print "ok 18 # skipped: granularity of the filetime\n";} |
116 | elsif ($atime == 500000000 && $mtime == 500000000 + $delta) |
6eb13c3b |
117 | {print "ok 18\n";} |
da93fe49 |
118 | elsif ($^O =~ /\blinux\b/i) { |
119 | # Maybe stat() cannot get the correct atime, as happens via NFS on linux? |
120 | $foo = (utime 400000000,500000000 + 2*$delta,'b'); |
121 | my ($new_atime, $new_mtime) = (stat('b'))[8,9]; |
122 | if ($new_atime == $atime && $new_mtime - $mtime == $delta) |
123 | {print "ok 18 # accounted for possible NFS/glibc2.2 bug on linux\n";} |
124 | else |
125 | {print "not ok 18 $atime/$new_atime $mtime/$new_mtime\n";} |
126 | } else |
6eb13c3b |
127 | {print "not ok 18 $atime $mtime\n";} |
8d063cd8 |
128 | |
378cc40b |
129 | if ((unlink 'b') == 1) {print "ok 19\n";} else {print "not ok 19\n";} |
8d063cd8 |
130 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
131 | $blksize,$blocks) = stat('b'); |
378cc40b |
132 | if ($ino == 0) {print "ok 20\n";} else {print "not ok 20\n";} |
133 | unlink 'c'; |
134 | |
135 | chdir $wd || die "Can't cd back to $wd"; |
136 | |
8d063cd8 |
137 | unlink 'c'; |
68dc0745 |
138 | if ($^O ne 'MSWin32' and `ls -l perl 2>/dev/null` =~ /^l.*->/) { |
139 | # we have symbolic links |
4ba7095c |
140 | system("cp TEST TEST$$"); |
141 | # we have to copy because e.g. GNU grep gets huffy if we have |
142 | # a symlink forest to another disk (it complains about too many |
143 | # levels of symbolic links, even if we have only two) |
144 | if (symlink("TEST$$","c")) {print "ok 21\n";} else {print "not ok 21\n";} |
145 | $foo = `grep perl c 2>&1`; |
378cc40b |
146 | if ($foo) {print "ok 22\n";} else {print "not ok 22\n";} |
44a8e56a |
147 | unlink 'c'; |
4ba7095c |
148 | unlink("TEST$$"); |
378cc40b |
149 | } |
150 | else { |
151 | print "ok 21\nok 22\n"; |
152 | } |
f783569b |
153 | |
154 | # truncate (may not be implemented everywhere) |
155 | unlink "Iofs.tmp"; |
156 | `echo helloworld > Iofs.tmp`; |
157 | eval { truncate "Iofs.tmp", 5; }; |
62b86938 |
158 | if ($@) { |
159 | if ($@ =~ /not implemented/) { |
160 | print "# truncate not implemented -- skipping tests 23 through 26\n"; |
161 | for (23 .. 26) { |
162 | print "ok $_ # Skip: no truncate\n"; |
163 | } |
164 | } else { |
165 | warn "io/fs before test 23: truncate dies with \$\@[$@]"; |
f783569b |
166 | } |
167 | } |
168 | else { |
62b86938 |
169 | if (-s "Iofs.tmp" == 5) { |
170 | print "ok 23\n"; |
171 | } else { |
172 | my $s = -s "Iofs.tmp"; |
173 | printf "# -s Iofs.tmp: %s\n", defined($s) ? $s : "UNDEFINED"; |
174 | print "not ok 23\n"; |
175 | } |
f783569b |
176 | truncate "Iofs.tmp", 0; |
177 | if (-z "Iofs.tmp") {print "ok 24\n"} else {print "not ok 24\n"} |
f783569b |
178 | open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp"; |
2f3b6ae4 |
179 | binmode FH; |
1bcfde30 |
180 | { select FH; $| = 1; select STDOUT } |
bb53490d |
181 | { |
182 | use strict; |
2f3b6ae4 |
183 | print FH "x\n" x 200; |
184 | truncate(FH, 200) or die "Can't truncate FH: $!"; |
bb53490d |
185 | } |
ed344e4f |
186 | if ($^O eq 'dos' |
187 | # Not needed on HPFS, but needed on HPFS386 ?! |
188 | or $^O eq 'os2') |
189 | { |
39e571d4 |
190 | close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; |
191 | } |
2f3b6ae4 |
192 | if (-s "Iofs.tmp" == 200) {print "ok 25\n"} else {print "not ok 25\n"} |
f783569b |
193 | truncate FH, 0; |
ed344e4f |
194 | if ($^O eq 'dos' |
195 | # Not needed on HPFS, but needed on HPFS386 ?! |
196 | or $^O eq 'os2') |
197 | { |
39e571d4 |
198 | close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; |
199 | } |
f783569b |
200 | if (-z "Iofs.tmp") {print "ok 26\n"} else {print "not ok 26\n"} |
201 | close FH; |
202 | } |
80252599 |
203 | |
65cb15a1 |
204 | # check if rename() can be used to just change case of filename |
205 | chdir './tmp'; |
206 | open(fh,'>x') || die "Can't create x"; |
207 | close(fh); |
208 | rename('x', 'X'); |
209 | print 'not ' unless -e 'X'; |
210 | print "ok 27\n"; |
211 | unlink 'X'; |
212 | chdir $wd || die "Can't cd back to $wd"; |
213 | |
80252599 |
214 | # check if rename() works on directories |
215 | rename 'tmp', 'tmp1' or print "not "; |
80252599 |
216 | print "ok 28\n"; |
65cb15a1 |
217 | -d 'tmp1' or print "not "; |
218 | print "ok 29\n"; |
80252599 |
219 | |
220 | END { rmdir 'tmp1'; unlink "Iofs.tmp"; } |