[2/2] btrfs-progs: test/mkfs: Add test case for rootdir parameter
diff mbox

Message ID 20170904034320.25744-2-quwenruo.btrfs@gmx.com
State New
Headers show

Commit Message

Qu Wenruo Sept. 4, 2017, 3:43 a.m. UTC
Add test case which checks if -r|--rootdir mount option can handle
softlink/char/block/fifo files.

Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
---
 .../009-special-files-for-rootdir/test.sh          | 40 ++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100755 tests/mkfs-tests/009-special-files-for-rootdir/test.sh

Comments

David Sterba Sept. 4, 2017, 5:43 p.m. UTC | #1
On Mon, Sep 04, 2017 at 12:43:20PM +0900, Qu Wenruo wrote:
> Add test case which checks if -r|--rootdir mount option can handle
> softlink/char/block/fifo files.
> 
> Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com>

Patch 1 applied, please fix up the test as commented below.

> ---
>  .../009-special-files-for-rootdir/test.sh          | 40 ++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
>  create mode 100755 tests/mkfs-tests/009-special-files-for-rootdir/test.sh
> 
> diff --git a/tests/mkfs-tests/009-special-files-for-rootdir/test.sh b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh
> new file mode 100755
> index 00000000..bc5297d0
> --- /dev/null
> +++ b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh
> @@ -0,0 +1,40 @@
> +#!/bin/bash
> +# Check if --rootdir can handle special files (socket/fifo/char/block) correctly
> +#
> +# --rootdir had a problem of filling dir items/indexes with wrong type
> +# and caused btrfs check to report such error
> +
> +source "$TOP/tests/common"
> +
> +check_prereq mkfs.btrfs
> +check_prereq btrfs
> +
> +setup_root_helper		# For mknod
> +prepare_test_dev 128M

Device size should be default (ie. no size), unless really required.

> +
> +# mknod can create FIFO/CHAR/BLOCK file but not SOCK.
> +# No neat tool to create socket file, unless using python or similar.
> +# So no SOCK is tested here

Ok, we can live without that.

> +check_global_prereq mknod
> +
> +# Also check regular file
> +check_global_prereq dd
> +
> +# And dir
> +check_global_prereq mkdir

We can assume the base utilities to exist, so cp, rm, mkdir, and several
more.

> +tmp="/tmp/btrfs_selftest_$$"

Please use something like $(mktemp --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX)

> +
> +run_check mkdir $tmp
> +run_check mkdir $tmp/dir
> +run_check mkdir -p $tmp/dir/in/dir
> +run_check mknod $tmp/fifo p
> +run_check $SUDO_HELPER mknod $tmp/char c 1 1
> +run_check $SUDO_HELPER mknod $tmp/block b 1 1
> +run_check dd if=/dev/zero bs=1M count=1 of=$tmp/regular
> +
> +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -r "$tmp" $TEST_DEV
> +
> +rm "$tmp" -rf

This should be options first, then arguments.

> +
> +run_check $SUDO_HELPER "$TOP/btrfs" check $TEST_DEV
> -- 
> 2.14.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/tests/mkfs-tests/009-special-files-for-rootdir/test.sh b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh
new file mode 100755
index 00000000..bc5297d0
--- /dev/null
+++ b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh
@@ -0,0 +1,40 @@ 
+#!/bin/bash
+# Check if --rootdir can handle special files (socket/fifo/char/block) correctly
+#
+# --rootdir had a problem of filling dir items/indexes with wrong type
+# and caused btrfs check to report such error
+
+source "$TOP/tests/common"
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper		# For mknod
+prepare_test_dev 128M
+
+# mknod can create FIFO/CHAR/BLOCK file but not SOCK.
+# No neat tool to create socket file, unless using python or similar.
+# So no SOCK is tested here
+check_global_prereq mknod
+
+# Also check regular file
+check_global_prereq dd
+
+# And dir
+check_global_prereq mkdir
+
+tmp="/tmp/btrfs_selftest_$$"
+
+run_check mkdir $tmp
+run_check mkdir $tmp/dir
+run_check mkdir -p $tmp/dir/in/dir
+run_check mknod $tmp/fifo p
+run_check $SUDO_HELPER mknod $tmp/char c 1 1
+run_check $SUDO_HELPER mknod $tmp/block b 1 1
+run_check dd if=/dev/zero bs=1M count=1 of=$tmp/regular
+
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -r "$tmp" $TEST_DEV
+
+rm "$tmp" -rf
+
+run_check $SUDO_HELPER "$TOP/btrfs" check $TEST_DEV