]> arthur.barton.de Git - bup.git/blob - t/test.sh
Merge remote branch 'origin/master' into meta
[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 midx --check -a
144 WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \
145         $BUP_DIR/objects/pack/*.idx
146 WVPASS bup midx --check -a
147 WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \
148         $BUP_DIR/objects/pack/*.idx \
149         $BUP_DIR/objects/pack/*.idx
150 WVPASS bup midx --check -a
151 all=$(echo $BUP_DIR/objects/pack/*.idx $BUP_DIR/objects/pack/*.midx)
152 WVPASS bup midx -o $BUP_DIR/objects/pack/zzz.midx $all
153 bup tick
154 WVPASS bup midx -o $BUP_DIR/objects/pack/yyy.midx $all
155 WVPASS bup midx -a
156 WVPASSEQ "$(echo $BUP_DIR/objects/pack/*.midx)" \
157         "$BUP_DIR/objects/pack/yyy.midx"
158 WVPASS bup margin
159 WVPASS bup split -t t/testfile2 >tags2t.tmp
160 WVPASS bup split -t t/testfile2 --fanout 3 >tags2tf.tmp
161 WVPASS bup split -r "$BUP_DIR" -c t/testfile2 >tags2c.tmp
162 WVPASS bup split -r :$BUP_DIR -c t/testfile2 >tags2c.tmp
163 WVPASS ls -lR \
164    | WVPASS bup split -r :$BUP_DIR -c --fanout 3 --max-pack-objects 3 -n lslr
165 WVPASS bup ls
166 WVFAIL bup ls /does-not-exist
167 WVPASS bup ls /lslr
168 WVPASS bup ls /lslr/latest
169 WVPASS bup ls /lslr/latest/
170 #WVPASS bup ls /lslr/1971-01-01   # all dates always exist
171 WVFAIL diff -u tags1.tmp tags2.tmp
172
173 # fanout must be different from non-fanout
174 WVFAIL diff tags2t.tmp tags2tf.tmp
175 wc -c t/testfile1 t/testfile2
176 wc -l tags1.tmp tags2.tmp
177
178 WVSTART "bloom"
179 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
180 rm $BUP_DIR/objects/pack/bup.bloom
181 WVPASS bup bloom -k 4
182 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
183 WVPASS bup bloom -d buptest.tmp/objects/pack --ruin --force
184 WVFAIL bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
185 WVPASS bup bloom --force -k 5
186 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
187
188 WVSTART "memtest"
189 WVPASS bup memtest -c1 -n100
190 WVPASS bup memtest -c1 -n100 --existing
191
192 WVSTART "join"
193 WVPASS bup join $(cat tags1.tmp) >out1.tmp
194 WVPASS bup join <tags2.tmp >out2.tmp
195 WVPASS bup join <tags2t.tmp -o out2t.tmp
196 WVPASS bup join -r "$BUP_DIR" <tags2c.tmp >out2c.tmp
197 WVPASS bup join -r ":$BUP_DIR" <tags2c.tmp >out2c.tmp
198 WVPASS diff -u t/testfile1 out1.tmp
199 WVPASS diff -u t/testfile2 out2.tmp
200 WVPASS diff -u t/testfile2 out2t.tmp
201 WVPASS diff -u t/testfile2 out2c.tmp
202
203 WVSTART "save/git-fsck"
204 (
205     set -e
206     cd "$BUP_DIR" || exit 1
207     #git repack -Ad
208     #git prune
209     (cd "$TOP/t/sampledata" && WVPASS bup save -vvn master /) || WVFAIL
210     n=$(git fsck --full --strict 2>&1 | 
211       egrep -v 'dangling (commit|tree)' |
212       tee -a /dev/stderr | 
213       wc -l)
214     WVPASS [ "$n" -eq 0 ]
215 ) || exit 1
216
217 WVSTART "restore"
218 rm -rf buprestore.tmp
219 WVFAIL bup restore boink
220 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D"
221 WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
222 rm -rf buprestore.tmp
223 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D/"
224 WVPASS diff -ur $D/ buprestore.tmp/
225
226 WVSTART "ftp"
227 WVPASS bup ftp "cat /master/latest/$TOP/$D/b" >$D/b.new
228 WVPASS bup ftp "cat /master/latest/$TOP/$D/f" >$D/f.new
229 WVPASS bup ftp "cat /master/latest/$TOP/$D/f"{,} >$D/f2.new
230 WVPASS bup ftp "cat /master/latest/$TOP/$D/a" >$D/a.new
231 WVPASSEQ "$(sha1sum <$D/b)" "$(sha1sum <$D/b.new)"
232 WVPASSEQ "$(sha1sum <$D/f)" "$(sha1sum <$D/f.new)"
233 WVPASSEQ "$(cat $D/f.new{,} | sha1sum)" "$(sha1sum <$D/f2.new)"
234 WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)"
235
236 WVSTART "tag"
237 WVFAIL bup tag -d v0.n 2>/dev/null
238 WVFAIL bup tag v0.n non-existant 2>/dev/null
239 WVPASSEQ "$(bup tag)" ""
240 WVPASS bup tag v0.1 master
241 WVPASSEQ "$(bup tag)" "v0.1"
242 WVPASS bup tag -d v0.1
243
244 # This section destroys data in the bup repository, so it is done last.
245 WVSTART "fsck"
246 WVPASS bup fsck
247 WVPASS bup fsck --quick
248 if bup fsck --par2-ok; then
249     WVSTART "fsck (par2)"
250 else
251     WVSTART "fsck (PAR2 IS MISSING)"
252 fi
253 WVPASS bup fsck -g
254 WVPASS bup fsck -r
255 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1 -S0
256 WVFAIL bup fsck --quick
257 WVFAIL bup fsck --quick --disable-par2
258 chmod u+w $BUP_DIR/objects/pack/*.idx
259 WVPASS bup damage $BUP_DIR/objects/pack/*.idx -n10 -s1 -S0
260 WVFAIL bup fsck --quick -j4
261 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1024 --percent 0.4 -S0
262 WVFAIL bup fsck --quick
263 WVFAIL bup fsck --quick -rvv -j99   # fails because repairs were needed
264 if bup fsck --par2-ok; then
265     WVPASS bup fsck -r # ok because of repairs from last time
266     WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n202 -s1 --equal -S0
267     WVFAIL bup fsck
268     WVFAIL bup fsck -rvv   # too many errors to be repairable
269     WVFAIL bup fsck -r   # too many errors to be repairable
270 else
271     WVFAIL bup fsck --quick -r # still fails because par2 was missing
272 fi
273
274 WVSTART "exclude-bupdir"
275 D=exclude-bupdir.tmp
276 rm -rf $D
277 mkdir $D
278 export BUP_DIR="$D/.bup"
279 WVPASS bup init
280 touch $D/a
281 WVPASS bup random 128k >$D/b
282 mkdir $D/d $D/d/e
283 WVPASS bup random 512 >$D/f
284 WVPASS bup index -ux $D
285 bup save -n exclude-bupdir $D
286 WVPASSEQ "$(bup ls exclude-bupdir/latest/$TOP/$D/)" "a
287 b
288 d/
289 f"
290
291 WVSTART "exclude"
292 D=exclude.tmp
293 rm -rf $D
294 mkdir $D
295 export BUP_DIR="$D/.bup"
296 WVPASS bup init
297 touch $D/a
298 WVPASS bup random 128k >$D/b
299 mkdir $D/d $D/d/e
300 WVPASS bup random 512 >$D/f
301 WVPASS bup index -ux --exclude $D/d $D
302 bup save -n exclude $D
303 WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
304 b
305 f"
306 mkdir $D/g $D/h
307 WVPASS bup index -ux --exclude $D/d --exclude $TOP/$D/g --exclude $D/h $D
308 bup save -n exclude $D
309 WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
310 b
311 f"
312
313 WVSTART "exclude-from"
314 D=exclude-fromdir.tmp
315 EXCLUDE_FILE=exclude-from.tmp
316 echo "$D/d 
317  $TOP/$D/g
318 $D/h" > $EXCLUDE_FILE
319 rm -rf $D
320 mkdir $D
321 export BUP_DIR="$D/.bup"
322 WVPASS bup init
323 touch $D/a
324 WVPASS bup random 128k >$D/b
325 mkdir $D/d $D/d/e
326 WVPASS bup random 512 >$D/f
327 mkdir $D/g $D/h
328 WVPASS bup index -ux --exclude-from $EXCLUDE_FILE $D
329 bup save -n exclude-from $D
330 WVPASSEQ "$(bup ls exclude-from/latest/$TOP/$D/)" "a
331 b
332 f"
333 rm $EXCLUDE_FILE
334
335 WVSTART "strip"
336 D=strip.tmp
337 rm -rf $D
338 mkdir $D
339 export BUP_DIR="$D/.bup"
340 WVPASS bup init
341 touch $D/a
342 WVPASS bup random 128k >$D/b
343 mkdir $D/d $D/d/e
344 WVPASS bup random 512 >$D/f
345 WVPASS bup index -ux $D
346 bup save --strip -n strip $D
347 WVPASSEQ "$(bup ls strip/latest/)" "a
348 b
349 d/
350 f"
351
352 WVSTART "strip-path"
353 D=strip-path.tmp
354 rm -rf $D
355 mkdir $D
356 export BUP_DIR="$D/.bup"
357 WVPASS bup init
358 touch $D/a
359 WVPASS bup random 128k >$D/b
360 mkdir $D/d $D/d/e
361 WVPASS bup random 512 >$D/f
362 WVPASS bup index -ux $D
363 bup save --strip-path $TOP -n strip-path $D
364 WVPASSEQ "$(bup ls strip-path/latest/$D/)" "a
365 b
366 d/
367 f"
368
369 WVSTART "graft_points"
370 D=graft-points.tmp
371 rm -rf $D
372 mkdir $D
373 export BUP_DIR="$D/.bup"
374 WVPASS bup init
375 touch $D/a
376 WVPASS bup random 128k >$D/b
377 mkdir $D/d $D/d/e
378 WVPASS bup random 512 >$D/f
379 WVPASS bup index -ux $D
380 bup save --graft $TOP/$D=/grafted -n graft-point-absolute $D
381 WVPASSEQ "$(bup ls graft-point-absolute/latest/grafted/)" "a
382 b
383 d/
384 f"
385 bup save --graft $D=grafted -n graft-point-relative $D
386 WVPASSEQ "$(bup ls graft-point-relative/latest/$TOP/grafted/)" "a
387 b
388 d/
389 f"
390
391 WVSTART "indexfile"
392 D=indexfile.tmp
393 INDEXFILE=tmpindexfile.tmp
394 rm -f $INDEXFILE
395 rm -rf $D
396 mkdir $D
397 export BUP_DIR="$D/.bup"
398 WVPASS bup init
399 touch $D/a
400 touch $D/b
401 mkdir $D/c
402 WVPASS bup index -ux $D
403 bup save --strip -n bupdir $D
404 WVPASSEQ "$(bup ls bupdir/latest/)" "a
405 b
406 c/"
407 WVPASS bup index -f $INDEXFILE --exclude=$D/c -ux $D
408 bup save --strip -n indexfile -f $INDEXFILE $D
409 WVPASSEQ "$(bup ls indexfile/latest/)" "a
410 b"
411
412
413 WVSTART "import-rsnapshot"
414 D=rsnapshot.tmp
415 export BUP_DIR="$TOP/$D/.bup"
416 rm -rf $D
417 mkdir $D
418 WVPASS bup init
419 mkdir -p $D/hourly.0/buptest/a
420 touch $D/hourly.0/buptest/a/b
421 mkdir -p $D/hourly.0/buptest/c/d
422 touch $D/hourly.0/buptest/c/d/e
423 WVPASS true
424 WVPASS bup import-rsnapshot $D/
425 WVPASSEQ "$(bup ls buptest/latest/)" "a/
426 c/"