[PATCH] erofs-utils: tests: add test for long xattr name prefixes

Gao Xiang hsiangkao at linux.alibaba.com
Tue Apr 11 19:48:53 AEST 2023



On 2023/4/11 17:46, Jingbo Xu wrote:
> mkfs.erofs supports user specified long xattr name prefix through
> "--xattr_prefixes" option.

--xattr_prefix?

> 
> Add test case for this feature.
> 
> Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
> ---
> The long xattr name prefix feature is introduced to erofs-utils by
> https://lore.kernel.org/all/20230407140902.97275-1-jefflexu@linux.alibaba.com/
> 
> The corresponding kernel patches are at
> https://lore.kernel.org/all/20230407141710.113882-1-jefflexu@linux.alibaba.com/
> ---
>   tests/Makefile.am   |  3 ++
>   tests/erofs/021     | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>   tests/erofs/021.out |  2 ++
>   3 files changed, 92 insertions(+)
>   create mode 100755 tests/erofs/021
>   create mode 100644 tests/erofs/021.out
> 
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 67e2bbc..791cd67 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -94,6 +94,9 @@ TESTS += erofs/019
>   # 020 - check extended attribute in different layouts
>   TESTS += erofs/020
>   
> +# 021 - check long extended attribute name prefix

# 021 - check long extended attribute name prefixes

> +TESTS += erofs/021
> +
>   EXTRA_DIST = common/rc erofs
>   
>   clean-local: clean-local-check
> diff --git a/tests/erofs/021 b/tests/erofs/021
> new file mode 100755
> index 0000000..5feffd4
> --- /dev/null
> +++ b/tests/erofs/021
> @@ -0,0 +1,87 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0+
> +#
> +# 021 - check long extended attribute name prefix

# 021 - check long extended attribute name prefixes

> +#
> +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.infix.p$(generate_random 16) -v $(generate_random 16) $localdir/file1
> +setfattr -n user.infix.p$(generate_random 16) -v $(generate_random 16) $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.infix.s$s_key_1 -v $s_val $localdir/file2
> +setfattr -n user.infix.s$s_key_2 -v $s_val $localdir/file2
> +
> +# file3: mixed inline and share xattrs
> +touch $localdir/file3
> +setfattr -n user.infix.p$(generate_random 16) -v $(generate_random 16) $localdir/file3
> +setfattr -n user.infix.s$s_key_1 -v $s_val $localdir/file3
> +
> +# file4: share xattr
> +touch $localdir/file4
> +setfattr -n user.infix.s$s_key_2 -v $s_val $localdir/file4
> +
> +# specify long xattr name prefix through "--xattr-prefix"
> +MKFS_OPTIONS="$MKFS_OPTIONS -x1 --xattr-prefix=user.infix."
> +_scratch_mkfs $localdir >> $seqres.full 2>&1 || _fail "failed to mkfs"
> +_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/021.out b/tests/erofs/021.out
> new file mode 100644
> index 0000000..09f4062
> --- /dev/null
> +++ b/tests/erofs/021.out
> @@ -0,0 +1,2 @@
> +QA output created by 021
> +Silence is golden


More information about the Linux-erofs mailing list