[PATCH 4/4] erofs-utils: tests: add test for fsck.erofs
Huang Jianan
jnhuang at linux.alibaba.com
Fri Sep 9 12:18:16 AEST 2022
Add basic functional check for fsck.erofs.
Signed-off-by: Huang Jianan <jnhuang at linux.alibaba.com>
---
tests/Makefile.am | 3 +++
tests/common/rc | 46 +++++++++++++++++++++++++++++++++
tests/erofs/022 | 62 +++++++++++++++++++++++++++++++++++++++++++++
tests/erofs/022.out | 2 ++
4 files changed, 113 insertions(+)
create mode 100755 tests/erofs/022
create mode 100644 tests/erofs/022.out
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bb1624d..25c1400 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -95,6 +95,9 @@ TESTS += erofs/019
# 021 - check dump basic functionality
TESTS += erofs/021
+# 021 - check fsck basic functionality
+TESTS += erofs/022
+
EXTRA_DIST = common/rc erofs
clean-local: clean-local-check
diff --git a/tests/common/rc b/tests/common/rc
index a9ae369..7b72573 100644
--- a/tests/common/rc
+++ b/tests/common/rc
@@ -189,6 +189,52 @@ _test_mkfs()
_mkfs $TEST_DEV "$*"
}
+_do_fsck()
+{
+ local fsck_cmd=$1
+ local fsck_filter=$2
+ local fsck_dev=$3
+ shift 3
+ local extra_fsck_options="$*"
+ local fsck_status
+ local tmp=`mktemp -u`
+
+ eval "$fsck_cmd $FSCK_OPTIONS $fsck_dev $extra_fsck_options" \
+ 1>$tmp.fsckstd 2>$tmp.fsckerr
+ fsck_status=$?
+
+ # output stored fsck output, filtering unnecessary output from stderr
+ cat $tmp.fsckstd
+ eval "cat $tmp.fsckerr | $fsck_filter" >&2
+
+ rm -f $tmp.fsckerr $tmp.fsckstd
+ return $fsck_status
+}
+
+_fsck()
+{
+ local fsck_dev=$1
+ shift 1
+ local extra_fsck_options="$*"
+ local fsck_cmd="$FSCK_EROFS_PROG"
+ local fsck_filter="true"
+
+ _do_fsck "$fsck_cmd" "$fsck_filter" "$fsck_dev" "$extra_fsck_options" \
+ 2>$tmp.fsckerr 1>$tmp.fsckstd
+ fsck_status=$?
+
+ # output fsck stdout and stderr
+ cat $tmp.fsckstd
+ cat $tmp.fsckerr >&2
+ rm -f $tmp.fsckerr $tmp.fsckstd
+
+ return $fsck_status
+}
+
+_scratch_fsck()
+{
+ _fsck $SCRATCH_DEV "$*"
+}
# Do the actual mount work.
_do_mount()
diff --git a/tests/erofs/022 b/tests/erofs/022
new file mode 100755
index 0000000..d3baf7a
--- /dev/null
+++ b/tests/erofs/022
@@ -0,0 +1,62 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0+
+#
+# 022 check fsck basic functionality
+#
+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_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
+
+localdir="$tmp/$seq"
+rm -rf $localdir
+mkdir -p $localdir
+
+# collect files pending for verification
+dirs=`find ../ -maxdepth 1 -type d -printf '%p:'`
+IFS=':'
+for d in $dirs; do
+ [ $d = '../' ] && continue
+ [ -z "${d##\.\./tests*}" ] && continue
+ [ -z "${d##\.\./\.*}" ] && continue
+ cp -nR $d $localdir
+done
+unset IFS
+
+_scratch_mkfs $localdir >> $seqres.full 2>&1 || _fail "failed to mkfs"
+
+extradir="$tmp/extra$seq"
+mkdir -p $extradir
+FSCK_OPTIONS="$FSCK_OPTIONS --extract=$extradir --preserve"
+_scratch_fsck >> $seqres.full 2>&1 || _fail "failed to fsck"
+
+sum1=`$FSSUM_PROG $FSSUM_OPTS $localdir`
+echo "$localdir checksum is $sum1" >>$seqres.full
+sum2=`$FSSUM_PROG $FSSUM_OPTS $extradir`
+echo "$extradir checksum is $sum2" >>$seqres.full
+
+[ "x$sum1" = "x$sum2" ] || _fail "-->checkMD5 FAILED"
+
+echo Silence is golden
+status=0
+exit 0
diff --git a/tests/erofs/022.out b/tests/erofs/022.out
new file mode 100644
index 0000000..394c6a7
--- /dev/null
+++ b/tests/erofs/022.out
@@ -0,0 +1,2 @@
+QA output created by 022
+Silence is golden
--
2.34.1
More information about the Linux-erofs
mailing list