Linux-EROFS Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: hsiangkao@linux.alibaba.com, linux-erofs@lists.ozlabs.org
Cc: huyue2@coolpad.com
Subject: [PATCH 2/2] erofs-utils: tests: add test for xattrs in random layouts
Date: Wed, 14 Jun 2023 11:26:42 +0800	[thread overview]
Message-ID: <20230614032642.8186-2-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20230614032642.8186-1-jefflexu@linux.alibaba.com>

Generate and check random xattrs.  Set xattrs on tested file as much
as possible until the number or size of xattrs has reached the upper
limit for single file, e.g. maximum one block size for xattrs for
single file in ext4.

The same xattr may be shared among multiple tested files or not.
Thus the layout of mixed inline and shared xattrs is tested.

Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
 tests/Makefile.am   |   3 ++
 tests/erofs/023     | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/erofs/023.out |   2 +
 3 files changed, 109 insertions(+)
 create mode 100755 tests/erofs/023
 create mode 100644 tests/erofs/023.out

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6295964..b0e7806 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -100,6 +100,9 @@ TESTS += erofs/021
 # 022 - check long extended attribute name prefixes
 TESTS += erofs/022
 
+# 023 - check extended attributes in random layouts
+TESTS += erofs/023
+
 EXTRA_DIST = common/rc erofs
 
 clean-local: clean-local-check
diff --git a/tests/erofs/023 b/tests/erofs/023
new file mode 100755
index 0000000..7998705
--- /dev/null
+++ b/tests/erofs/023
@@ -0,0 +1,104 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0+
+#
+# 023 - check extended attributes in random layouts
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$(echo $0 | awk '{print $((NF-1))"/"$NF}' FS="/")
+
+# get standard environment, filters and checks
+. "${srcdir}/common/rc"
+
+cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+}
+
+_require_erofs
+_require_xattr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+echo "QA output created by $seq"
+
+if [ -z $SCRATCH_DEV ]; then
+	SCRATCH_DEV=$tmp/erofs_$seq.img
+	rm -f SCRATCH_DEV
+fi
+
+localdir="$tmp/$seq"
+rm -rf $localdir
+mkdir -p $localdir
+
+# feed random seed
+RANDOM=$$
+
+# build file list of all descendant files under the directory
+cp -nR ../ $localdir
+entries=`find $localdir -mindepth 1 -type f -not -path '*git*' -printf '%P\n'`
+i=0
+for file in $entries; do
+	files[$i]="$file"
+	i=$((i+1))
+done
+num_files=${#files[*]}
+[ $num_files -eq 0 ] && _notrun "empty file list"
+
+# set random xattrs
+for file in ${files[*]}; do
+	while true; do
+		key=$(_random $(($RANDOM%32)))
+		val=$(_random $(($RANDOM%32)))
+
+		# allow of xattrs with empty value
+		VAL_OPTIONS=""
+		if [ -n "$val" ]; then
+			VAL_OPTIONS="-v $val"
+		fi
+
+		# move to next file if the disk space for xattr has been consumed
+		# for the current file
+		setfattr -n user.$key $VAL_OPTIONS $localdir/$file >>$seqres.full 2>&1 \
+			|| break
+
+		# share this xattr or not?
+		if [ $(($RANDOM%2)) -ne 0 ]; then
+			# tag this xattr to other files to build shared xattrs
+			# generate a random step in [1, 64]
+			step=$(($(($RANDOM%64))+1))
+			i=0
+			while true; do
+				i=$(($i+$step))
+				if [ $i -lt $num_files ]; then
+					setfattr -n user.$key $VAL_OPTIONS $localdir/${files[$i]} \
+						>>$seqres.full 2>&1
+				else
+					break
+				fi
+			done
+		fi
+	done
+done
+
+# round 1: test mixed of inline and shared xattrs (default)
+_scratch_unmount
+MKFS_OPTIONS="$MKFS_OPTIONS"
+_scratch_mkfs $localdir >> $seqres.full 2>&1 || _fail "failed to mkfs"
+_scratch_mount 2>>$seqres.full
+_check_xattrs $localdir $SCRATCH_MNT
+
+# round 2: test shared xattrs
+_scratch_unmount
+MKFS_OPTIONS="$MKFS_OPTIONS -x1"
+_scratch_mkfs $localdir >> $seqres.full 2>&1 || _fail "failed to mkfs"
+_scratch_mount 2>>$seqres.full
+_check_xattrs $localdir $SCRATCH_MNT
+
+_scratch_unmount
+
+echo Silence is golden
+status=0
+exit 0
diff --git a/tests/erofs/023.out b/tests/erofs/023.out
new file mode 100644
index 0000000..5c4197b
--- /dev/null
+++ b/tests/erofs/023.out
@@ -0,0 +1,2 @@
+QA output created by 023
+Silence is golden
-- 
1.8.3.1


  reply	other threads:[~2023-06-14  3:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-14  3:26 [PATCH 1/2] erofs-utils: tests: check xattrs for all descendants under target directory Jingbo Xu
2023-06-14  3:26 ` Jingbo Xu [this message]
2023-06-14  7:49 ` Gao Xiang

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=20230614032642.8186-2-jefflexu@linux.alibaba.com \
    --to=jefflexu@linux.alibaba.com \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=huyue2@coolpad.com \
    --cc=linux-erofs@lists.ozlabs.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox