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