From: Karel Zak Date: Thu, 11 Dec 2025 12:42:02 +0000 (+0100) Subject: tests: convert fallocate to use subtests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d5f4bb9230be43fb17d6ff1e95df2a498eaed23;p=thirdparty%2Futil-linux.git tests: convert fallocate to use subtests Convert the fallocate test to use subtests pattern following the waitpid test example. This allows testing multiple scenarios in a single test run. Subtests: - alloc: Basic allocation test (original test) - report-data-holes: Report holes before digging (data holes) - dig-holes: Convert data holes to sparse holes with verbose output - report-file-holes: Report holes after digging (file holes) The test reuses the same image file across dig/report subtests to efficiently test the complete workflow: report → dig → report. Uses placeholder instead of absolute paths in expected output to ensure tests work from any directory. Signed-off-by: Karel Zak --- diff --git a/tests/expected/misc/fallocate b/tests/expected/misc/fallocate-alloc similarity index 100% rename from tests/expected/misc/fallocate rename to tests/expected/misc/fallocate-alloc diff --git a/tests/expected/misc/fallocate-dig-holes b/tests/expected/misc/fallocate-dig-holes new file mode 100644 index 0000000000..7cfe843d4e --- /dev/null +++ b/tests/expected/misc/fallocate-dig-holes @@ -0,0 +1 @@ +: 1 holes, 1 MiB (1048576 bytes, 33.33% of the file) converted to sparse holes. diff --git a/tests/expected/misc/fallocate-report-data-holes b/tests/expected/misc/fallocate-report-data-holes new file mode 100644 index 0000000000..077fa61f3c --- /dev/null +++ b/tests/expected/misc/fallocate-report-data-holes @@ -0,0 +1,4 @@ + +Summary: +file holes: 0 holes, 0 B (0 bytes, 0.00% of the file) +data holes: 1 holes, 1 MiB (1048576 bytes, 33.33% of the file) diff --git a/tests/expected/misc/fallocate-report-file-holes b/tests/expected/misc/fallocate-report-file-holes new file mode 100644 index 0000000000..573a566511 --- /dev/null +++ b/tests/expected/misc/fallocate-report-file-holes @@ -0,0 +1,4 @@ + +Summary: +file holes: 1 holes, 1 MiB (1048576 bytes, 33.33% of the file) +data holes: 0 holes, 0 B (0 bytes, 0.00% of the file) diff --git a/tests/ts/misc/fallocate b/tests/ts/misc/fallocate index 07efd987d9..fbab4c0780 100755 --- a/tests/ts/misc/fallocate +++ b/tests/ts/misc/fallocate @@ -12,7 +12,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -TS_TOPDIR="${0%/*}/../.." + TS_TOPDIR="${0%/*}/../.." TS_DESC="fallocate" . "$TS_TOPDIR"/functions.sh @@ -22,6 +22,11 @@ ts_check_test_command "$TS_CMD_FALLOCATE" ts_check_test_command "$TS_CMD_FINDMNT" IMAGE=${TS_OUTDIR}/${TS_TESTNAME}.file + +# +# Basic allocation test +# +ts_init_subtest "alloc" rm -f $IMAGE if $TS_CMD_FALLOCATE -o 128 -l 256 $IMAGE >> $TS_OUTPUT 2>> $TS_ERRLOG; then @@ -34,6 +39,40 @@ else && ts_skip "'${fs_type}' not supported" fi +rm -f $IMAGE +ts_finalize_subtest + +# +# Create test file with data and zeros for dig/report tests +# +rm -f $IMAGE +{ + dd if=/dev/zero bs=1M count=1 2>/dev/null | tr '\000' '\252' + dd if=/dev/zero bs=1M count=1 2>/dev/null + dd if=/dev/zero bs=1M count=1 2>/dev/null | tr '\000' '\125' +} > $IMAGE + +# +# Report holes - initial state with data holes +# +ts_init_subtest "report-data-holes" +$TS_CMD_FALLOCATE --report-holes $IMAGE >> $TS_OUTPUT 2>> $TS_ERRLOG +ts_finalize_subtest + +# +# Dig holes with verbose +# +ts_init_subtest "dig-holes" +$TS_CMD_FALLOCATE --dig-holes -v $IMAGE 2>> $TS_ERRLOG | sed "s|$IMAGE||g" >> $TS_OUTPUT +ts_finalize_subtest + +# +# Report holes after digging - should show file holes +# +ts_init_subtest "report-file-holes" +$TS_CMD_FALLOCATE --report-holes $IMAGE >> $TS_OUTPUT 2>> $TS_ERRLOG +ts_finalize_subtest + rm -f $IMAGE ts_finalize