From: Rob Browning Date: Sun, 17 Feb 2013 03:20:50 +0000 (-0600) Subject: Add tests for index --no-check-device, and support for t/mnt. X-Git-Tag: bup-0.25-rc2~34 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=8622b8cccd80979d8fb10831b9f66be621e70de9 Add tests for index --no-check-device, and support for t/mnt. Add support for t/mnt; anything mounted there will be cleaned up during "make clean". Thanks to Zak Wilcox for an earlier version of these tests. Signed-off-by: Rob Browning --- diff --git a/Makefile b/Makefile index 560a858..241a4bc 100644 --- a/Makefile +++ b/Makefile @@ -89,6 +89,7 @@ runtests-cmdline: all t/test.sh t/test-meta.sh t/test-restore-single-file.sh + t/test-index-check-device.sh stupid: PATH=/bin:/usr/bin $(MAKE) test @@ -158,6 +159,9 @@ clean: Documentation/clean config/clean bup bup-* cmd/bup-* lib/bup/_version.py randomgen memtest \ out[12] out2[tc] tags[12] tags2[tc] \ testfs.img lib/bup/t/testfs.img + umount t/mnt/* || true + if test -e t/mnt; then rm -r t/mnt; fi + # FIXME: migrate these to t/mnt/ if test -e bupmeta.tmp/testfs; \ then umount bupmeta.tmp/testfs || true; fi if test -e lib/bup/t/testfs; \ diff --git a/t/lib.sh b/t/lib.sh index e8e5268..5696c61 100644 --- a/t/lib.sh +++ b/t/lib.sh @@ -1,3 +1,9 @@ +# Assumes shell is Bash. + +actually-root() +{ + test "$(whoami)" == root -a -z "$FAKEROOTKEY" +} force-delete() { diff --git a/t/test-index-check-device.sh b/t/test-index-check-device.sh new file mode 100755 index 0000000..de7f7ed --- /dev/null +++ b/t/test-index-check-device.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +. ./wvtest-bup.sh +. ./t/lib.sh + +set -ex -o pipefail + +if ! actually-root; then + echo 'Not root: skipping --check-device tests.' + exit 0 # FIXME: add WVSKIP. +fi + +if test -z "$(type -p losetup)"; then + echo 'Unable to find losetup: skipping --check-device tests.' + exit 0 # FIXME: add WVSKIP. +fi + +if test -z "$(type -p mke2fs)"; then + echo 'Unable to find mke2fs: skipping --check-device tests.' + exit 0 # FIXME: add WVSKIP. +fi + +WVSTART '--check-device' + +top="$(pwd)" +tmpdir="$(wvmktempdir)" +export BUP_DIR="$tmpdir/bup" + +bup() { "$top/bup" "$@"; } + +srcmnt="$(wvmkmountpt)" +tmpmnt1="$(wvmkmountpt)" +tmpmnt2="$(wvmkmountpt)" + +cd "$tmpdir" + +dd if=/dev/zero of=testfs.img bs=1M count=32 +mke2fs -F -j -m 0 testfs.img +mount -o loop testfs.img "$tmpmnt1" +# Hide, so that tests can't create risks. +chown root:root "$tmpmnt1" +chmod 0700 "$tmpmnt1" + +# Create trivial content. +date > "$tmpmnt1/foo" +umount "$tmpmnt1" + +# Mount twice, so we'll have the same content with different devices. +mount -oro,loop testfs.img "$tmpmnt1" +mount -oro,loop testfs.img "$tmpmnt2" + +# Test default behavior: --check-device. +mount -oro --bind "$tmpmnt1" "$srcmnt" +bup init +bup index --fake-valid "$srcmnt" +umount "$srcmnt" +mount -oro --bind "$tmpmnt2" "$srcmnt" +bup index "$srcmnt" +WVPASSEQ "$(bup index --status "$srcmnt")" \ +"M $srcmnt/lost+found/ +M $srcmnt/foo +M $srcmnt/" +umount "$srcmnt" + +WVSTART '--no-check-device' +mount -oro --bind "$tmpmnt1" "$srcmnt" +bup index --clear +bup index --fake-valid "$srcmnt" +umount "$srcmnt" +mount -oro --bind "$tmpmnt2" "$srcmnt" +bup index --no-check-device "$srcmnt" +bup index --status "$srcmnt" +WVPASSEQ "$(bup index --status "$srcmnt")" \ +" $srcmnt/lost+found/ + $srcmnt/foo + $srcmnt/" + +umount "$srcmnt" +umount "$tmpmnt1" +umount "$tmpmnt2" +rm -r "$tmpmnt1" "$tmpmnt2" "$tmpdir" diff --git a/t/test-meta.sh b/t/test-meta.sh index 1354505..29c1828 100755 --- a/t/test-meta.sh +++ b/t/test-meta.sh @@ -30,11 +30,6 @@ genstat() ) } -actually-root() -{ - test "$(whoami)" == root -a -z "$FAKEROOTKEY" -} - test-src-create-extract() { # Test bup meta create/extract for ./src -> ./src-restore. diff --git a/wvtest-bup.sh b/wvtest-bup.sh index e7e7752..2529da3 100644 --- a/wvtest-bup.sh +++ b/wvtest-bup.sh @@ -9,8 +9,16 @@ _wvtop="$(pwd)" wvmktempdir () ( - local script_name="$(basename $0)" + script_name="$(basename $0)" set -e -o pipefail mkdir -p "$_wvtop/t/tmp" - echo "$(mktemp -d "$_wvtop/t/tmp/$script_name-XXXXXXX")" + mktemp -d "$_wvtop/t/tmp/$script_name-XXXXXXX" +) + +wvmkmountpt () +( + script_name="$(basename $0)" + set -e -o pipefail + mkdir -p "$_wvtop/t/mnt" + mktemp -d "$_wvtop/t/mnt/$script_name-XXXXXXX" )