]> arthur.barton.de Git - bup.git/blob - t/test-index-check-device.sh
Test for load failures in t/test-*.sh
[bup.git] / t / test-index-check-device.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3 . ./t/lib.sh || exit $?
4
5 set -o pipefail
6
7 if [ $(t/root-status) != root ]; then
8     echo 'Not root: skipping --check-device tests.'
9     exit 0 # FIXME: add WVSKIP.
10 fi
11
12 if test -z "$(type -p losetup)"; then
13     echo 'Unable to find losetup: skipping --check-device tests.'
14     exit 0 # FIXME: add WVSKIP.
15 fi
16
17 if test -z "$(type -p mke2fs)"; then
18     echo 'Unable to find mke2fs: skipping --check-device tests.'
19     exit 0 # FIXME: add WVSKIP.
20 fi
21
22 WVSTART '--check-device'
23
24 top="$(pwd)"
25 tmpdir="$(WVPASS wvmktempdir)" || exit $?
26
27 export BUP_DIR="$tmpdir/bup"
28
29 bup() { "$top/bup" "$@"; }
30
31 srcmnt="$(WVPASS wvmkmountpt)" || exit $?
32 tmpmnt1="$(WVPASS wvmkmountpt)" || exit $?
33 tmpmnt2="$(WVPASS wvmkmountpt)" || exit $?
34
35 WVPASS cd "$tmpdir"
36
37 WVPASS dd if=/dev/zero of=testfs.img bs=1M count=32
38 WVPASS mke2fs -F -j -m 0 testfs.img
39 WVPASS mount -o loop testfs.img "$tmpmnt1"
40 # Hide, so that tests can't create risks.
41 WVPASS chown root:root "$tmpmnt1"
42 WVPASS chmod 0700 "$tmpmnt1"
43
44 # Create trivial content.
45 WVPASS date > "$tmpmnt1/foo"
46 WVPASS umount "$tmpmnt1"
47
48 # Mount twice, so we'll have the same content with different devices.
49 WVPASS mount -oro,loop testfs.img "$tmpmnt1"
50 WVPASS mount -oro,loop testfs.img "$tmpmnt2"
51
52 # Test default behavior: --check-device.
53 WVPASS mount -oro --bind "$tmpmnt1" "$srcmnt"
54 WVPASS bup init
55 WVPASS bup index --fake-valid "$srcmnt"
56 WVPASS umount "$srcmnt"
57 WVPASS mount -oro --bind "$tmpmnt2" "$srcmnt"
58 WVPASS bup index "$srcmnt"
59 WVPASSEQ "$(bup index --status "$srcmnt")" \
60 "M $srcmnt/lost+found/
61 M $srcmnt/foo
62 M $srcmnt/"
63 WVPASS umount "$srcmnt"
64
65 WVSTART '--no-check-device'
66 WVPASS mount -oro --bind "$tmpmnt1" "$srcmnt"
67 WVPASS bup index --clear
68 WVPASS bup index --fake-valid "$srcmnt"
69 WVPASS umount "$srcmnt"
70 WVPASS mount -oro --bind "$tmpmnt2" "$srcmnt"
71 WVPASS bup index --no-check-device "$srcmnt"
72 WVPASS bup index --status "$srcmnt"
73 WVPASSEQ "$(bup index --status "$srcmnt")" \
74 "  $srcmnt/lost+found/
75   $srcmnt/foo
76   $srcmnt/"
77
78 WVPASS umount "$srcmnt"
79 WVPASS umount "$tmpmnt1"
80 WVPASS umount "$tmpmnt2"
81 WVPASS rm -r "$tmpmnt1" "$tmpmnt2" "$tmpdir"