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