From patchwork Mon Jul 27 06:27:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 6869291 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EAEC2C05AC for ; Mon, 27 Jul 2015 06:30:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 00C342062B for ; Mon, 27 Jul 2015 06:30:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 08A612062A for ; Mon, 27 Jul 2015 06:30:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751807AbbG0GaE (ORCPT ); Mon, 27 Jul 2015 02:30:04 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:24133 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751103AbbG0G3i (ORCPT ); Mon, 27 Jul 2015 02:29:38 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="98920054" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Jul 2015 14:33:12 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t6R6Rjfq003818 for ; Mon, 27 Jul 2015 14:27:46 +0800 Received: from localhost.localdomain (10.167.226.114) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Mon, 27 Jul 2015 14:29:35 +0800 From: Zhaolei To: CC: Zhao Lei Subject: [PATCH v2 6/7] btrfs-progs: Move code to create loop device to common Date: Mon, 27 Jul 2015 14:27:53 +0800 Message-ID: <1af761602385c1f0003822af604f307065a835d0.1437977968.git.zhaolei@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Zhao Lei This code block is common used, move it to common function will make code clean. Signed-off-by: Zhao Lei --- tests/common | 16 ++++++++++++++++ tests/fsck-tests/013-extent-tree-rebuild/test.sh | 11 +---------- tests/misc-tests/001-btrfstune-features/test.sh | 11 +---------- tests/misc-tests/002-uuid-rewrite/test.sh | 11 +---------- tests/misc-tests/003-zero-log/test.sh | 11 +---------- 5 files changed, 20 insertions(+), 40 deletions(-) diff --git a/tests/common b/tests/common index 899ec7b..2d337b0 100644 --- a/tests/common +++ b/tests/common @@ -142,3 +142,19 @@ setup_root_helper() fi SUDO_HELPER=root_helper } + +prepare_test_dev() +{ + # num[K/M/G/T...] + local size="$1" + + [[ "$TEST_DEV" ]] && return + [[ "$size" ]] || size='1G' + + echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ + $RESULTS + TEST_DEV="$TOP/tests/test.img" + + truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed" +} + diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 3290cd7..88a66cc 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -5,16 +5,7 @@ source $TOP/tests/common check_prereq btrfs-debug-tree check_prereq mkfs.btrfs setup_root_helper - -if [ -z $TEST_DEV ]; then - echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ - $RESULTS - TEST_DEV="$TOP/tests/test.img" - - # Need at least 1G to avoid mixed block group, which extent tree - # rebuild doesn't support. - run_check truncate -s 1G $TEST_DEV -fi +prepare_test_dev 1G if [ -z $TEST_MNT ];then echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh index c9981e6..ea33954 100755 --- a/tests/misc-tests/001-btrfstune-features/test.sh +++ b/tests/misc-tests/001-btrfstune-features/test.sh @@ -7,16 +7,7 @@ check_prereq btrfs-debug-tree check_prereq btrfs-show-super check_prereq mkfs.btrfs setup_root_helper - -if [ -z $TEST_DEV ]; then - echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ - $RESULTS - TEST_DEV="$TOP/tests/test.img" - - # Need at least 1G to avoid mixed block group, which extent tree - # rebuild doesn't support. - run_check truncate -s 1G $TEST_DEV -fi +prepare_test_dev if [ -z $TEST_MNT ];then echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index 6c2a393..bffa9b8 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -7,16 +7,7 @@ check_prereq btrfs-debug-tree check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfstune - -if [ -z $TEST_DEV ]; then - echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ - $RESULTS - TEST_DEV="$TOP/tests/test.img" - - # Need at least 1G to avoid mixed block group, which extent tree - # rebuild doesn't support. - run_check truncate -s 1G $TEST_DEV -fi +prepare_test_dev if [ -z $TEST_MNT ];then echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh index da5b351..edab5db 100755 --- a/tests/misc-tests/003-zero-log/test.sh +++ b/tests/misc-tests/003-zero-log/test.sh @@ -6,16 +6,7 @@ source $TOP/tests/common check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfs - -if [ -z $TEST_DEV ]; then - echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ - $RESULTS - TEST_DEV="$TOP/tests/test.img" - - # Need at least 1G to avoid mixed block group, which extent tree - # rebuild doesn't support. - run_check truncate -s 1G $TEST_DEV -fi +prepare_test_dev if [ -z $TEST_MNT ];then echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant"