/[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 15 - (hide annotations)
Mon Jul 9 13:33:13 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: application/x-troff
File size: 3769 byte(s)
add a lot of harness tests, and make truncate flag file write
1 dpavlin 6 #!/usr/bin/perl
2     use strict;
3     use warnings;
4    
5     my $debug = shift @ARGV;
6    
7 dpavlin 15 use Test::More tests => 710;
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     cmp_ok( -s "$to/$path", '==', 0, "truncate $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 15 my $curr_size = -s "$from/$path";
71     diag "$op curr_size: $curr_size size: $size";
72     $size += $curr_size if ( $op eq '>>' );
73 dpavlin 12 cmp_ok( -s "$from/$path", '==', $size, "$from/$path = $size bytes" );
74 dpavlin 11 }
75 dpavlin 10
76 dpavlin 12 dump_debug('at end');
77    
78 dpavlin 6 return $content;
79     }
80    
81 dpavlin 10 my $buff = '<<--just a chunk of data-->>';
82 dpavlin 6
83 dpavlin 10 for my $i ( 1 .. 3 ) {
84     my $content = $buff x int(3 + $i * rand(15));
85     $content =~ s/\s+/ /gs;
86 dpavlin 6
87 dpavlin 10 my $file = "test.$i";
88    
89     file( '>', $file, $content );
90 dpavlin 11 file( '<', $file, $content );
91 dpavlin 10
92     file( '>>', $file, '+append' );
93 dpavlin 11 file( '<', $file, $content . '+append' );
94 dpavlin 10
95     file( '>', $file, '' );
96 dpavlin 11 file( '<', $file, '' );
97 dpavlin 10
98 dpavlin 15 file( '>', $file, $content );
99     file( '<', $file, $content );
100 dpavlin 10
101     }
102 dpavlin 12
103    
104 dpavlin 13 sub multiple_rw {
105 dpavlin 12
106 dpavlin 13 diag "multiple read-write";
107     ok( my $fh1 = IO::File->new("> $to/m"), 'open 1' );
108     $fh1->autoflush;
109     ok( print($fh1 "1.1\n"), 'print 1.1' );
110     ok( my $fh2 = IO::File->new(">> $to/m"), 'open 2' );
111     $fh2->autoflush;
112     ok( print($fh2 "2.1\n"), 'print 2.1' );
113     cmp_ok( read_file("$to/m"), 'eq', "1.1\n2.1\n", 'mixed' );
114     ok( print($fh1 "1.2\n"), 'print 1.2' );
115     cmp_ok( read_file("$to/m"), 'eq', "1.1\n1.2\n", 'just 1' );
116     dump_debug 'own twice';
117     ok( print($fh1 "x" x 65535), 'print 1 64k' );
118     ok( close($fh1), 'close 1' );
119     dump_debug 'own once';
120     ok( close($fh2), 'close 2' );
121     dump_debug 'closed';
122    
123 dpavlin 15 my @sizes;
124     my $size = 65536;
125     while ( $size > 1 ) {
126     push @sizes, $size;
127     $size /= 2;
128     }
129    
130     foreach my $size ( @sizes ) {
131     ok( my $fh1 = IO::File->new("> $to/m"), 'open 1' );
132     ok( truncate( $fh1, $size ), 'truncate' );
133     dump_debug 'truncate';
134     ok( close($fh1), 'close 1' );
135     cmp_ok( -s "$to/m", '==', $size, "truncated to $size" );
136     }
137    
138    
139     foreach my $size ( sort @sizes ) {
140     my $orig_size = -s "$to/m";
141     ok( my $fh1 = IO::File->new(">> $to/m"), 'open 1' );
142     ok( print($fh1 "x" x $size), "print $size bytes" );
143     dump_debug 'append';
144     ok( close($fh1), 'close 1' );
145     my $expected_size = $size + $orig_size;
146     cmp_ok( -s "$to/m", '==', $expected_size, "appended upto $expected_size" );
147     }
148    
149    
150 dpavlin 13 }
151    
152     multiple_rw;
153     multiple_rw;
154    
155    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26