[PATCH 2/2] erofs-utils: tests: add test for xattr

Huang Jianan huangjianan at oppo.com
Tue Dec 14 20:52:02 AEDT 2021


Add basic function check for xattr.

Signed-off-by: Huang Jianan <huangjianan at oppo.com>
---
 tests/Makefile.am   |  3 +++
 tests/erofs/019     | 63 +++++++++++++++++++++++++++++++++++++++++++++
 tests/erofs/019.out |  2 ++
 3 files changed, 68 insertions(+)
 create mode 100755 tests/erofs/019
 create mode 100644 tests/erofs/019.out

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6eeaece..da3e888 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -82,6 +82,9 @@ TESTS += erofs/017
 # 018 - verify lzma compressed image
 TESTS += erofs/018
 
+# 019 - check the xattr functionality
+TESTS += erofs/019
+
 EXTRA_DIST = common/rc erofs
 
 clean-local: clean-local-check
diff --git a/tests/erofs/019 b/tests/erofs/019
new file mode 100755
index 0000000..5e182a0
--- /dev/null
+++ b/tests/erofs/019
@@ -0,0 +1,63 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+
+# get standard environment, filters and checks
+. "${srcdir}/common/rc"
+
+cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+}
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+echo "QA output created by $seq"
+
+_require_erofs
+
+[ -z "$lz4_on" ] && \
+	_notrun "lz4 compression is disabled, skipped."
+
+have_xattr=`which xattr`
+[ -z "$have_xattr" ] && \
+	_notrun "xattr 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 xattr
+cp -nR ../ $localdir
+dirs=`ls $localdir`
+for d in $dirs; do
+	key=`head -20 /dev/urandom | cksum | cut -f1 -d " "`
+	val=`head -20 /dev/urandom | cksum | cut -f1 -d " "`
+	xattr -w user.$key $val $localdir/$d
+done
+
+_scratch_mkfs $localdir || _fail "failed to mkfs"
+
+# check xattr
+_scratch_mount 2>>$seqres.full
+
+for d in $dirs; do
+	xattr1=`xattr -l $localdir/$d`
+	xattr2=`xattr -l $SCRATCH_MNT/$d`
+	[ "$xattr1" = "$xattr2" ] || _fail "-->check xattr FAILED"
+done
+
+_scratch_unmount
+
+echo Silence is golden
+status=0
+exit 0
diff --git a/tests/erofs/019.out b/tests/erofs/019.out
new file mode 100644
index 0000000..163484b
--- /dev/null
+++ b/tests/erofs/019.out
@@ -0,0 +1,2 @@
+QA output created by 019
+Silence is golden
-- 
2.25.1



More information about the Linux-erofs mailing list