introduce $^U, a global bit to indicate whether system
[p5sagit/p5-mst-13.2.git] / t / op / lfs.t
CommitLineData
ea2b5ef6 1# NOTE: this file tests how large files (>2GB) work with perlio (stdio/sfio).
2# sysopen(), sysseek(), syswrite(), sysread() are tested in t/lib/syslfs.t.
3# If you modify/add tests here, remember to update also t/lib/syslfs.t.
4
817e2dcb 5BEGIN {
ea2b5ef6 6 chdir 't' if -d 't';
7 unshift @INC, '../lib';
9f8fdb7d 8 # Don't bother if there are no quad offsets.
9 require Config; import Config;
10 if ($Config{lseeksize} < 8) {
64215065 11 print "1..0\n# no 64-bit file offsets\n";
48ea9154 12 exit(0);
9f8fdb7d 13 }
817e2dcb 14}
15
6da84e39 16sub bye {
17 close(BIG);
18 unlink "big";
19 exit(0);
20}
21
fcbfa962 22sub explain {
2d4389e4 23 print <<EOM;
fcbfa962 24#
25# If the lfs (large file support: large meaning larger than two gigabytes)
eed7fde4 26# tests are skipped or fail, it may mean either that your process
27# (or process group) is not allowed to write large files (resource
28# limits) or that the file system you are running the tests on doesn't
29# let your user/group have large files (quota) or the filesystem simply
30# doesn't support large files. You may even need to reconfigure your kernel.
31# (This is all very operating system and site-dependent.)
fcbfa962 32#
33# Perl may still be able to support large files, once you have
eed7fde4 34# such a process, enough quota, and such a (file) system.
fcbfa962 35#
36EOM
37}
38
e0a10278 39print "# checking whether we have sparse files...\n";
40
05f8a9f5 41# Known have-nots.
817e2dcb 42if ($^O eq 'win32' || $^O eq 'vms') {
e0a10278 43 print "1..0\n# no sparse files (because this is $^O) \n";
6da84e39 44 bye();
45}
46
b18f8161 47# Known haves that have problems running this test
48# (for example because they do not support sparse files, like UNICOS)
49if ($^O eq 'unicos') {
e0a10278 50 print "1..0\n# large files known to work but unable to test them here ($^O)\n";
b18f8161 51 bye();
52}
53
e0a10278 54# Then try to heuristically deduce whether we have sparse files.
05f8a9f5 55
64215065 56# Let's not depend on Fcntl or any other extension.
57
ea2b5ef6 58my ($SEEK_SET, $SEEK_CUR, $SEEK_END) = (0, 1, 2);
6da84e39 59
ea2b5ef6 60# We'll start off by creating a one megabyte file which has
05f8a9f5 61# only three "true" bytes. If we have sparseness, we should
62# consume less blocks than one megabyte (assuming nobody has
63# one megabyte blocks...)
817e2dcb 64
ea2b5ef6 65open(BIG, ">big") or do { warn "open failed: $!\n"; bye };
6da84e39 66binmode BIG;
ea2b5ef6 67seek(BIG, 1_000_000, $SEEK_SET);
6da84e39 68print BIG "big";
817e2dcb 69close(BIG);
70
71my @s;
72
73@s = stat("big");
74
ea2b5ef6 75print "# @s\n";
76
2ef4205b 77my $BLOCKSIZE = $s[11] || 512;
5cec1e3b 78
6da84e39 79unless (@s == 13 &&
ea2b5ef6 80 $s[7] == 1_000_003 &&
6da84e39 81 defined $s[12] &&
5cec1e3b 82 $BLOCKSIZE * $s[12] < 1_000_003) {
ea2b5ef6 83 print "1..0\n# no sparse files?\n";
6da84e39 84 bye();
817e2dcb 85}
86
e0a10278 87print "# we seem to have sparse files...\n";
88
817e2dcb 89# By now we better be sure that we do have sparse files:
90# if we are not, the following will hog 5 gigabytes of disk. Ooops.
91
eed7fde4 92$ENV{LC_ALL} = "C";
93
ea2b5ef6 94open(BIG, ">big") or do { warn "open failed: $!\n"; bye };
817e2dcb 95binmode BIG;
e0a10278 96unless (seek(BIG, 5_000_000_000, $SEEK_SET)) {
97 print "1..0\n# seeking past 2GB failed: $!\n";
98 explain();
99 bye();
100}
eed7fde4 101
fcbfa962 102# Either the print or (more likely, thanks to buffering) the close will
103# fail if there are are filesize limitations (process or fs).
104my $print = print BIG "big";
e0a10278 105print "# print failed: $!\n" unless $print;
106my $close = close BIG;
107print "# close failed: $!\n" unless $close;
fcbfa962 108unless ($print && $close) {
b948423f 109 if ($! =~/too large/i) {
110 print "1..0\n# writing past 2GB failed: process limits?\n";
111 } elsif ($! =~ /quota/i) {
112 print "1..0\n# filesystem quota limits?\n";
fcbfa962 113 }
56d29690 114 explain();
fcbfa962 115 bye();
116}
817e2dcb 117
118@s = stat("big");
119
ea2b5ef6 120print "# @s\n";
121
ae178db1 122unless ($s[7] == 5_000_000_003) {
123 print "1..0\n# not configured to use large files?\n";
124 explain();
125 bye();
126}
127
05f8a9f5 128sub fail () {
64215065 129 print "not ";
05f8a9f5 130 $fail++;
131}
132
77166d51 133print "1..17\n";
fcbfa962 134
135my $fail = 0;
136
64215065 137fail unless $s[7] == 5_000_000_003; # exercizes pp_stat
817e2dcb 138print "ok 1\n";
139
64215065 140fail unless -s "big" == 5_000_000_003; # exercizes pp_ftsize
817e2dcb 141print "ok 2\n";
142
77166d51 143fail unless -e "big";
144print "ok 3\n";
145
146fail unless -f "big";
147print "ok 4\n";
148
ea2b5ef6 149open(BIG, "big") or do { warn "open failed: $!\n"; bye };
817e2dcb 150binmode BIG;
151
77166d51 152fail unless seek(BIG, 4_500_000_000, $SEEK_SET);
153print "ok 5\n";
817e2dcb 154
05f8a9f5 155fail unless tell(BIG) == 4_500_000_000;
77166d51 156print "ok 6\n";
817e2dcb 157
77166d51 158fail unless seek(BIG, 1, $SEEK_CUR);
159print "ok 7\n";
817e2dcb 160
05f8a9f5 161fail unless tell(BIG) == 4_500_000_001;
77166d51 162print "ok 8\n";
817e2dcb 163
77166d51 164fail unless seek(BIG, -1, $SEEK_CUR);
165print "ok 9\n";
817e2dcb 166
05f8a9f5 167fail unless tell(BIG) == 4_500_000_000;
77166d51 168print "ok 10\n";
817e2dcb 169
77166d51 170fail unless seek(BIG, -3, $SEEK_END);
171print "ok 11\n";
817e2dcb 172
05f8a9f5 173fail unless tell(BIG) == 5_000_000_000;
77166d51 174print "ok 12\n";
817e2dcb 175
176my $big;
177
05f8a9f5 178fail unless read(BIG, $big, 3) == 3;
77166d51 179print "ok 13\n";
817e2dcb 180
05f8a9f5 181fail unless $big eq "big";
77166d51 182print "ok 14\n";
183
184# 705_032_704 = (I32)5_000_000_000
185fail unless seek(BIG, 705_032_704, $SEEK_SET);
186print "ok 15\n";
187
188my $zero;
189
190fail unless read(BIG, $zero, 3) == 3;
191print "ok 16\n";
192
193fail unless $zero eq "\0\0\0";
194print "ok 17\n";
817e2dcb 195
fcbfa962 196explain if $fail;
05f8a9f5 197
77166d51 198bye(); # does the necessary cleanup
e9a694fc 199
290be4b1 200END {
201 unlink "big"; # be paranoid about leaving 5 gig files lying around
202}
203
6da84e39 204# eof