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 --- 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. 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