[PATCH experimental-tests] erofs-utils: tests: add test for rebuild fulldata

Lucas Karpinski <[email protected]>
Newsgroups org.ozlabs.lists.linux-erofs
Message-ID <[email protected]>
Add a regression test for building a self-contained image out of two other
erofs images.

1. Create img1 & img2 with various file types and sizes.
2. Rebuild a new self-contained image of img1 & img2.
3. Delete img1 & img2 to prove that this isn't use the blob based rebuild
   path.
4. Mount the new self-contained image and compare the checksum to the
   original folders.

Signed-off-by: Lucas Karpinski <[email protected]>
---
 tests/Makefile.am   |  3 ++
 tests/erofs/030     | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/erofs/030.out |  2 ++
 3 files changed, 93 insertions(+)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index d8ac0678..125aa8f6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -126,6 +126,9 @@ TESTS += erofs/028
 # 029 - test FUSE daemon and kernel error handling on corrupted inodes
 TESTS += erofs/029
 
+# 030 - verify multi-source fulldata rebuild
+TESTS += erofs/030
+
 # NEW TEST CASE HERE
 # TESTS += erofs/999
 
diff --git a/tests/erofs/030 b/tests/erofs/030
new file mode 100755
index 00000000..8111be10
--- /dev/null
+++ b/tests/erofs/030
@@ -0,0 +1,88 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0+
+#
+# verify multi-source fulldata rebuild merges multiple EROFS images into
+# a single self-contained image
+#
+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_fssum
+
+# 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
+
+src1dir="$tmp/$seq.src1"
+src2dir="$tmp/$seq.src2"
+combdir="$tmp/$seq.combined"
+img1="$tmp/$seq.img1"
+img2="$tmp/$seq.img2"
+
+rm -rf $src1dir $src2dir $combdir
+rm -f $img1 $img2
+
+# Two source trees that share a top-level `common/` directory so the
+# rebuild must merge directories, with otherwise disjoint contents.
+mkdir -p $src1dir/tree1 $src1dir/common/only1
+printf "image 1 small file\n" > $src1dir/tree1/small
+printf "image 1 common\n" > $src1dir/common/only1/a.txt
+yes "image 1 payload" | head -c 65536 > $src1dir/tree1/big1
+ln $src1dir/tree1/small $src1dir/tree1/hardlink
+ln -s small $src1dir/tree1/symlink
+
+mkdir -p $src2dir/tree2 $src2dir/common/only2
+printf "image 2 file\n"   > $src2dir/tree2/file2.txt
+printf "image 2 common\n" > $src2dir/common/only2/b.txt
+yes "image 2 payload" | head -c 32768 > $src2dir/tree2/big2
+
+# combined reference tree
+mkdir -p $combdir
+cp -a $src1dir/. $combdir/
+cp -a $src2dir/. $combdir/
+
+# build two source EROFS images
+$MKFS_EROFS_PROG $img1 $src1dir >> $seqres.full 2>&1 || _fail "failed to create $img1"
+$MKFS_EROFS_PROG $img2 $src2dir >> $seqres.full 2>&1 || _fail "failed to create $img2"
+
+# multi-source fulldata rebuild
+$MKFS_EROFS_PROG --clean=data $SCRATCH_DEV $img1 $img2 >> $seqres.full 2>&1 || \
+	_fail "failed to rebuild merged image with --clean=data"
+$FSCK_EROFS_PROG --extract $SCRATCH_DEV >> $seqres.full 2>&1 || \
+	_fail "merged image failed integrity check"
+
+# remove both source images: the merged image must be self-contained
+rm -f $img1 $img2
+
+FSSUM_OPTS="-MAC"
+[ $FSTYP = "erofsfuse" ] && FSSUM_OPTS="${FSSUM_OPTS}T"
+
+_scratch_mount 2>>$seqres.full
+sum1=`$FSSUM_PROG $FSSUM_OPTS $combdir`
+sum2=`$FSSUM_PROG $FSSUM_OPTS $SCRATCH_MNT`
+echo "combined source checksum: $sum1" >>$seqres.full
+echo "merged image checksum: $sum2" >>$seqres.full
+_scratch_unmount
+
+[ "x$sum1" = "x$sum2" ] || _fail "multi-source fulldata rebuild mismatch"
+
+echo Silence is golden
+status=0
+exit 0
diff --git a/tests/erofs/030.out b/tests/erofs/030.out
new file mode 100644
index 00000000..06a1c8fe
--- /dev/null
+++ b/tests/erofs/030.out
@@ -0,0 +1,2 @@
+QA output created by 030
+Silence is golden

---
base-commit: feadb09fcfa1b05ca930cfce871d0e56f6bd3a95
change-id: 20260417-b4-fulldata-test-b8e15272bc59

Best regards,
-- 
Lucas Karpinski <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.