Skip to contentSkip to conversation

erofs-utils: tests: cover the canonical xattr order

PATCH In review Martin Pitt 2 participants 6 messages Aug 4 – Aug 27

lore
Share & tools
lore
#0 lore raw

cover erofs-utils: tests: cover the canonical xattr order

A test for b260119b8edb ("erofs-utils: mkfs: emit an inode's xattrs in a canonical order"), plus two portability fixes that I ran into along the way. Based on experimental-tests (a3b00c4).

The test stages the same tree twice with the same attributes set in opposite order and compares the two images, so it needs neither root nor a mount. It is red without b260119b8edb and green with it. That commit is currently only in experimental, so the test fails as long as experimental-tests is run without it.

Martin Pitt (3):
erofs-utils: tests: fix broken loop in POSIX shells
erofs-utils: tests: look up programs with command -v
erofs-utils: tests: check that the xattr layout is order-independent

 tests/Makefile.am   |  5 ++-
 tests/common/rc     |  8 ++---
 tests/erofs/021     |  2 +-
 tests/erofs/028     |  6 ++--
 tests/erofs/032     | 77 +++++++++++++++++++++++++++++++++++++++++++++
 tests/erofs/032.out |  2 ++
 6 files changed, 91 insertions(+), 9 deletions(-)
 create mode 100755 tests/erofs/032
 create mode 100644 tests/erofs/032.out
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/3 erofs-utils: tests: fix broken loop in POSIX shells

{1..n} is a bashism. A POSIX shell iterates once over that literal string, so the test silently sets a single attribute instead of three and nothing crosses the block boundary any more. Sadly, seq is also not POSIX (although ubiquitous).

Spell out the loop.

---
 tests/erofs/021 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/erofs/021 +1 -1
index d36aa56..b77a8d7 100755
@@ -39,7 +39,7 @@ mkdir -p $localdir
 # cross the block boundary; besides set three xattrs to ensure at least
 # one xattr name crosses the block boundary
 touch $localdir/file1
-for i in {1..3}; do
+for i in 1 2 3; do
 	setfattr -n user.p$(_random 249) -v $(_random 512) $localdir/file1 \
 		|| _notrun "no space for xattrs"
 done
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/3 erofs-utils: tests: look up programs with command -v

In reply to Martin Pitt

which stopped being installed by default in recent distros, and it is not needed at all. Use the POSIX command -v instead.

Drop a doubled "unless" from the POSIX compliant note.

---
 tests/Makefile.am | 2 +-
 tests/common/rc   | 8 ++++----
 tests/erofs/028   | 6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)
tests/Makefile.am +1 -1
index 2f109b8..c0291ac 100644
@@ -137,7 +137,7 @@ TESTS += erofs/031
 
 # NOTE: When adding a new test case or updating an existing one, please write
 # POSIX-compliant shell scripts and avoid using Linux-specific features unless
-# unless the test case is expected to run only on Linux platforms.
+# the test case is expected to run only on Linux platforms.
 
 EXTRA_DIST = common/rc erofs
 
tests/common/rc +4 -4
index 78e704d..aa7ef99 100644
@@ -48,10 +48,10 @@ _fatal()
     exit 1
 }
 
-export MOUNT_PROG="$(which mount)"
+export MOUNT_PROG="$(command -v mount)"
 [ "$MOUNT_PROG" = "" ] && _fatal "mount not found"
 
-export UMOUNT_PROG="$(which umount)"
+export UMOUNT_PROG="$(command -v umount)"
 [ "$UMOUNT_PROG" = "" ] && _fatal "umount not found"
 [ "$MKFS_EROFS_PROG" = "" ] && _fatal "mkfs.erofs not found"
 
@@ -94,7 +94,7 @@ _require_root()
 
 _require_xattr()
 {
-	which setfattr >/dev/null 2>&1 ||
+	command -v setfattr >/dev/null 2>&1 ||
 		_notrun "attr isn't installed, skipped."
 }
 
@@ -309,7 +309,7 @@ _do_unmount()
 {
 	local mnt_path=$1
 
-	if [ "$FSTYP" = "erofsfuse" -a "$(which fusermount > /dev/null && echo ok)" = "ok" ]; then
+	if [ "$FSTYP" = "erofsfuse" ] && command -v fusermount > /dev/null 2>&1; then
 		fusermount -u $mnt_path
 	else
 		$UMOUNT_PROG $mnt_path
tests/erofs/028 +3 -3
index bf31c3f..05d9a5e 100755
@@ -42,9 +42,9 @@ check_ishare()
 _require_erofs
 _require_erofs_inode_sharing
 _require_erofs_compression "-zlz4"
-which strace > /dev/null 2>&1 || _notrun "strace is not found"
-which fincore > /dev/null 2>&1 || _notrun "fincore is not found"
-which fadvise > /dev/null 2>&1 || _notrun "fadvise is not found"
+command -v strace > /dev/null 2>&1 || _notrun "strace is not found"
+command -v fincore > /dev/null 2>&1 || _notrun "fincore is not found"
+command -v fadvise > /dev/null 2>&1 || _notrun "fadvise is not found"
 
 # remove previous $seqres.full before test
 rm -f $seqres.full
Signature · 1 line
2.55.0
#3 lore raw

PATCH 3/3 erofs-utils: tests: check that the xattr layout is order-independent

In reply to Martin Pitt

b260119b8edb ("erofs-utils: mkfs: emit an inode's xattrs in a canonical order") made the layout independent of the order listxattr(2) reports an inode's attributes in. Cover it: stage the same tree twice with the same attributes set in opposite order, and compare the two images. The names differ in length and share prefixes, so a subtly wrong comparison cannot order them correctly by accident.

---
 tests/Makefile.am   |  3 ++
 tests/erofs/032     | 77 +++++++++++++++++++++++++++++++++++++++++++++
 tests/erofs/032.out |  2 ++
 3 files changed, 82 insertions(+)
 create mode 100755 tests/erofs/032
 create mode 100644 tests/erofs/032.out
tests/Makefile.am +3 -0
index c0291ac..363b93d 100644
@@ -132,6 +132,9 @@ TESTS += erofs/030
 # 031 - test chunk-based mapping with shared chunks across inodes
 TESTS += erofs/031
 
+# 032 - check that the xattr layout does not depend on listxattr(2) order
+TESTS += erofs/032
+
 # NEW TEST CASE HERE
 # TESTS += erofs/999
 
tests/erofs/032 new file +77 -0

77 lines not on this page · raw message

tests/erofs/032.out new file +2 -0
new file mode 100644
index 0000000..34e059f
@@ -0,0 +1,2 @@
+QA output created by 032
+Silence is golden
Signature · 1 line
2.55.0
#4 lore raw

Re: [PATCH 3/3] erofs-utils: tests: check that the xattr layout is order-independent

Hello again,

Martin Pitt [2026-08-04 5:32 +0200]:

Quoted 6 lines

b260119b8edb ("erofs-utils: mkfs: emit an inode's xattrs in a canonical order") made the layout independent of the order listxattr(2) reports an inode's attributes in. Cover it: stage the same tree twice with the same attributes set in opposite order, and compare the two images. The names differ in length and share prefixes, so a subtly wrong comparison cannot order them correctly by accident.

I see my first [1] and second [2] preparatory patch made it into the tree [3][4], but not this third one (and the main test).

Do you want me to explain or change anything, or did it simply fell through the cracks?

Thank you!

Martin

[1] https://lore.kernel.org/linux-erofs/[email protected]/
[2] https://lore.kernel.org/linux-erofs/[email protected]/
[3] https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=experimental-tests&id=4b02ea1792c14cb9f250bd55aced5614e699397a
[4] https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=experimental-tests&id=887ce207bc8b068de9771b736333a8da6d939670

#5 lore raw

Re: [PATCH 3/3] erofs-utils: tests: check that the xattr layout is order-independent

Hi Martin,

Quoted 10 lines · Martin Pitt

Hello again,

Martin Pitt [2026-08-04 5:32 +0200]:

Quoted 6 lines

b260119b8edb ("erofs-utils: mkfs: emit an inode's xattrs in a canonical order") made the layout independent of the order listxattr(2) reports an inode's attributes in. Cover it: stage the same tree twice with the same attributes set in opposite order, and compare the two images. The names differ in length and share prefixes, so a subtly wrong comparison cannot order them correctly by accident.

Quoted 5 lines

I see my first [1] and second [2] preparatory patch made it into the tree [3][4], but not this third one (and the main test).

Do you want me to explain or change anything, or did it simply fell through the cracks?

I didn't miss this one, there are also other pending tests in my queue, I need to resolve them all but maybe a bit delay.

It's already merged with very minor changes.

Thanks,
Gao Xiang

Quoted 10 lines

Thank you!

Martin

[1] https://lore.kernel.org/linux-erofs/[email protected]/
[2] https://lore.kernel.org/linux-erofs/[email protected]/
[3] https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=experimental-tests&id=4b02ea1792c14cb9f250bd55aced5614e699397a
[4] https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=experimental-tests&id=887ce207bc8b068de9771b736333a8da6d939670