summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDimitri John Ledkov <xnox@ubuntu.com>2016-05-10 10:13:23 +0100
committerDimitri John Ledkov <xnox@ubuntu.com>2016-05-10 10:13:23 +0100
commit58e631d01823afd60e52f3a09887f270a91889a0 (patch)
tree6afbca5492c1ad1040608e01fe0c9d909482adeb /tests
parentcec572daccafa1e912cbed363df6f84687778c6f (diff)
New upstream release 4.5.2.
* Thanks for NMU of package rename. * New upstream release 4.5.2. * Upload using dgit. * Source-only upload. * btrfs-convert should not be included in the initramfs, but should be compiled. Using btrfs-convert is not a trivial operation, and especially not from a minimal shell. Also it is known to fail, and for a sophisticated user it is trivial to include it in the initramfs. Thus won't fix Closes: #801192 * No sponsorship required Closes: #823474 * Add Provides btrfs-tools-udeb to the -progs-udeb package.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/cli-tests.sh41
-rwxr-xr-xtests/cli-tests/001-btrfs/test.sh15
-rwxr-xr-xtests/cli-tests/002-balance-full-no-filters/test.sh21
-rw-r--r--tests/common26
-rwxr-xr-x[-rw-r--r--]tests/convert-tests.sh90
-rw-r--r--tests/fuzz-tests/images/bko-96971-btrfs-image.raw.xzbin0 -> 6448 bytes
-rw-r--r--tests/fuzz-tests/images/bko-96971-btrfs-image.txt69
-rwxr-xr-xtests/misc-tests/013-subvolume-sync-crash/test.sh49
-rwxr-xr-xtests/misc-tests/014-filesystem-label/test.sh69
-rwxr-xr-xtests/mkfs-tests/001-basic-profiles/test.sh2
-rwxr-xr-xtests/mkfs-tests/005-long-device-name-for-ssd/test.sh3
11 files changed, 379 insertions, 6 deletions
diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh
new file mode 100755
index 00000000..e65e7f50
--- /dev/null
+++ b/tests/cli-tests.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+#
+# command line interface coverage tests
+
+unset TOP
+unset LANG
+LANG=C
+SCRIPT_DIR=$(dirname $(readlink -f $0))
+TOP=$(readlink -f $SCRIPT_DIR/../)
+TEST_DEV=${TEST_DEV:-}
+RESULTS="$TOP/tests/cli-tests-results.txt"
+IMAGE="$TOP/tests/test.img"
+
+source $TOP/tests/common
+
+export TOP
+export RESULTS
+export LANG
+export IMAGE
+
+rm -f $RESULTS
+
+check_prereq btrfs
+
+# The tests are driven by their custom script called 'test.sh'
+
+for i in $(find $TOP/tests/cli-tests -maxdepth 1 -mindepth 1 -type d \
+ ${TEST:+-name "$TEST"} | sort)
+do
+ name=$(basename $i)
+ cd $i
+ if [ -x test.sh ]; then
+ echo "=== Entering $i" >> $RESULTS
+ echo " [TEST/cli] $name"
+ ./test.sh
+ if [ $? -ne 0 ]; then
+ _fail "test failed for case $(basename $i)"
+ fi
+ fi
+ cd $TOP
+done
diff --git a/tests/cli-tests/001-btrfs/test.sh b/tests/cli-tests/001-btrfs/test.sh
new file mode 100755
index 00000000..1de2f6f2
--- /dev/null
+++ b/tests/cli-tests/001-btrfs/test.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+# test commands of btrfs
+
+source $TOP/tests/common
+
+check_prereq btrfs
+
+# returns 1
+run_mayfail $TOP/btrfs || true
+run_check $TOP/btrfs version
+run_check $TOP/btrfs version --
+run_check $TOP/btrfs help
+run_check $TOP/btrfs help --
+run_check $TOP/btrfs --help
+run_check $TOP/btrfs --help --full
diff --git a/tests/cli-tests/002-balance-full-no-filters/test.sh b/tests/cli-tests/002-balance-full-no-filters/test.sh
new file mode 100755
index 00000000..c2757f24
--- /dev/null
+++ b/tests/cli-tests/002-balance-full-no-filters/test.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+#
+# coverage of balance --full-balance
+
+source $TOP/tests/common
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev 2g
+
+run_check $TOP/mkfs.btrfs -f $IMAGE
+run_check_mount_test_dev
+
+run_check $SUDO_HELPER $TOP/btrfs balance start --full-balance $TEST_MNT
+run_check $SUDO_HELPER $TOP/btrfs balance start $TEST_MNT
+run_check $SUDO_HELPER $TOP/btrfs balance --full-balance $TEST_MNT
+run_check $SUDO_HELPER $TOP/btrfs balance $TEST_MNT
+
+run_check_umount_test_dev
diff --git a/tests/common b/tests/common
index 61780486..91682eff 100644
--- a/tests/common
+++ b/tests/common
@@ -61,6 +61,32 @@ run_mayfail()
fi
}
+# first argument is error message to print if it fails, otherwise
+# same as run_check but expects the command to fail, output is logged
+run_mustfail()
+{
+ local msg
+
+ msg="$1"
+ shift
+
+ echo "############### $@" >> $RESULTS 2>&1
+ if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mustfail): $@" > /dev/tty; fi
+ if [ "$1" = 'root_helper' ]; then
+ "$@" >> $RESULTS 2>&1
+ else
+ $INSTRUMENT "$@" >> $RESULTS 2>&1
+ fi
+ if [ $? != 0 ]; then
+ echo "failed (expected): $@" >> $RESULTS
+ return 0
+ else
+ echo "succeeded (unexpected!): $@" >> $RESULTS
+ _fail "unexpected success: $msg"
+ return 1
+ fi
+}
+
check_prereq()
{
if ! [ -f $TOP/$1 ]; then
diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh
index 0bfb41f8..06d8419e 100644..100755
--- a/tests/convert-tests.sh
+++ b/tests/convert-tests.sh
@@ -10,16 +10,95 @@ LANG=C
SCRIPT_DIR=$(dirname $(readlink -f $0))
TOP=$(readlink -f $SCRIPT_DIR/../)
RESULTS="$TOP/tests/convert-tests-results.txt"
+# how many files to create.
+DATASET_SIZE=50
source $TOP/tests/common
rm -f $RESULTS
setup_root_helper
-prepare_test_dev 256M
+prepare_test_dev 512M
CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
+generate_dataset() {
+
+ dataset_type="$1"
+ dirpath=$TEST_MNT/$dataset_type
+ run_check $SUDO_HELPER mkdir -p $dirpath
+
+ case $dataset_type in
+ small)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
+ count=1 >/dev/null 2>&1
+ done
+ ;;
+
+ hardlink)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
+ run_check $SUDO_HELPER ln $dirpath/$dataset_type.$num $dirpath/hlink.$num
+ done
+ ;;
+
+ symlink)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
+ run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/slink.$num
+ done
+ ;;
+
+ brokenlink)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/blink.$num
+ done
+ ;;
+
+ perm)
+ for modes in 777 775 755 750 700 666 664 644 640 600 444 440 400 000 \
+ 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \
+ 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \
+ 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do
+ if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]]
+ then
+ continue;
+ else
+ run_check $SUDO_HELPER touch $dirpath/$dataset_type.$modes
+ run_check $SUDO_HELPER chmod $modes $dirpath/$dataset_type.$modes
+ fi
+ done
+ ;;
+
+ sparse)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
+ count=1 >/dev/null 2>&1
+ run_check $SUDO_HELPER truncate -s 500K $dirpath/$dataset_type.$num
+ run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
+ oflag=append conv=notrunc count=1 >/dev/null 2>&1
+ run_check $SUDO_HELPER truncate -s 800K $dirpath/$dataset_type.$num
+ done
+ ;;
+
+ acls)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
+ run_check $SUDO_HELPER setfacl -m "u:root:x" $dirpath/$dataset_type.$num
+ run_check $SUDO_HELPER setfattr -n user.foo -v bar$num $dirpath/$dataset_type.$num
+ done
+ ;;
+ esac
+}
+
+populate_fs() {
+
+ for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 'sparse' 'acls'; do
+ generate_dataset "$dataset_type"
+ done
+}
+
convert_test() {
local features
local nodesize
@@ -39,15 +118,16 @@ convert_test() {
# when test image is on NFS and would not be writable for root
run_check truncate -s 0 $TEST_DEV
# 256MB is the smallest acceptable btrfs image.
- run_check truncate -s 256M $TEST_DEV
+ run_check truncate -s 512M $TEST_DEV
run_check $* -F $TEST_DEV
# create a file to check btrfs-convert can convert regular file
# correct
run_check_mount_test_dev
+ populate_fs
run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \
- count=1 1>/dev/null 2>&1
- run_check_stdout md5sum $TEST_MNT/test > $CHECKSUMTMP
+ count=1 >/dev/null 2>&1
+ run_check_stdout find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > $CHECKSUMTMP
run_check_umount_test_dev
run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $TEST_DEV
@@ -56,7 +136,7 @@ convert_test() {
run_check_mount_test_dev
run_check_stdout md5sum -c $CHECKSUMTMP |
- grep -q 'OK' || _fail "file validation failed."
+ grep -q 'FAILED' && _fail "file validation failed."
run_check_umount_test_dev
}
diff --git a/tests/fuzz-tests/images/bko-96971-btrfs-image.raw.xz b/tests/fuzz-tests/images/bko-96971-btrfs-image.raw.xz
new file mode 100644
index 00000000..21aa33b0
--- /dev/null
+++ b/tests/fuzz-tests/images/bko-96971-btrfs-image.raw.xz
Binary files differ
diff --git a/tests/fuzz-tests/images/bko-96971-btrfs-image.txt b/tests/fuzz-tests/images/bko-96971-btrfs-image.txt
new file mode 100644
index 00000000..ff85540d
--- /dev/null
+++ b/tests/fuzz-tests/images/bko-96971-btrfs-image.txt
@@ -0,0 +1,69 @@
+URL: https://bugzilla.kernel.org/show_bug.cgi?id=96971
+ Lukas Lueg 2015-04-20 23:01:44 UTC
+
+I've identified some problems in the btrfs code and attached a btrfs-image
+which causes the userland tools to crash and the kernel to immediately freeze
+once the filesystem get's mounted and one of the files is accessed. Putting
+the image onto a usb-drive gives you a freeze-on-a-stick :-)
+
+"btrfs check" crashes due to a SIGFPE in count_csum_range(). The culprit is
+struct btrfs_root->fs_info->super_copy->csum_size being 0, which goes
+unchecked before entering a division. I was not able to identify where the
+kernel crashes (system goes down the tubes), yet the problem is probably the
+same.
+
+"btrfs version" is v3.19.1; bug is also present in latest git (kdave and
+unstable) as of 2015/04/21
+
+
+Full gdb output:
+
+gdb btrfs
+GNU gdb (GDB) Fedora 7.8.2-38.fc21
+Copyright (C) 2014 Free Software Foundation, Inc.
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law. Type "show copying"
+and "show warranty" for details.
+This GDB was configured as "x86_64-redhat-linux-gnu".
+Type "show configuration" for configuration details.
+For bug reporting instructions, please see:
+<http://www.gnu.org/software/gdb/bugs/>.
+Find the GDB manual and other documentation resources online at:
+<http://www.gnu.org/software/gdb/documentation/>.
+For help, type "help".
+Type "apropos word" to search for commands related to "word"...
+Reading symbols from btrfs...Reading symbols from /usr/lib/debug/usr/sbin/btrfs.debug...done.
+done.
+(gdb) run check btrfs_fukked.bin
+Starting program: /usr/sbin/btrfs check btrfs_fukked.bin
+[Thread debugging using libthread_db enabled]
+Using host libthread_db library "/lib64/libthread_db.so.1".
+Checking filesystem on btrfs_fukked.bin
+UUID: cdd8684f-9eb1-40a4-91ec-1ed7c3cb444c
+checking extents
+checking free space cache
+checking fs roots
+
+Program received signal SIGFPE, Arithmetic exception.
+count_csum_range (root=<optimized out>, root=<optimized out>,
+ found=<synthetic pointer>, len=7385088, start=7471104) at cmds-check.c:1455
+1455 csum_end = key.offset + (size / csum_size) * root->sectorsize;
+(gdb) bt
+#0 count_csum_range (root=<optimized out>, root=<optimized out>,
+ found=<synthetic pointer>, len=7385088, start=7471104) at cmds-check.c:1455
+#1 process_file_extent (active_node=0x7fffffffd710, key=0x7fffffffd680,
+ slot=11, eb=<optimized out>, root=0x894b10) at cmds-check.c:1551
+#2 process_one_leaf (wc=0x7fffffffd6c0, eb=<optimized out>, root=0x894b10)
+ at cmds-check.c:1617
+#3 walk_down_tree (level=<synthetic pointer>, wc=0x7fffffffd6c0,
+ path=0x7fffffffd7f0, root=0x894b10) at cmds-check.c:1742
+#4 check_fs_root (wc=0x7fffffffd6c0, root_cache=0x7fffffffdb20, root=0x894b10)
+ at cmds-check.c:3380
+#5 check_fs_roots (root_cache=root_cache@entry=0x7fffffffdb20, root=0x894b10)
+ at cmds-check.c:3516
+#6 0x0000000000428aea in cmd_check (argc=<optimized out>,
+ argv=<optimized out>) at cmds-check.c:9465
+#7 0x000000000040e5a2 in main (argc=2, argv=0x7fffffffdeb0) at btrfs.c:245
+(gdb) p csum_size
+$2 = 0
diff --git a/tests/misc-tests/013-subvolume-sync-crash/test.sh b/tests/misc-tests/013-subvolume-sync-crash/test.sh
new file mode 100755
index 00000000..c7955269
--- /dev/null
+++ b/tests/misc-tests/013-subvolume-sync-crash/test.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+#
+# Verify that subovolume sync waits until the subvolume is cleaned and does not
+# crash at the end
+
+source $TOP/tests/common
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+
+run_check truncate -s 2G $IMAGE
+run_check $TOP/mkfs.btrfs -f $IMAGE
+run_check $SUDO_HELPER mount $IMAGE $TEST_MNT
+run_check $SUDO_HELPER chmod a+rw $TEST_MNT
+
+cd $TEST_MNT
+
+for i in `seq 5`; do
+ run_check dd if=/dev/zero of=file$i bs=1M count=10
+done
+
+# 128 is minimum
+for sn in `seq 130`;do
+ run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot . snap$sn
+ for i in `seq 10`; do
+ run_check dd if=/dev/zero of=snap$sn/file$i bs=1M count=1
+ done
+done
+
+run_check $SUDO_HELPER $TOP/btrfs subvolume list .
+run_check $SUDO_HELPER $TOP/btrfs subvolume list -d .
+
+idtodel=`run_check_stdout $SUDO_HELPER $TOP/btrfs inspect-internal rootid snap3`
+
+# delete, sync after some time
+run_check $SUDO_HELPER $TOP/btrfs subvolume delete -c snap*
+{ sleep 5; run_check $TOP/btrfs filesystem sync $TEST_MNT; } &
+
+run_check $SUDO_HELPER $TOP/btrfs subvolume sync .
+
+run_check $TOP/btrfs filesystem sync $TEST_MNT
+run_check $SUDO_HELPER $TOP/btrfs subvolume list -d .
+
+wait
+cd ..
+
+run_check $SUDO_HELPER umount $TEST_MNT
diff --git a/tests/misc-tests/014-filesystem-label/test.sh b/tests/misc-tests/014-filesystem-label/test.sh
new file mode 100755
index 00000000..a5e08ccc
--- /dev/null
+++ b/tests/misc-tests/014-filesystem-label/test.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+#
+# test label settings
+
+source $TOP/tests/common
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+
+run_check truncate -s 2G $IMAGE
+run_check $TOP/mkfs.btrfs -L BTRFS-TEST-LABEL -f $IMAGE
+run_check $SUDO_HELPER mount $IMAGE $TEST_MNT
+run_check $SUDO_HELPER chmod a+rw $TEST_MNT
+
+cd $TEST_MNT
+run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT
+# shortest label
+run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT a
+run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT
+run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT ''
+
+longlabel=\
+0123456789\
+0123456789\
+0123456789\
+0123456789\
+0123456789\
+\
+0123456789\
+0123456789\
+0123456789\
+0123456789\
+0123456789\
+\
+0123456789\
+0123456789\
+0123456789\
+0123456789\
+0123456789\
+\
+0123456789\
+0123456789\
+0123456789\
+0123456789\
+0123456789\
+\
+0123456789\
+0123456789\
+0123456789\
+0123456789\
+0123456789\
+\
+01234
+
+run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT "$longlabel"
+run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT
+# 256, must fail
+run_mustfail "label 256 bytes long succeeded" \
+ $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT "$longlabel"5
+run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT
+run_mustfail "label 2 * 255 bytes long succeeded" \
+ $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT "$longlabel$longlabel"
+run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT
+
+cd ..
+
+run_check $SUDO_HELPER umount $TEST_MNT
diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh
index 2747d429..a6769214 100755
--- a/tests/mkfs-tests/001-basic-profiles/test.sh
+++ b/tests/mkfs-tests/001-basic-profiles/test.sh
@@ -87,5 +87,7 @@ test_mkfs_multi -d raid5 -m raid5
test_mkfs_multi -d raid5 -m raid5 --mixed
test_mkfs_multi -d raid6 -m raid6
test_mkfs_multi -d raid6 -m raid6 --mixed
+test_mkfs_multi -d dup -m dup
+test_mkfs_multi -d dup -m dup --mixed
cleanup_devices
diff --git a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh
index c89ee0e1..cff495e6 100755
--- a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh
+++ b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh
@@ -21,7 +21,8 @@ run_check truncate -s2g img
loopdev=`run_check_stdout $SUDO_HELPER losetup --find --show img`
run_check $SUDO_HELPER dmsetup create $dmname --table "0 1048576 linear $loopdev 0"
-base=`basename "$loopdev"`
+dmbase=`readlink -f $dmdev`
+base=`basename "$dmbase"`
rot=/sys/class/block/$base/queue/rotational
# switch rotational