]> arthur.barton.de Git - bup.git/blob - test/ext/test-index-check-device
Teach pytest to handle WVSKIP and use it where we can
[bup.git] / test / ext / test-index-check-device
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3 . ./dev/lib.sh || exit $?
4
5 set -o pipefail
6
7 root_status="$(dev/root-status)" || exit $?
8
9 if [ "$root_status" != root ]; then
10     WVSKIP 'Not root: skipping --check-device tests.'
11     exit 0
12 fi
13
14 if test -n "$(type -p modprobe)" && ! modprobe loop; then
15     WVSKIP 'Unable to load loopback module; skipping --check-device test.'
16     exit 0
17 fi
18
19 if test -z "$(type -p losetup)"; then
20     WVSKIP 'Unable to find losetup: skipping --check-device tests.'
21     exit 0
22 fi
23
24 if test -z "$(type -p mke2fs)"; then
25     WVSKIP 'Unable to find mke2fs: skipping --check-device tests.'
26     exit 0
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 # A non-lazy umount was reported to fail on some systems
54 WVPASS umount -l "$tmpmnt1"
55
56 # Mount twice, so we'll have the same content with different devices.
57 WVPASS cp -pP testfs.img testfs2.img
58 WVPASS mount -oro,loop testfs.img "$tmpmnt1"
59 WVPASS mount -oro,loop testfs2.img "$tmpmnt2"
60
61 # Test default behavior: --check-device.
62 WVPASS mount -oro --bind "$tmpmnt1" "$srcmnt"
63 WVPASS bup init
64 WVPASS bup index --fake-valid "$srcmnt"
65 WVPASS umount "$srcmnt"
66 WVPASS mount -oro --bind "$tmpmnt2" "$srcmnt"
67 WVPASS bup index "$srcmnt"
68 WVPASSEQ "$(bup index --status "$srcmnt")" \
69 "M $srcmnt/lost+found/
70 M $srcmnt/foo
71 M $srcmnt/"
72 WVPASS umount "$srcmnt"
73
74 WVSTART '--no-check-device'
75 WVPASS mount -oro --bind "$tmpmnt1" "$srcmnt"
76 WVPASS bup index --clear
77 WVPASS bup index --fake-valid "$srcmnt"
78 WVPASS umount "$srcmnt"
79 WVPASS mount -oro --bind "$tmpmnt2" "$srcmnt"
80 WVPASS bup index --no-check-device "$srcmnt"
81 WVPASS bup index --status "$srcmnt"
82 WVPASSEQ "$(bup index --status "$srcmnt")" \
83 "  $srcmnt/lost+found/
84   $srcmnt/foo
85   $srcmnt/"
86
87 WVPASS umount "$srcmnt"
88 WVPASS umount "$tmpmnt1"
89 WVPASS umount "$tmpmnt2"
90 WVPASS rm -r "$tmpmnt1" "$tmpmnt2" "$tmpdir"