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