From patchwork Thu Oct 12 08:49:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10001253 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9FFAF6028A for ; Thu, 12 Oct 2017 08:50:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93A1228CF3 for ; Thu, 12 Oct 2017 08:50:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88B2228D0E; Thu, 12 Oct 2017 08:50:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2443A28CF3 for ; Thu, 12 Oct 2017 08:50:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752966AbdJLIuH (ORCPT ); Thu, 12 Oct 2017 04:50:07 -0400 Received: from mout.gmx.net ([212.227.15.18]:52314 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751717AbdJLIuF (ORCPT ); Thu, 12 Oct 2017 04:50:05 -0400 Received: from localhost.localdomain ([104.156.253.204]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0Me8RK-1dcnGZ3lBG-00Prey; Thu, 12 Oct 2017 10:50:02 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v2 2/2] btrfs-progs: test/mkfs: Test if the minimal device size is valid Date: Thu, 12 Oct 2017 01:49:58 -0700 Message-Id: <20171012084958.19117-1-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171012072858.19005-2-quwenruo.btrfs@gmx.com> References: <20171012072858.19005-2-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:LEDzMfJTBQX6WfMsA/JDkALuKRTpYSIkzaf+kUP+SMSf6wosq5f 7Krvq+DgESASXKeOKEiEjFoSG0/YAlf96ILiYqQS1Yz4C0EQRmT9JVVgxAii9iJW2Cg8CW0 awT/cwGiQMxpew+pe+sVlv138tmPNZVWTZY52+QLTG1IjHcDwsXhvO3tzcc27hRQD8snQy6 4bXwX8+0FWGwBnYxwdtcg== X-UI-Out-Filterresults: notjunk:1; V01:K0:BBwWoe0L1bo=:QNqmxqRvnYDShFWrDgoBN5 a2rdr/2SpBt0qY00GcGOuc5ZH19ooCkdbfj1g3TStT2+fz9JGfPLzSAow1DJPs6B3UXTpHNR7 PEgArMqGUzE0xPbKTc+mKMa9YHwFkAUeoNfyoLhvrptSNBE+FqKsIgWkyf+aluTPQCqLyT+FD OIcU7b7LrbLL/0y6Lumps0lxpO2hXQVRrHtC4juwyNsaNgHFZAJ6TP0V7inUU9inByNf7D3Ql Cr47EpAbrJHIdixnRnmQ0YdKrAsJV5zC7onRtl5YMWtSTGLCtsnm3RcSMjvzZdit+iI6iu9Sc HLu4BXrIDPOhHoYRoZUrHjvbDrWLblQ7myzWkYRg99b+3FPAvMWe8QzaGi8Gh3uGo6+/tQ/kn /jUjq+wUE804muFX0ny4ECkDOBvXuV8wnz8WD8sWRyOvbQuKjy/JdRZAv8k/v+G8YXaS5Yg7u 9koItMY0BMKmsViaNgKF0rCL6QT/fBwB9/Wh5nZnMvfbG1LGjnG8kaO3ej1NJkw2eAHoP+tCr W73mIdpdxQzsRbvvbEmKaARy8DmJjyuZicROfEjbXIqifqYwV0aFPfqdus6elAozkhYasC1Xa lPlER476Hnzg//Wf5Ul2yQWlFCCcfW4y/aEf+2kMnhJfaNVIElhcyhdIhRqNyjVyoRI+KzlLb Js12QzDyoEXG5AlTSxWssknQWC503NqAzIbh74al7JUNXJwSvFriVO3eN595QeWEmSVEu5iwK g7y3v+7YxuYyIhEH/INJJSetVcIexVxIlAw7yRWR6UWgsBaTV04olI/LS+Fl7Zec4/I7kK361 /oX1yG/qBpaGi23eKmTfhsXozYobA== Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP New test case to test if the minimal device size given by "mkfs.btrfs" failure case is valid. Signed-off-by: Qu Wenruo --- changelog: v2: Remove tailing whitespace. Use more accurate regex to match minimal device size, suggested by Lu Fengqi. --- 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..2ed379f9b66f --- /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 -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