From patchwork Mon Sep 18 07:21:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9955607 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 2A3D460385 for ; Mon, 18 Sep 2017 07:22:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1803428A50 for ; Mon, 18 Sep 2017 07:22:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CE9928ACD; Mon, 18 Sep 2017 07:22:23 +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.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI 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 50DC528A50 for ; Mon, 18 Sep 2017 07:22:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752513AbdIRHWU (ORCPT ); Mon, 18 Sep 2017 03:22:20 -0400 Received: from mout.gmx.net ([212.227.17.21]:53821 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751906AbdIRHWB (ORCPT ); Mon, 18 Sep 2017 03:22:01 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MLR30-1dtIPd1KFO-000eNA; Mon, 18 Sep 2017 09:22:00 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v3 10/14] btrfs-progs: tests/common: Make checksum, permission and acl check path independent Date: Mon, 18 Sep 2017 16:21:35 +0900 Message-Id: <20170918072139.6300-11-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170918072139.6300-1-quwenruo.btrfs@gmx.com> References: <20170918072139.6300-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:WMSbQE8lWonxRT1tZ7DM/ns9vohOYy4Z9vu7m47zHHBVVjyYmyu L3py3OQNCzz8utTxfRrD9IvGzA+MfFIzW+a3tjGnBq/MxcOIgD5O6TvSxGrL2QEWEex8lfQ RNdwTNTIQ/pBSrCN3+nqxij/b0x8vbJjrN0M7edxMEvtbenngSN9XFVMzG5/9oTPOKaf6Ak 7ePhmewSOn4XEXwot/GIQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:RBCMcY1DIak=:3kU0X693wXXJBvJuT4aXvs rSoE3XFsv6TJxOY2YsSxg7KD593Xny1EOVbG54FnDclnIsIoMfawmZYt69cp0sJsgPgMmnv7b F6D+rgyGD/KfdSavHaUVv5rU4+rOHeGIIT6NS+atD0QKvjbBboQklbhFuCN/AbvUWp2giAxeI KMAW17UCrfynq83HdmxfJjsUBuqvoc7mItAU6PSogaEGfk19wQmvF/ECzNEPDS+4hzoZMvNIk a0gPas6jchmSmqSdW1Tu4CMdeCgmHusFT9xR/vVRyK9jQeivbQQNUd2h2wc6KI7GBbT+a+0KL wk4J5PAa8jdHX66ZU4cACoepx8m0nTkwTLShwuIUPByh53vTJdXGbYELX2VjS4PkLIni/uG3o aWbpC9TqsEStNltI9zCiLR7TsQodGyi358hxfzbqTWu/xz6tGYt9YO3wTksAunmQh5F1PwY9I BanG8bSKS7mzWrFUhmB7YPWgZDqYOKZ9sVKNCjktw2s8z7WWlMrCpFXMv4bz2G7Fo9HXbsM1C 9y6SsOU2zF6x7BdP0glDUfhwJIMPz7W3NUGeJKMSIW6kd3U5Fx3z87kFTl+wGzvuKkkqRUbNA AOLC6WFBVSh8zSXHwpv9OlavuDxtzoR4jvw39JWptgkLTyYt1rSffw6LDLnBbEv+eaK7GpQzp n0X9HXaIT1yK5YtivSnVjWm9Q1qQpeJO6Kh3VdjvkjAqnSfIhv0Bk7tR8YZWPDLRaaLCFpKle wt2JWP2BzRW/vuRSThaBr2v6gKOUK+kow/OfMKLjLKi6Er20CmYMobHbT8r4ph3eFvbYhfkL5 owUVrwf8sGP+RIBFJpsF/ky8QI2BA== 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 convert_test_gen_checksums(), convert_test_perm() and convert_test_acl() all uses absolute path, which is good enough for convert test. However for "mkfs --rootdir" test, we want all above function to use relative path, making the output path independent. This patch modified all these functions by: 1) Adding new optional parameter to specify destination directory Callers and corresponding checkers also get this new optional parameter 2) Changing directory before generate files list/csum file And return to old pwd after work is done. Signed-off-by: Qu Wenruo --- tests/common.convert | 91 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/tests/common.convert b/tests/common.convert index 45174b7e..8a36cba3 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -93,45 +93,92 @@ convert_test_prep_fs() { # generate md5 checksums of files on $TEST_MNT # $1: path where the checksums will be stored +# $2: (optional) destination directory if we're not using $TEST_MNT convert_test_gen_checksums() { + local dir_path + local csum_file + local saved_pwd + _assert_path "$1" + csum_file="$1" + if [ -z "$2" ]; then + dir_path="$TEST_MNT" + else + dir_path="$2" + fi - run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \ + run_check $SUDO_HELPER dd if=/dev/zero of="$dir_path/test" "bs=$nodesize" \ count=1 >/dev/null 2>&1 - run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -exec md5sum {} \+ > "$1" + + # We change directory into destination, so generated md5sum file won't + # include absolute path, making the result path independent. + saved_pwd="$(pwd)" + run_check cd "$dir_path" + run_check_stdout $SUDO_HELPER find . -type f ! -name 'image' -exec md5sum {} \+ \ + > "$csum_file" + run_check cd "$saved_pwd" } + # list $TEST_MNT data set file permissions. # $1: path where the permissions will be stored +# $2: (optional) destination directory if we're not using $TEST_MNT convert_test_perm() { local PERMTMP + local saved_pwd + local dir_path _assert_path "$1" PERMTMP="$1" + if [ -z "$2" ]; then + dir_path="$TEST_MNT" + else + dir_path="$2" + fi FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX) - run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \ + run_check $SUDO_HELPER dd if=/dev/zero of="$dir_path/test" "bs=$nodesize" \ count=1 >/dev/null 2>&1 - run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -fprint "$FILES_LIST" + + # Same as convert_test_gen_checksums(), make output path independent + saved_pwd="$(pwd)" + run_check cd "$dir_path" + run_check_stdout $SUDO_HELPER find . -type f ! -name 'image' -fprint "$FILES_LIST" # Fix directory entries order sort "$FILES_LIST" -o "$FILES_LIST" for file in `cat "$FILES_LIST"` ;do run_check_stdout $SUDO_HELPER getfacl --absolute-names "$file" >> "$PERMTMP" done + run_check cd "$saved_pwd" rm -- "$FILES_LIST" } + # list acls of files on $TEST_MNT # $1: path where the acls will be stored +# $2: (optional) destination directory if we're not using $TEST_MNT convert_test_acl() { local ACLSTMP + local dir_path + local saved_pwd + + _assert_path "$1" ACLTMP="$1" + if [ -z "$2" ]; then + dir_path="$TEST_MNT" + else + dir_path="$2" + fi FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX) - run_check_stdout $SUDO_HELPER find "$TEST_MNT/acls" -type f -fprint "$FILES_LIST" + # Make find result and later getfattr output path independent + saved_pwd="$(pwd)" + run_check cd "$dir_path" + run_check_stdout $SUDO_HELPER find "./acls" -type f -fprint "$FILES_LIST" # Fix directory entries order sort "$FILES_LIST" -o "$FILES_LIST" for file in `cat "$FILES_LIST"`;do run_check_stdout $SUDO_HELPER getfattr --absolute-names -d "$file" >> "$ACLTMP" done + run_check cd "$saved_pwd" rm -- "$FILES_LIST" } @@ -149,11 +196,18 @@ convert_test_do_convert() { convert_test_post_check_permissions() { local EXT_PERMTMP local BTRFS_PERMTMP + local dir_path + local saved_pwd _assert_path "$1" EXT_PERMTMP="$1" + if [ -z "$2" ]; then + dir_path="$TEST_MNT" + else + dir_path="$2" + fi BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX) - convert_test_perm "$BTRFS_PERMTMP" + convert_test_perm "$BTRFS_PERMTMP" "$dir_path" btrfs_perm=`md5sum "$BTRFS_PERMTMP" | cut -f1 -d' '` ext_perm=`md5sum "$EXT_PERMTMP" | cut -f1 -d' '` @@ -162,7 +216,7 @@ convert_test_post_check_permissions() { then btrfs_perm_file=`md5sum "$BTRFS_PERMTMP" | cut -f2 -d' '` ext_perm_file=`md5sum "$EXT_PERMTMP" | cut -f2 -d' '` - _fail "file permission failed. Mismatched BTRFS:$btrfs_perm_file:$btrfs_perm EXT:$ext_perm_file:$ext_perm" + _fail "file permission failed. Mismatched AFTER:$btrfs_perm_file:$btrfs_perm BEFORE:$ext_perm_file:$ext_perm" fi rm -- "$BTRFS_PERMTMP" @@ -172,11 +226,17 @@ convert_test_post_check_permissions() { convert_test_post_check_acl() { local EXT_ACLTMP local BTRFS_ACLTMP + local dir_path _assert_path "$1" EXT_ACLTMP="$1" + if [ -z "$2" ]; then + dir_path="$TEST_MNT" + else + dir_path="$2" + fi BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX) - convert_test_acl "$BTRFS_ACLTMP" + convert_test_acl "$BTRFS_ACLTMP" "$dir_path" btrfs_acl=`md5sum "$BTRFS_ACLTMP" | cut -f1 -d' '` ext_acl=`md5sum "$EXT_ACLTMP" | cut -f1 -d' '` @@ -193,9 +253,24 @@ convert_test_post_check_acl() { # post conversion checks, verify md5sums convert_test_post_check_checksums() { + local dir_path + local csum_file + _assert_path "$1" + csum_file="$1" + + if [ -z "$2" ]; then + dir_path="$TEST_MNT" + else + dir_path="$2" + fi + + # csum file is generated using relative path, change directory + saved_pwd="$(pwd)" + run_check cd $dir_path run_check_stdout $SUDO_HELPER md5sum -c "$1" | grep -q 'FAILED' && _fail "file validation failed" + run_check cd $saved_pwd } # post conversion checks, all three in one call, on an unmounted image