From patchwork Mon Jul 27 14:01:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 6874311 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E23D29F358 for ; Mon, 27 Jul 2015 14:03:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A625B2063B for ; Mon, 27 Jul 2015 14:03:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 743C720636 for ; Mon, 27 Jul 2015 14:03:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753899AbbG0ODk (ORCPT ); Mon, 27 Jul 2015 10:03:40 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:27556 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753722AbbG0ODi (ORCPT ); Mon, 27 Jul 2015 10:03:38 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="98938160" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Jul 2015 22:07:11 +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 t6RE1iOi026014 for ; Mon, 27 Jul 2015 22:01:44 +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 22:03:34 +0800 From: Zhaolei To: CC: Zhao Lei Subject: [PATCH 1/2] btrfs-progs-tests: Introduce init_env() to initialize common env variant Date: Mon, 27 Jul 2015 22:01:58 +0800 Message-ID: X-Mailer: git-send-email 1.8.5.1 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 For example, $TEST_DIR is common used in severial tests, and have duplicated code for initialize. These duplicated code not only benifits harddisk vendor, but have inconsistent details, as: convert-tests.sh: lack of mkdir fsck-tests/012-leaf-corruption/test.sh: unnecessary mkdir fsck-tests/013-extent-tree-rebuild/test.sh: unnecessary init misc-tests/XXX ... And severial error message: _fail "unable to create mount point on $TEST_MNT" _fail "failed to create mount point" ... This patch move initizlizaton of $TEST_DIR to common init_env(), to avoid above problem, and init_env() can be used to add more things in future. Signed-off-by: Zhao Lei --- tests/common | 7 +++++++ tests/convert-tests.sh | 1 - tests/fsck-tests.sh | 3 --- tests/fsck-tests/012-leaf-corruption/test.sh | 1 - tests/fsck-tests/013-extent-tree-rebuild/test.sh | 5 ----- tests/misc-tests.sh | 3 --- tests/misc-tests/001-btrfstune-features/test.sh | 5 ----- tests/misc-tests/002-uuid-rewrite/test.sh | 5 ----- tests/misc-tests/003-zero-log/test.sh | 5 ----- 9 files changed, 7 insertions(+), 28 deletions(-) diff --git a/tests/common b/tests/common index 2d337b0..ba0b78a 100644 --- a/tests/common +++ b/tests/common @@ -158,3 +158,10 @@ prepare_test_dev() truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed" } +init_env() +{ + TEST_MNT="${TEST_MNT:-$TOP/tests/mnt}" + export TEST_MNT + mkdir -p "$TEST_MNT" || { echo "Failed mkdir -p $TEST_MNT"; exit 1; } +} +init_env diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index efed90b..4e8496a 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -9,7 +9,6 @@ unset LANG LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) -TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} RESULTS="$TOP/tests/convert-tests-results.txt" IMAGE="$TOP/tests/test.img" diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index b0ded6a..46dd72d 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -11,7 +11,6 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) TEST_DEV=${TEST_DEV:-} -TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} RESULTS="$TOP/tests/fsck-tests-results.txt" source $TOP/tests/common @@ -20,11 +19,9 @@ source $TOP/tests/common export TOP export RESULTS # For custom script needs to verfiy recovery -export TEST_MNT export LANG rm -f $RESULTS -mkdir -p $TEST_MNT || _fail "unable to create mount point on $TEST_MNT" # test rely on corrupting blocks tool check_prereq btrfs-corrupt-block diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index f8701ad..a37ceda 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -85,7 +85,6 @@ check_inode() check_leaf_corrupt_no_data_ext() { image=$1 - mkdir -p $TEST_MNT || _fail "failed to create mount point" $SUDO_HELPER mount -o loop $image -o ro $TEST_MNT i=0 diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 88a66cc..b7909d2 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -7,11 +7,6 @@ check_prereq mkfs.btrfs setup_root_helper prepare_test_dev 1G -if [ -z $TEST_MNT ];then - echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" - exit 0 -fi - # test whether fsck can rebuild a corrupted extent tree test_extent_tree_rebuild() { diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index 5bbe914..cabe9c3 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -8,7 +8,6 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) TEST_DEV=${TEST_DEV:-} -TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} RESULTS="$TOP/tests/misc-tests-results.txt" IMAGE="$TOP/tests/test.img" @@ -18,11 +17,9 @@ source $TOP/tests/common export TOP export RESULTS # For custom script needs to verfiy recovery -export TEST_MNT export LANG rm -f $RESULTS -mkdir -p $TEST_MNT || _fail "unable to create mount point on $TEST_MNT" # test rely on corrupting blocks tool check_prereq btrfs-corrupt-block diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh index ea33954..836e8d3 100755 --- a/tests/misc-tests/001-btrfstune-features/test.sh +++ b/tests/misc-tests/001-btrfstune-features/test.sh @@ -9,11 +9,6 @@ check_prereq mkfs.btrfs setup_root_helper prepare_test_dev -if [ -z $TEST_MNT ];then - echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" - exit 0 -fi - # test whether fsck can rebuild a corrupted extent tree # parameters: # - option for mkfs.btrfs -O, empty for defaults diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index bffa9b8..9b103aa 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -9,11 +9,6 @@ check_prereq mkfs.btrfs check_prereq btrfstune prepare_test_dev -if [ -z $TEST_MNT ];then - echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" - exit 0 -fi - get_fs_uuid() { local image diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh index edab5db..b650930 100755 --- a/tests/misc-tests/003-zero-log/test.sh +++ b/tests/misc-tests/003-zero-log/test.sh @@ -8,11 +8,6 @@ check_prereq mkfs.btrfs check_prereq btrfs prepare_test_dev -if [ -z $TEST_MNT ];then - echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" - exit 0 -fi - get_log_root() { local image