Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Baokun Li <libaokun@linux.alibaba.com>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz,
	yi.zhang@huawei.com, ojaswin@linux.ibm.com,
	ritesh.list@gmail.com
Subject: [PATCH e2fsprogs 4/5] tests: add fsck option-parsing regression test
Date: Tue, 14 Jul 2026 14:31:35 +0800	[thread overview]
Message-ID: <20260714063136.1284287-5-libaokun@linux.alibaba.com> (raw)
In-Reply-To: <20260714063136.1284287-1-libaokun@linux.alibaba.com>

Add f_fsck_opt_parse, which runs the fsck wrapper in dry-run mode
(-N) with -V so it echoes the exact argv it builds for the checker,
and asserts the wrapper:

  - consumes the util-linux "-l" (lockdisk) option instead of leaking
    it to e2fsck, where -l takes a bad-blocks-file argument and would
    swallow the following option; and
  - parses "-C 2" (progress fd as a separate argument) into "-C2"
    instead of dropping it and leaking "2" as a stray device name.

Signed-off-by: Baokun Li <libaokun@linux.alibaba.com>
---
 tests/f_fsck_opt_parse/expect.1 |  2 ++
 tests/f_fsck_opt_parse/name     |  1 +
 tests/f_fsck_opt_parse/script   | 61 +++++++++++++++++++++++++++++++++
 tests/test_config               |  2 ++
 4 files changed, 66 insertions(+)
 create mode 100644 tests/f_fsck_opt_parse/expect.1
 create mode 100644 tests/f_fsck_opt_parse/name
 create mode 100644 tests/f_fsck_opt_parse/script

diff --git a/tests/f_fsck_opt_parse/expect.1 b/tests/f_fsck_opt_parse/expect.1
new file mode 100644
index 000000000000..10b716cd16a2
--- /dev/null
+++ b/tests/f_fsck_opt_parse/expect.1
@@ -0,0 +1,2 @@
+[fsck.ext4 (1) -- test.img] fsck.ext4 -f -C2 test.img 
+Exit status is 0
diff --git a/tests/f_fsck_opt_parse/name b/tests/f_fsck_opt_parse/name
new file mode 100644
index 000000000000..37135f686288
--- /dev/null
+++ b/tests/f_fsck_opt_parse/name
@@ -0,0 +1 @@
+fsck wrapper consumes -l and parses "-C fd" as a separate argument
diff --git a/tests/f_fsck_opt_parse/script b/tests/f_fsck_opt_parse/script
new file mode 100644
index 000000000000..92597ac11754
--- /dev/null
+++ b/tests/f_fsck_opt_parse/script
@@ -0,0 +1,61 @@
+if ! test -x $FSCK_WRAPPER_EXE; then
+	echo "$test_name: $test_description: skipped (no fsck wrapper)"
+	return 0
+fi
+
+OUT=$test_name.log
+
+$MKE2FS -Fq -t ext4 -o Linux $TMPFILE 4M > /dev/null 2>&1
+
+# The fsck wrapper resolves fsck.<type> via a fixed search path
+# (/sbin:...:$PATH).  Provide our own fsck.ext4 on $PATH as a fallback so a
+# checker is always found even in a clean build tree with none installed.  A
+# system /sbin/fsck.ext4, if present, is searched first and used instead, but
+# either way the printed path is normalized by filter.sed below.
+WRAPPER_DIR="$test_name.fsckdir"
+mkdir -p $WRAPPER_DIR
+ln -sf "$(cd ../e2fsck && pwd)/e2fsck" $WRAPPER_DIR/fsck.ext4
+SAVED_PATH="$PATH"
+export PATH="$WRAPPER_DIR:$PATH"
+
+# Suppress "WARNING: couldn't open /etc/fstab" from the fsck wrapper.
+SAVED_FSTAB_FILE="${FSTAB_FILE-unset}"
+export FSTAB_FILE=/dev/null
+
+cp /dev/null $OUT
+
+# Dry run (-N) so no checker is executed; -V echoes the exact argv the
+# wrapper builds for the checker, which is what we are asserting.  -T
+# suppresses the version banner so the output is stable across releases.
+#
+#   -l       lockdisk option from util-linux; the wrapper must consume it
+#            rather than leak it to e2fsck (where -l takes a bad-blocks-file
+#            argument and would swallow the following option).
+#   -C 2     progress fd given as a separate argument; the wrapper must read
+#            the "2" and emit "-C2", not drop it and leak "2" as a device.
+$FSCK_WRAPPER -N -T -V -f -l -C 2 $TMPFILE > $OUT.new 2>&1
+status=$?
+echo "Exit status is $status" >> $OUT.new
+sed -f $cmd_dir/filter.sed \
+	-e "s|$TMPFILE|test.img|g" \
+	-e "s|\[[^]]*fsck\.ext4|[fsck.ext4|g" $OUT.new > $OUT
+rm -f $OUT.new
+
+cmp -s $OUT $test_dir/expect.1
+status=$?
+if [ "$status" -eq 0 ]; then
+	echo "$test_name: $test_description: ok"
+	touch $test_name.ok
+else
+	echo "$test_name: $test_description: failed"
+	diff $DIFF_OPTS $test_dir/expect.1 $OUT > $test_name.failed
+fi
+
+export PATH="$SAVED_PATH"
+if [ "$SAVED_FSTAB_FILE" = "unset" ]; then
+	unset FSTAB_FILE
+else
+	export FSTAB_FILE="$SAVED_FSTAB_FILE"
+fi
+rm -rf $WRAPPER_DIR
+unset OUT SAVED_PATH SAVED_FSTAB_FILE
diff --git a/tests/test_config b/tests/test_config
index 9dc762ce5a88..cb2654d59266 100644
--- a/tests/test_config
+++ b/tests/test_config
@@ -13,6 +13,8 @@ E2IMAGE="$USE_VALGRIND ../misc/e2image"
 E2IMAGE_EXE="../misc/e2image"
 DEBUGFS="$USE_VALGRIND ../debugfs/debugfs"
 DEBUGFS_EXE="../debugfs/debugfs"
+FSCK_WRAPPER="$USE_VALGRIND ../misc/fsck"
+FSCK_WRAPPER_EXE="../misc/fsck"
 TEST_BITS="test_data.tmp"
 RESIZE2FS_EXE="../resize/resize2fs"
 RESIZE2FS="$USE_VALGRIND $RESIZE2FS_EXE"
-- 
2.43.7


  parent reply	other threads:[~2026-07-14  6:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14  6:31 [PATCH e2fsprogs 0/5] fsck: fix stale "bad orphan inode" after fsck runs Baokun Li
2026-07-14  6:31 ` [PATCH e2fsprogs 1/5] fsck: consume -l option instead of passing to e2fsck Baokun Li
2026-07-14  6:31 ` [PATCH e2fsprogs 2/5] fsck: fix -C fd option parsing when fd is a separate argument Baokun Li
2026-07-14  6:31 ` [PATCH e2fsprogs 3/5] e2fsck: flush superblock immediately after orphan cleanup Baokun Li
2026-07-14  6:31 ` Baokun Li [this message]
2026-07-14  6:31 ` [PATCH e2fsprogs 5/5] tests: add orphan-cleanup flush regression test Baokun Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260714063136.1284287-5-libaokun@linux.alibaba.com \
    --to=libaokun@linux.alibaba.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox