]> arthur.barton.de Git - bup.git/blob - t/test.sh
Add tests around the bloom ruin and check options
[bup.git] / t / test.sh
1 #!/usr/bin/env bash
2 . wvtest.sh
3 #set -e
4
5 TOP="$(/bin/pwd)"
6 export BUP_DIR="$TOP/buptest.tmp"
7
8 bup()
9 {
10     "$TOP/bup" "$@"
11 }
12
13 WVSTART "init"
14
15 #set -x
16 rm -rf "$BUP_DIR"
17 WVPASS bup init
18
19 WVSTART "index"
20 D=bupdata.tmp
21 rm -rf $D
22 mkdir $D
23 WVPASSEQ "$(bup index --check -p)" ""
24 WVPASSEQ "$(bup index --check -p $D)" ""
25 WVFAIL [ -e $D.fake ]
26 WVFAIL bup index --check -u $D.fake
27 WVPASS bup index --check -u $D
28 WVPASSEQ "$(bup index --check -p $D)" "$D/"
29 touch $D/a
30 WVPASS bup random 128k >$D/b
31 mkdir $D/d $D/d/e
32 WVPASS bup random 512 >$D/f
33 WVPASSEQ "$(bup index -s $D/)" "A $D/"
34 WVPASSEQ "$(bup index -s $D/b)" ""
35 WVPASSEQ "$(bup index --check -us $D/b)" "A $D/b"
36 WVPASSEQ "$(bup index --check -us $D/b $D/d)" \
37 "A $D/d/e/
38 A $D/d/
39 A $D/b"
40 touch $D/d/z
41 bup tick
42 WVPASSEQ "$(bup index --check -usx $D)" \
43 "A $D/f
44 A $D/d/z
45 A $D/d/e/
46 A $D/d/
47 A $D/b
48 A $D/a
49 A $D/"
50 WVPASSEQ "$(bup index --check -us $D/a $D/b --fake-valid)" \
51 "  $D/b
52   $D/a"
53 WVPASSEQ "$(bup index --check -us $D/a)" "  $D/a"  # stays unmodified
54 WVPASSEQ "$(bup index --check -us $D/d --fake-valid)" \
55 "  $D/d/z
56   $D/d/e/
57   $D/d/"
58 touch $D/d/z
59 WVPASS bup index -u $D/d/z  # becomes modified
60 WVPASSEQ "$(bup index -s $D/a $D $D/b)" \
61 "A $D/f
62 M $D/d/z
63   $D/d/e/
64 M $D/d/
65   $D/b
66   $D/a
67 A $D/"
68
69 WVPASS bup index -u $D/d/e $D/a --fake-invalid
70 WVPASSEQ "$(cd $D && bup index -m .)" \
71 "./f
72 ./d/z
73 ./d/e/
74 ./d/
75 ./a
76 ./"
77 WVPASSEQ "$(cd $D && bup index -m)" \
78 "f
79 d/z
80 d/e/
81 d/
82 a
83 ./"
84 WVPASSEQ "$(cd $D && bup index -s .)" "$(cd $D && bup index -s .)"
85
86 WVFAIL bup save -t $D/doesnt-exist-filename
87
88 mv $BUP_DIR/bupindex $BUP_DIR/bi.old
89 WVFAIL bup save -t $D/d/e/fifotest
90 mkfifo $D/d/e/fifotest
91 WVPASS bup index -u $D/d/e/fifotest
92 WVFAIL bup save -t $D/d/e/fifotest
93 WVFAIL bup save -t $D/d/e
94 rm -f $D/d/e/fifotest
95 WVPASS bup index -u $D/d/e
96 WVFAIL bup save -t $D/d/e/fifotest
97 mv $BUP_DIR/bi.old $BUP_DIR/bupindex
98
99 WVPASS bup index -u $D/d/e
100 WVPASS bup save -t $D/d/e
101 WVPASSEQ "$(cd $D && bup index -m)" \
102 "f
103 d/z
104 d/
105 a
106 ./"
107 WVPASS bup save -t $D/d
108 WVPASSEQ "$(cd $D && bup index -m)" \
109 "f
110 a
111 ./"
112 tree1=$(bup save -t $D)
113 WVPASSEQ "$(cd $D && bup index -m)" ""
114 tree2=$(bup save -t $D)
115 WVPASSEQ "$tree1" "$tree2"
116 WVPASSEQ "$(bup index -s / | grep ^D)" ""
117 tree3=$(bup save -t /)
118 WVPASSEQ "$tree1" "$tree3"
119 WVPASS bup save -r :$BUP_DIR -n r-test $D
120 WVFAIL bup save -r :$BUP_DIR/fake/path -n r-test $D
121 WVFAIL bup save -r :$BUP_DIR -n r-test $D/fake/path
122
123 WVSTART "split"
124 echo a >a.tmp
125 echo b >b.tmp
126 WVPASS bup split -b a.tmp >taga.tmp
127 WVPASS bup split -b b.tmp >tagb.tmp
128 cat a.tmp b.tmp | WVPASS bup split -b >tagab.tmp
129 WVPASSEQ $(cat taga.tmp | wc -l) 1
130 WVPASSEQ $(cat tagb.tmp | wc -l) 1
131 WVPASSEQ $(cat tagab.tmp | wc -l) 1
132 WVPASSEQ $(cat tag[ab].tmp | wc -l) 2
133 WVPASSEQ "$(bup split -b a.tmp b.tmp)" "$(cat tagab.tmp)"
134 WVPASSEQ "$(bup split -b --keep-boundaries a.tmp b.tmp)" "$(cat tag[ab].tmp)"
135 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --keep-boundaries --git-ids)" \
136          "$(cat tag[ab].tmp)"
137 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --git-ids)" \
138          "$(cat tagab.tmp)"
139 WVPASS bup split --bench -b <t/testfile1 >tags1.tmp
140 WVPASS bup split -vvvv -b t/testfile2 >tags2.tmp
141 WVPASS bup margin
142 WVPASS bup midx -f
143 WVPASS bup margin
144 WVPASS bup split -t t/testfile2 >tags2t.tmp
145 WVPASS bup split -t t/testfile2 --fanout 3 >tags2tf.tmp
146 WVPASS bup split -r "$BUP_DIR" -c t/testfile2 >tags2c.tmp
147 WVPASS bup split -r :$BUP_DIR -c t/testfile2 >tags2c.tmp
148 WVPASS ls -lR \
149    | WVPASS bup split -r :$BUP_DIR -c --fanout 3 --max-pack-objects 3 -n lslr
150 WVPASS bup ls
151 WVFAIL bup ls /does-not-exist
152 WVPASS bup ls /lslr
153 WVPASS bup ls /lslr/latest
154 WVPASS bup ls /lslr/latest/
155 #WVPASS bup ls /lslr/1971-01-01   # all dates always exist
156 WVFAIL diff -u tags1.tmp tags2.tmp
157
158 # fanout must be different from non-fanout
159 WVFAIL diff tags2t.tmp tags2tf.tmp
160 wc -c t/testfile1 t/testfile2
161 wc -l tags1.tmp tags2.tmp
162
163 WVSTART "bloom"
164 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
165 rm $BUP_DIR/objects/pack/bup.bloom
166 WVPASS bup bloom -k 4
167 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
168 WVPASS bup bloom -d buptest.tmp/objects/pack --ruin --force
169 WVFAIL bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
170 WVPASS bup bloom --force -k 5
171 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
172
173 WVSTART "memtest"
174 WVPASS bup memtest -c1 -n100
175 WVPASS bup memtest -c1 -n100 --existing
176
177 WVSTART "join"
178 WVPASS bup join $(cat tags1.tmp) >out1.tmp
179 WVPASS bup join <tags2.tmp >out2.tmp
180 WVPASS bup join <tags2t.tmp -o out2t.tmp
181 WVPASS bup join -r "$BUP_DIR" <tags2c.tmp >out2c.tmp
182 WVPASS bup join -r ":$BUP_DIR" <tags2c.tmp >out2c.tmp
183 WVPASS diff -u t/testfile1 out1.tmp
184 WVPASS diff -u t/testfile2 out2.tmp
185 WVPASS diff -u t/testfile2 out2t.tmp
186 WVPASS diff -u t/testfile2 out2c.tmp
187
188 WVSTART "save/git-fsck"
189 (
190     set -e
191     cd "$BUP_DIR" || exit 1
192     #git repack -Ad
193     #git prune
194     (cd "$TOP/t/sampledata" && WVPASS bup save -vvn master /) || WVFAIL
195     n=$(git fsck --full --strict 2>&1 | 
196       egrep -v 'dangling (commit|tree)' |
197       tee -a /dev/stderr | 
198       wc -l)
199     WVPASS [ "$n" -eq 0 ]
200 ) || exit 1
201
202 WVSTART "restore"
203 rm -rf buprestore.tmp
204 WVFAIL bup restore boink
205 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D"
206 WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
207 rm -rf buprestore.tmp
208 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D/"
209 WVPASS diff -ur $D/ buprestore.tmp/
210
211 WVSTART "ftp"
212 WVPASS bup ftp "cat /master/latest/$TOP/$D/b" >$D/b.new
213 WVPASS bup ftp "cat /master/latest/$TOP/$D/f" >$D/f.new
214 WVPASS bup ftp "cat /master/latest/$TOP/$D/f"{,} >$D/f2.new
215 WVPASS bup ftp "cat /master/latest/$TOP/$D/a" >$D/a.new
216 WVPASSEQ "$(sha1sum <$D/b)" "$(sha1sum <$D/b.new)"
217 WVPASSEQ "$(sha1sum <$D/f)" "$(sha1sum <$D/f.new)"
218 WVPASSEQ "$(cat $D/f.new{,} | sha1sum)" "$(sha1sum <$D/f2.new)"
219 WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)"
220
221 WVSTART "tag"
222 WVFAIL bup tag -d v0.n 2>/dev/null
223 WVFAIL bup tag v0.n non-existant 2>/dev/null
224 WVPASSEQ "$(bup tag)" ""
225 WVPASS bup tag v0.1 master
226 WVPASSEQ "$(bup tag)" "v0.1"
227 WVPASS bup tag -d v0.1
228
229 # This section destroys data in the bup repository, so it is done last.
230 WVSTART "fsck"
231 WVPASS bup fsck
232 WVPASS bup fsck --quick
233 if bup fsck --par2-ok; then
234     WVSTART "fsck (par2)"
235 else
236     WVSTART "fsck (PAR2 IS MISSING)"
237 fi
238 WVPASS bup fsck -g
239 WVPASS bup fsck -r
240 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1 -S0
241 WVFAIL bup fsck --quick
242 WVFAIL bup fsck --quick --disable-par2
243 chmod u+w $BUP_DIR/objects/pack/*.idx
244 WVPASS bup damage $BUP_DIR/objects/pack/*.idx -n10 -s1 -S0
245 WVFAIL bup fsck --quick -j4
246 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1024 --percent 0.4 -S0
247 WVFAIL bup fsck --quick
248 WVFAIL bup fsck --quick -rvv -j99   # fails because repairs were needed
249 if bup fsck --par2-ok; then
250     WVPASS bup fsck -r # ok because of repairs from last time
251     WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n202 -s1 --equal -S0
252     WVFAIL bup fsck
253     WVFAIL bup fsck -rvv   # too many errors to be repairable
254     WVFAIL bup fsck -r   # too many errors to be repairable
255 else
256     WVFAIL bup fsck --quick -r # still fails because par2 was missing
257 fi
258
259 WVSTART "exclude-bupdir"
260 D=exclude-bupdir.tmp
261 rm -rf $D
262 mkdir $D
263 export BUP_DIR="$D/.bup"
264 WVPASS bup init
265 touch $D/a
266 WVPASS bup random 128k >$D/b
267 mkdir $D/d $D/d/e
268 WVPASS bup random 512 >$D/f
269 WVPASS bup index -ux $D
270 bup save -n exclude-bupdir $D
271 WVPASSEQ "$(bup ls exclude-bupdir/latest/$TOP/$D/)" "a
272 b
273 d/
274 f"
275
276 WVSTART "exclude"
277 D=exclude.tmp
278 rm -rf $D
279 mkdir $D
280 export BUP_DIR="$D/.bup"
281 WVPASS bup init
282 touch $D/a
283 WVPASS bup random 128k >$D/b
284 mkdir $D/d $D/d/e
285 WVPASS bup random 512 >$D/f
286 WVPASS bup index -ux --exclude $D/d $D
287 bup save -n exclude $D
288 WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
289 b
290 f"
291 mkdir $D/g $D/h
292 WVPASS bup index -ux --exclude $D/d --exclude $TOP/$D/g --exclude $D/h $D
293 bup save -n exclude $D
294 WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
295 b
296 f"
297
298 WVSTART "exclude-from"
299 D=exclude-fromdir.tmp
300 EXCLUDE_FILE=exclude-from.tmp
301 echo "$D/d 
302  $TOP/$D/g
303 $D/h" > $EXCLUDE_FILE
304 rm -rf $D
305 mkdir $D
306 export BUP_DIR="$D/.bup"
307 WVPASS bup init
308 touch $D/a
309 WVPASS bup random 128k >$D/b
310 mkdir $D/d $D/d/e
311 WVPASS bup random 512 >$D/f
312 mkdir $D/g $D/h
313 WVPASS bup index -ux --exclude-from $EXCLUDE_FILE $D
314 bup save -n exclude-from $D
315 WVPASSEQ "$(bup ls exclude-from/latest/$TOP/$D/)" "a
316 b
317 f"
318 rm $EXCLUDE_FILE
319
320 WVSTART "strip"
321 D=strip.tmp
322 rm -rf $D
323 mkdir $D
324 export BUP_DIR="$D/.bup"
325 WVPASS bup init
326 touch $D/a
327 WVPASS bup random 128k >$D/b
328 mkdir $D/d $D/d/e
329 WVPASS bup random 512 >$D/f
330 WVPASS bup index -ux $D
331 bup save --strip -n strip $D
332 WVPASSEQ "$(bup ls strip/latest/)" "a
333 b
334 d/
335 f"
336
337 WVSTART "strip-path"
338 D=strip-path.tmp
339 rm -rf $D
340 mkdir $D
341 export BUP_DIR="$D/.bup"
342 WVPASS bup init
343 touch $D/a
344 WVPASS bup random 128k >$D/b
345 mkdir $D/d $D/d/e
346 WVPASS bup random 512 >$D/f
347 WVPASS bup index -ux $D
348 bup save --strip-path $TOP -n strip-path $D
349 WVPASSEQ "$(bup ls strip-path/latest/$D/)" "a
350 b
351 d/
352 f"
353
354 WVSTART "graft_points"
355 D=graft-points.tmp
356 rm -rf $D
357 mkdir $D
358 export BUP_DIR="$D/.bup"
359 WVPASS bup init
360 touch $D/a
361 WVPASS bup random 128k >$D/b
362 mkdir $D/d $D/d/e
363 WVPASS bup random 512 >$D/f
364 WVPASS bup index -ux $D
365 bup save --graft $TOP/$D=/grafted -n graft-point-absolute $D
366 WVPASSEQ "$(bup ls graft-point-absolute/latest/grafted/)" "a
367 b
368 d/
369 f"
370 bup save --graft $D=grafted -n graft-point-relative $D
371 WVPASSEQ "$(bup ls graft-point-relative/latest/$TOP/grafted/)" "a
372 b
373 d/
374 f"
375
376 WVSTART "indexfile"
377 D=indexfile.tmp
378 INDEXFILE=tmpindexfile.tmp
379 rm -f $INDEXFILE
380 rm -rf $D
381 mkdir $D
382 export BUP_DIR="$D/.bup"
383 WVPASS bup init
384 touch $D/a
385 touch $D/b
386 mkdir $D/c
387 WVPASS bup index -ux $D
388 bup save --strip -n bupdir $D
389 WVPASSEQ "$(bup ls bupdir/latest/)" "a
390 b
391 c/"
392 WVPASS bup index -f $INDEXFILE --exclude=$D/c -ux $D
393 bup save --strip -n indexfile -f $INDEXFILE $D
394 WVPASSEQ "$(bup ls indexfile/latest/)" "a
395 b"
396
397
398 WVSTART "import-rsnapshot"
399 D=rsnapshot.tmp
400 export BUP_DIR="$TOP/$D/.bup"
401 rm -rf $D
402 mkdir $D
403 WVPASS bup init
404 mkdir -p $D/hourly.0/buptest/a
405 touch $D/hourly.0/buptest/a/b
406 mkdir -p $D/hourly.0/buptest/c/d
407 touch $D/hourly.0/buptest/c/d/e
408 WVPASS true
409 WVPASS bup import-rsnapshot $D/
410 WVPASSEQ "$(bup ls buptest/latest/)" "a/
411 c/"