[PATCH v2] erofs-utils: tests: add test for xattrs in different layouts

Jingbo Xu jefflexu at linux.alibaba.com
Mon Mar 27 23:39:26 AEDT 2023


Test xattr in following layouts:

- multiple inline xattrs for one single file
- multiple share xattrs for one single file
- mixed inline and share xattrs for one single file
- name/value field of xattr crossing block boundary

Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
---
changes since v1:
- make this test a new testcase, aka. erofs/020
- make it compatible with erofs-utils that doesn't support '-b
  #blocksize' feature yet. Now the testcase will try mkfs with '-b 1024'
  first, and retry with '-b 1024' dropped if the previous attempt fails.
---
 tests/Makefile.am   |  3 ++
 tests/erofs/020     | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/erofs/020.out |  2 ++
 3 files changed, 100 insertions(+)
 create mode 100755 tests/erofs/020
 create mode 100644 tests/erofs/020.out

diff --git a/tests/Makefile.am b/tests/Makefile.am
index b85ae89..67e2bbc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -91,6 +91,9 @@ TESTS += erofs/018
 # 019 - check extended attribute functionality
 TESTS += erofs/019
 
+# 020 - check extended attribute in different layouts
+TESTS += erofs/020
+
 EXTRA_DIST = common/rc erofs
 
 clean-local: clean-local-check
diff --git a/tests/erofs/020 b/tests/erofs/020
new file mode 100755
index 0000000..8b345bf
--- /dev/null
+++ b/tests/erofs/020
@@ -0,0 +1,95 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0+
+#
+# 020 - check extended attribute in different layouts
+#
+set -x
+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.*
+}
+
+generate_random()
+{
+	head -20 /dev/urandom | base64 -w0 | head -c $1
+}
+
+_require_erofs
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+echo "QA output created by $seq"
+
+have_attr=`which setfattr`
+[ -z "$have_attr" ] && \
+	_notrun "attr isn't installed, skipped."
+
+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
+
+# set random xattrs
+
+# file1: multiple inline xattrs
+touch $localdir/file1
+setfattr -n user.p$(generate_random 16) -v $(generate_random 16) $localdir/file1
+# inline xattr (large name/value crossing block boundary)
+setfattr -n user.p$(generate_random 249) -v $(generate_random 1024) $localdir/file1
+
+# file2: multiple share xattrs
+s_key_1=$(generate_random 16)
+s_key_2=$(generate_random 16)
+s_val=$(generate_random 16)
+
+touch $localdir/file2
+setfattr -n user.s$s_key_1 -v $s_val $localdir/file2
+setfattr -n user.s$s_key_2 -v $s_val $localdir/file2
+
+# file3: mixed inline and share xattrs
+touch $localdir/file3
+setfattr -n user.p$(generate_random 16) -v $(generate_random 16) $localdir/file3
+setfattr -n user.s$s_key_1 -v $s_val $localdir/file3
+
+# file4: share xattr
+touch $localdir/file4
+setfattr -n user.s$s_key_2 -v $s_val $localdir/file4
+
+# Specify 1024 blocksize explicitly so that the large name/value of file1
+# could cross the block boundary. Retry without '-b #blocksize' if mkfs.erofs
+# doesn't support this feature yet.
+BASE_MKFS_OPTIONS="$MKFS_OPTIONS -x1"
+MKFS_OPTIONS="$BASE_MKFS_OPTIONS -b1024"
+_scratch_mkfs $localdir >> $seqres.full 2>&1
+if [ $? -ne 0 ]; then
+	MKFS_OPTIONS="$BASE_MKFS_OPTIONS"
+	_scratch_mkfs $localdir >> $seqres.full 2>&1 || _fail "failed to mkfs"
+fi
+_scratch_mount 2>>$seqres.full
+
+# check xattrs
+dirs=`ls $localdir`
+for d in $dirs; do
+	xattr1=`getfattr --absolute-names -d $localdir/$d | tail -n+2`
+	xattr2=`getfattr --absolute-names -d $SCRATCH_MNT/$d | tail -n+2`
+	[ "x$xattr1" = "x$xattr2" ] || _fail "-->check xattrs FAILED"
+done
+
+_scratch_unmount
+
+echo Silence is golden
+status=0
+exit 0
diff --git a/tests/erofs/020.out b/tests/erofs/020.out
new file mode 100644
index 0000000..20d7944
--- /dev/null
+++ b/tests/erofs/020.out
@@ -0,0 +1,2 @@
+QA output created by 020
+Silence is golden
-- 
1.8.3.1



More information about the Linux-erofs mailing list