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