]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: convert fallocate to use subtests
authorKarel Zak <kzak@redhat.com>
Thu, 11 Dec 2025 12:42:02 +0000 (13:42 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 11 Dec 2025 12:42:02 +0000 (13:42 +0100)
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 <testfile> placeholder instead of absolute paths in expected
output to ensure tests work from any directory.

Signed-off-by: Karel Zak <kzak@redhat.com>
tests/expected/misc/fallocate-alloc [moved from tests/expected/misc/fallocate with 100% similarity]
tests/expected/misc/fallocate-dig-holes [new file with mode: 0644]
tests/expected/misc/fallocate-report-data-holes [new file with mode: 0644]
tests/expected/misc/fallocate-report-file-holes [new file with mode: 0644]
tests/ts/misc/fallocate

diff --git a/tests/expected/misc/fallocate-dig-holes b/tests/expected/misc/fallocate-dig-holes
new file mode 100644 (file)
index 0000000..7cfe843
--- /dev/null
@@ -0,0 +1 @@
+<testfile>: 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 (file)
index 0000000..077fa61
--- /dev/null
@@ -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 (file)
index 0000000..573a566
--- /dev/null
@@ -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)
index 07efd987d90fddf20030ebaedc93c1d9042ea33e..fbab4c0780396df58fb2ed38b9882374c86e7197 100755 (executable)
@@ -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|<testfile>|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