/[fuse-comp]/t/fs.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /t/fs.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 28 - (hide annotations)
Tue Jul 10 01:10:49 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: application/x-troff
File size: 5113 byte(s)
ASSERT if uncompressed version also exist,
extracted create_tmp_file and compress_path_dest
1 dpavlin 6 #!/usr/bin/perl
2     use strict;
3     use warnings;
4    
5     my $debug = shift @ARGV;
6    
7 dpavlin 27 use Test::More tests => 766;
8 dpavlin 10 use File::Slurp;
9 dpavlin 12 use IO::File;
10 dpavlin 6
11 dpavlin 10 my ( $from, $to, $tmp ) = ( '/tmp/comp', '/tmp/no-comp', '/dev/shm/comp' );
12 dpavlin 6
13     ok( -e $from, 'from' );
14     ok( -e $to, 'to' );
15     ok( -e $tmp, 'tmp' );
16    
17 dpavlin 12 ok( (system "touch $to/.debug") == 0, 'debug on' );
18    
19     sub dump_debug {
20     my $msg = shift;
21     ok( open(my $d, '<', "$to/.debug"), 'open debug' );
22     local $/;
23     my $dump = <$d>;
24 dpavlin 13 diag "DEBUG: $msg\n$dump\n" if $debug;
25 dpavlin 12 ok( close($d), 'close debug' );
26     }
27    
28 dpavlin 6 sub file {
29     my ( $op, $path, $content ) = @_;
30 dpavlin 12 my $orig_size = -s "$to/$path";
31 dpavlin 6 ok( open( my $fh, $op, "$to/$path" ), "open( $op $path )");
32 dpavlin 12 if ( $op eq '>' ) {
33 dpavlin 28 cmp_ok( -s "$to/$path", '==', 0, "truncated $to/$path" );
34 dpavlin 6 print $fh $content;
35 dpavlin 12 } elsif ( $op eq '>>' ) {
36     cmp_ok( -s "$to/$path", '==', $orig_size, "no truncate $to/$path" );
37     print $fh $content;
38    
39     } elsif ( $op eq '<' ) {
40 dpavlin 11 my $orig_content = $content;
41 dpavlin 6 local $/;
42     $content = <$fh>;
43 dpavlin 11 if ( defined( $content ) ) {
44 dpavlin 12 cmp_ok( $content, 'eq', $orig_content, "content " . length($content) . " bytes" );
45 dpavlin 11 } else {
46 dpavlin 12 ok( $content, "has " . length($content) . " bytes" );
47 dpavlin 11 }
48 dpavlin 12 } else {
49     die "unsupported op: $op";
50 dpavlin 6 }
51 dpavlin 12 dump_debug 'before close';
52 dpavlin 6 ok( close($fh), 'close' );
53 dpavlin 12 dump_debug 'after close';
54 dpavlin 6
55 dpavlin 12 ok ( -e "$to/$path", "exists $to/$path" );
56 dpavlin 6
57 dpavlin 11 my $pack = "$from/${path}.gz";
58 dpavlin 12 my $size = length($content);
59 dpavlin 6
60 dpavlin 11 if ( -e $pack ) {
61 dpavlin 12 ok( -s $pack, "on disk $pack" ) if ( $size > 0 );
62     # check uncompressed size if read
63     ok( -e "$tmp/$path" , "in tmp $tmp/$path" ) if ( $op eq '<' );
64     # check total size if not append
65     if ( $op ne '>>' ) {
66 dpavlin 15 cmp_ok( -s $pack, '==', $size, "$tmp/$path = $size bytes" );
67 dpavlin 12 }
68 dpavlin 11 } else {
69 dpavlin 12 ok( -e "$from/$path", "on disk $from/$path" );
70 dpavlin 16 diag "$op curr_size: $orig_size size: $size";
71     $size += $orig_size if ( $op eq '>>' );
72 dpavlin 12 cmp_ok( -s "$from/$path", '==', $size, "$from/$path = $size bytes" );
73 dpavlin 11 }
74 dpavlin 10
75 dpavlin 12 dump_debug('at end');
76    
77 dpavlin 6 return $content;
78     }
79    
80 dpavlin 18 sub md5sum {
81     my $path = shift;
82     my $md5sum = `md5sum $path`;
83     $md5sum =~ s/\s+.*$//s;
84     warn "## md5sum($path) = $md5sum\n" if $debug;
85     return $md5sum;
86     }
87    
88 dpavlin 10 my $buff = '<<--just a chunk of data-->>';
89 dpavlin 6
90 dpavlin 10 for my $i ( 1 .. 3 ) {
91     my $content = $buff x int(3 + $i * rand(15));
92     $content =~ s/\s+/ /gs;
93 dpavlin 6
94 dpavlin 10 my $file = "test.$i";
95    
96     file( '>', $file, $content );
97 dpavlin 11 file( '<', $file, $content );
98 dpavlin 10
99     file( '>>', $file, '+append' );
100 dpavlin 11 file( '<', $file, $content . '+append' );
101 dpavlin 10
102     file( '>', $file, '' );
103 dpavlin 11 file( '<', $file, '' );
104 dpavlin 10
105 dpavlin 15 file( '>', $file, $content );
106     file( '<', $file, $content );
107 dpavlin 10
108     }
109 dpavlin 12
110    
111 dpavlin 13 sub multiple_rw {
112 dpavlin 12
113 dpavlin 13 diag "multiple read-write";
114     ok( my $fh1 = IO::File->new("> $to/m"), 'open 1' );
115     $fh1->autoflush;
116     ok( print($fh1 "1.1\n"), 'print 1.1' );
117     ok( my $fh2 = IO::File->new(">> $to/m"), 'open 2' );
118     $fh2->autoflush;
119     ok( print($fh2 "2.1\n"), 'print 2.1' );
120     cmp_ok( read_file("$to/m"), 'eq', "1.1\n2.1\n", 'mixed' );
121     ok( print($fh1 "1.2\n"), 'print 1.2' );
122     cmp_ok( read_file("$to/m"), 'eq', "1.1\n1.2\n", 'just 1' );
123     dump_debug 'own twice';
124     ok( print($fh1 "x" x 65535), 'print 1 64k' );
125     ok( close($fh1), 'close 1' );
126     dump_debug 'own once';
127     ok( close($fh2), 'close 2' );
128     dump_debug 'closed';
129    
130 dpavlin 27 ok( symlink("$to/m", "$to/s"), 'symlink' );
131     ok( -l "$to/s", 'is symlink' );
132     ok( link("$to/m", "$to/l"), 'link' );
133     cmp_ok( (stat("$to/l"))[3], '==', 2, 'l has 2 links' );
134     cmp_ok( (stat("$to/m"))[3], '==', 2, 'm has 2 links' );
135    
136     my $size = -s "$to/m";
137     cmp_ok( length(read_file("$to/s")), '==', $size, "$to/s size $size" );
138     cmp_ok( length(read_file("$to/l")), '==', $size, "$to/l size $size" );
139    
140     ok( unlink("$to/s"), 'unlink s' );
141     ok( ! -e "$to/s", 'gone' );
142     ok( unlink("$to/l"), 'unlink l' );
143     cmp_ok( (stat("$to/m"))[3], '==', 1, 'no links' );
144    
145 dpavlin 15 my @sizes;
146 dpavlin 28 $size = 65536;
147 dpavlin 15 while ( $size > 1 ) {
148     push @sizes, $size;
149     $size /= 2;
150     }
151    
152     foreach my $size ( @sizes ) {
153     ok( my $fh1 = IO::File->new("> $to/m"), 'open 1' );
154     ok( truncate( $fh1, $size ), 'truncate' );
155     dump_debug 'truncate';
156     ok( close($fh1), 'close 1' );
157     cmp_ok( -s "$to/m", '==', $size, "truncated to $size" );
158     }
159    
160    
161     foreach my $size ( sort @sizes ) {
162     my $orig_size = -s "$to/m";
163     ok( my $fh1 = IO::File->new(">> $to/m"), 'open 1' );
164     ok( print($fh1 "x" x $size), "print $size bytes" );
165     dump_debug 'append';
166     ok( close($fh1), 'close 1' );
167     my $expected_size = $size + $orig_size;
168     cmp_ok( -s "$to/m", '==', $expected_size, "appended upto $expected_size" );
169     }
170    
171 dpavlin 18 ok( $size = -s "$to/m", 'size' );
172     ok( my $md5sum = md5sum("$to/m"), 'md5sum m' );
173     ok( rename("$to/m", "$to/n"), 'rename' );
174     ok( -e "$to/n", "$to/n exists" );
175     ok( ! -e "$to/m", "$to/m gone" );
176     cmp_ok( -s "$to/n", '==', $size, 'size' );
177     cmp_ok( $md5sum, 'eq', md5sum("$to/n"), 'md5sums same' );
178 dpavlin 15
179 dpavlin 18 ok( unlink("$to/n"), "$to/n unlink" );
180     ok( ! -e "$to/n", "$to/n gone" );
181    
182 dpavlin 25 {
183     ok( my $fh1 = IO::File->new(">> $to/h"), "open $to/h" );
184     ok( print($fh1 "foobar"), "print" );
185     ok( unlink("$to/h"), 'create .fuse_hidden' );
186     ok( ! -e "$to/h", "$to/h gone" );
187     dump_debug 'hidden';
188     ok( print($fh1 "foobar"), "print to hidden" );
189     ok( close($fh1), "close $to/h" );
190     }
191 dpavlin 13 }
192    
193     multiple_rw;
194     multiple_rw;
195    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26