All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
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	[thread overview]
Message-ID: <20170918072139.6300-11-quwenruo.btrfs@gmx.com> (raw)
In-Reply-To: <20170918072139.6300-1-quwenruo.btrfs@gmx.com>

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 <quwenruo.btrfs@gmx.com>
---
 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
-- 
2.14.1


  parent reply	other threads:[~2017-09-18  7:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-18  7:21 [PATCH v3 00/14] Mkfs: Rework --rootdir to a more generic behavior Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 01/14] btrfs-progs: Refactor find_next_chunk() to get rid of parameter root and objectid Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 02/14] btrfs-progs: Fix one-byte overlap bug in free_block_group_cache Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 03/14] btrfs-progs: mkfs: Rework rootdir option to avoid custom chunk layout Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 04/14] btrfs-progs: mkfs: Update allocation info before verbose output Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 05/14] btrfs-progs: Avoid BUG_ON for chunk allocation when ENOSPC happens Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 06/14] btrfs-progs: mkfs: Workaround BUG_ON caused by rootdir option Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 07/14] btrfs-progs: Doc/mkfs: Add extra condition for " Qu Wenruo
2017-09-22  9:24   ` Anand Jain
2017-09-22 10:39     ` Qu Wenruo
2017-09-22 11:38       ` Austin S. Hemmelgarn
2017-09-22 12:32         ` Qu Wenruo
2017-09-22 13:33           ` Austin S. Hemmelgarn
2017-09-22 15:07             ` Qu Wenruo
2017-09-24 10:10               ` Anand Jain
2017-09-24 14:08                 ` Goffredo Baroncelli
2017-09-25 11:15                   ` Austin S. Hemmelgarn
2017-09-27 16:20                     ` David Sterba
2017-09-28  0:00                       ` Qu Wenruo
2017-09-29 11:30                         ` Austin S. Hemmelgarn
2017-09-29 16:57                         ` Goffredo Baroncelli
2017-09-30  3:33                           ` Qu Wenruo
2017-10-02 11:47                             ` Austin S. Hemmelgarn
2017-10-02 18:47                               ` Goffredo Baroncelli
2017-09-25 11:53               ` Austin S. Hemmelgarn
2017-09-18  7:21 ` [PATCH v3 08/14] btrfs-progs: tests/common: Split user xattr into its own branch for generate_dataset Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 09/14] btrfs-progs: tests/common: Introduce optional parameter to specify destination directory " Qu Wenruo
2017-09-18  7:21 ` Qu Wenruo [this message]
2017-09-18  7:21 ` [PATCH v3 11/14] btrfs-progs: tests/mkfs: Add basic test case for rootdir parameter Qu Wenruo
2017-09-18  7:35   ` [PATCH v3.1 " Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 12/14] btrfs-progs: tests/common: Detect ungraceful failure case Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 13/14] btrfs-progs: mkfs: Fix overwritten return value for mkfs Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 14/14] btrfs-progs: tests/mkfs: Check error handler for rootdir parameter Qu Wenruo

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=20170918072139.6300-11-quwenruo.btrfs@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.