-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.pl
executable file
·164 lines (122 loc) · 4.04 KB
/
test.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/perl
=pod
This script implements a basic test for the ESFS filesystem.
This file is part of ESFS, a FUSE-based filesystem that supports snapshots.
ESFS is Copyright (C) 2013 Elod Csirmaz
<http://www.epcsirmaz.com/> <https://github.com/csirmaz>.
ESFS is based on Big Brother File System (fuse-tutorial)
Copyright (C) 2012 Joseph J. Pfeiffer, Jr., Ph.D. <[email protected]>,
and was forked from it on 21 August 2013.
Big Brother File System can be distributed under the terms of
the GNU GPLv3. See the file COPYING.
See also <http://www.cs.nmsu.edu/~pfeiffer/fuse-tutorial/>.
Big Brother File System was derived from function prototypes found in
/usr/include/fuse/fuse.h
Copyright (C) 2001-2007 Miklos Szeredi <[email protected]>
fuse.h is licensed under the LGPLv2.
ESFS is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
ESFS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
=cut
use strict;
$| = 1;
sub create_write {
my $filename = shift;
my $contents = shift;
my $fh;
open( $fh, '>', $filename ) || die "Cannot open \'$filename\': $!";
print $fh $contents;
close($fh);
}
sub append {
my $filename = shift;
my $contents = shift;
my $fh;
open( $fh, '>>', $filename ) || die "Cannot open \'$filename\': $!";
print $fh $contents;
close($fh);
}
sub delete_file {
my $filename = shift;
unlink $filename || die "Cannot delete \'$filename\': $!";
}
sub test_contents {
my $filename = shift;
my $contents = shift;
my $fh;
my $fcont;
open( $fh, '<', $filename ) || die "Cannot open \'$filename\': $!";
while(<$fh>) { $fcont .= $_; }
close($fh);
if( $fcont ne $contents ) {
die "Testing \'$filename\' for contents \'$contents\' failed";
}
}
sub test_nonexistent {
my $filename = shift;
if( -e $filename ) {
die "Test failed: \'$filename\' should not exist";
}
}
sub create_snapshot {
my $name = shift;
mkdir 'snapshots/' . $name || die "Cannot create snapshot \'$name\': $!";
}
sub delete_snapshot {
rmdir 'snapshots' || die "Cannot delete snapshot: $!";
}
# Setup
#######
if( -e 'test' ) {
die "'test' already exists - cannot continue";
}
mkdir 'test' || die "Setup failed";
mkdir 'test/data' || die "Setup failed";
mkdir 'test/mnt' || die "Setup failed";
print `./esfs test/data test/mnt`;
chdir 'test/mnt' || die "Cannot chdir";
# Test
######
test_nonexistent('file1');
test_nonexistent('file2');
create_write( 'file1', 'Hello' );
create_snapshot('s1');
create_write( 'file2', 'Two' );
append( 'file1', ' world' );
test_contents( 'snapshots/s1/file1', 'Hello' );
test_nonexistent('snapshots/s1/file2');
test_contents( 'file1', 'Hello world' );
test_contents( 'file2', 'Two' );
create_snapshot('s2');
delete_file('file1');
test_contents( 'snapshots/s1/file1', 'Hello' );
test_nonexistent('snapshots/s1/file2');
test_contents( 'snapshots/s2/file1', 'Hello world' );
test_contents( 'snapshots/s2/file2', 'Two' );
test_nonexistent('file1');
test_contents( 'file2', 'Two' );
create_write( 'file1', 'Second' );
append( 'file1', ' test' );
test_contents( 'snapshots/s1/file1', 'Hello' );
test_nonexistent('snapshots/s1/file2');
test_contents( 'snapshots/s2/file1', 'Hello world' );
test_contents( 'snapshots/s2/file2', 'Two' );
test_contents( 'file1', 'Second test' );
test_contents( 'file2', 'Two' );
delete_snapshot();
delete_snapshot();
# Cleanup
#########
sleep 3;
chdir '../..' || die "Cannot chdir";
`fusermount -u test/mnt`;
rmdir 'test/mnt' || die "Error: test/mnt is not empty";
`rm -rf test`;
print "Done - no errors\n";