From: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: <linux-btrfs@vger.kernel.org>, <dsterba@suse.cz>
Subject: Re: [PATCH 2/2] btrfs-progs: test/mkfs: Test if the minimal device size is valid
Date: Thu, 12 Oct 2017 16:24:03 +0800 [thread overview]
Message-ID: <20171012082403.GA495@fnst.localdomain> (raw)
In-Reply-To: <20171012072858.19005-2-quwenruo.btrfs@gmx.com>
On Thu, Oct 12, 2017 at 12:28:58AM -0700, Qu Wenruo wrote:
>New test case to test if the minimal device size given by "mkfs.btrfs"
>failure case is valid.
>
>Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
>---
> tests/common | 57 +++++++++++++++++++++++++++++++-
> tests/mkfs-tests/010-small-image/test.sh | 51 ++++++++++++++++++++++++++++
> 2 files changed, 107 insertions(+), 1 deletion(-)
> create mode 100755 tests/mkfs-tests/010-small-image/test.sh
>
>diff --git a/tests/common b/tests/common
>index eb525a4d02c5..e026cc2f4d30 100644
>--- a/tests/common
>+++ b/tests/common
>@@ -236,6 +236,57 @@ run_mustfail()
> fi
> }
>
>+run_mustfail_stdout()
>+{
>+ local spec
>+ local ins
>+ local cmd
>+ local msg
>+ local ret
>+
>+ # We don't use pipefail to avoid disturbing other script, so here we
>+ # use temporary output file.
>+ # So it doesn't support pipeline in the @cmd
>+ local tmp_output
>+
>+ tmp_output=$(mktemp --tmpdir btrfs-progs-test--mustfail-stdtout.XXXXXX)
>+
>+ msg="$1"
>+ shift
>+
>+ if _is_file_or_command "$msg"; then
>+ echo "ASSERTION FAIL: 1st argument of run_mustfail_stdout must be a message"
>+ exit 1
>+ fi
>+
>+ ins=$(_get_spec_ins "$@")
>+ spec=$(($ins-1))
>+ cmd=$(eval echo "\${$spec}")
>+ spec=$(_cmd_spec "${@:$spec}")
>+ set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}"
>+ echo "############### $@" >> "$RESULTS" 2>&1
>+ if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mustfail): $@" > /dev/tty; fi
>+ if [ "$1" = 'root_helper' ]; then
>+ "$@" 2>&1 > "$tmp_output"
>+ else
>+ $INSTRUMENT "$@" 2>&1 > "$tmp_output"
>+ fi
>+ ret=$?
>+
>+ cat "$tmp_output" >> "$RESULTS"
>+ cat "$tmp_output"
>+ rm "$tmp_output"
>+
>+ if [ "$ret" != 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
>@@ -389,7 +440,11 @@ prepare_test_dev()
> # num[K/M/G/T...]
> local size="$1"
>
>- [[ "$TEST_DEV" ]] && return
>+ # Still truncate it to new size
>+ if [[ "$TEST_DEV" ]]; then
>+ truncate -s "$size" "$TEST_DEV"
>+ return;
>+ fi
> [[ "$size" ]] || size='2G'
>
> echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \
>diff --git a/tests/mkfs-tests/010-small-image/test.sh b/tests/mkfs-tests/010-small-image/test.sh
>new file mode 100755
>index 000000000000..f12c9c836bd6
>--- /dev/null
>+++ b/tests/mkfs-tests/010-small-image/test.sh
>@@ -0,0 +1,51 @@
>+#!/bin/bash
>+# test if the reported minimal size of mkfs.btrfs is valid
>+
>+source $TOP/tests/common
>+
>+check_prereq mkfs.btrfs
>+check_prereq btrfs
>+
>+setup_root_helper
>+
>+pagesize=$(getconf PAGESIZE)
>+
>+do_test()
>+{
>+ # Well, 1M small enough to fail, we just use the output
>+ # to get the minimal device size
>+ prepare_test_dev 1M
>+ output=$(run_mustfail_stdout "mkfs.btrfs for small image" \
>+ $TOP/mkfs.btrfs -f $@ "$TEST_DEV")
>+ good_size=$(echo $output | grep -o "[[:digit:]]\{3,\}")
I applied these patches on kdave/devel, and found a small problem when run
mkfs-tests/010-small-image.
# fallocate -l 1M a.img
# ./mkfs.btrfs a.img
btrfs-progs v4.13.2-34-ga8dc557a
See http://btrfs.wiki.kernel.org for more information.
ERROR: 'a.img' is too small to make a usable filesystem
ERROR: minimum size for each btrfs device is 113246208
"[[:digit:]]\{3,\}" will not only match 113246208, but will match 557.
So I suggest using the following regex here. It will only match the
number after "is ".
good_size=$(echo $output | grep -oP "(?<=is )\d+")
>+
>+ prepare_test_dev "$good_size"
>+ run_check $TOP/mkfs.btrfs -f $@ "$TEST_DEV"
>+ run_check $SUDO_HELPER mount $TEST_DEV $TEST_MNT
>+ run_check $SUDO_HELPER umount $TEST_MNT
>+}
>+
>+do_test -n 4k -m single -d single
>+do_test -n 4k -m single -d dup
>+do_test -n 4k -m dup -d single
>+do_test -n 4k -m dup -d dup
>+
>+do_test -n 8k -m single -d single
>+do_test -n 8k -m single -d dup
>+do_test -n 8k -m dup -d single
>+do_test -n 8k -m dup -d dup
>+
>+do_test -n 16k -m single -d single
>+do_test -n 16k -m single -d dup
>+do_test -n 16k -m dup -d single
>+do_test -n 16k -m dup -d dup
>+
>+do_test -n 32k -m single -d single
>+do_test -n 32k -m single -d dup
>+do_test -n 32k -m dup -d single
>+do_test -n 32k -m dup -d dup
>+
>+do_test -n 64k -m single -d single
>+do_test -n 64k -m single -d dup
>+do_test -n 64k -m dup -d single
>+do_test -n 64k -m dup -d dup
>--
>2.14.2
>
>--
>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
>
>
--
Thanks,
Lu
next prev parent reply other threads:[~2017-10-12 8:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-12 7:28 [PATCH 1/2] btrfs-progs: mkfs: Enhance minimal device size calculation to fix mkfs failure on small file Qu Wenruo
2017-10-12 7:28 ` [PATCH 2/2] btrfs-progs: test/mkfs: Test if the minimal device size is valid Qu Wenruo
2017-10-12 8:24 ` Lu Fengqi [this message]
2017-10-12 8:41 ` Qu Wenruo
2017-10-12 8:49 ` [PATCH v2 " Qu Wenruo
2017-10-12 9:23 ` [PATCH 1/2] btrfs-progs: mkfs: Enhance minimal device size calculation to fix mkfs failure on small file Lu Fengqi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171012082403.GA495@fnst.localdomain \
--to=lufq.fnst@cn.fujitsu.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo.btrfs@gmx.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).