]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: add subtest status tracking to ts_finalize_subtest
authorKarel Zak <kzak@redhat.com>
Wed, 6 May 2026 11:19:11 +0000 (13:19 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 11 May 2026 09:06:04 +0000 (11:06 +0200)
Add TS_SUBFAILED and TS_SUBSKIPPED flags that are set by
ts_failed_subtest and ts_skip_subtest respectively, and
cleared by ts_init_subtest.

ts_finalize_subtest now checks these flags before running the
diff comparison. If the subtest was already marked as failed or
skipped, it respects that status instead of unconditionally
running ts_gen_diff (which could report OK over a previous
failure).

Remove ts_init_core_env from ts_skip_subtest — environment
reset is now handled exclusively by ts_finalize_subtest, making
ts_init_subtest/ts_finalize_subtest the only paired open/close
for every subtest.

Add runtime guards: ts_init_subtest and ts_finalize both call
ts_failed if TS_SUBNAME is still set from a previous subtest
that was never finalized. This makes missing ts_finalize_subtest
calls a hard test failure, detectable in CI.

Signed-off-by: Karel Zak <kzak@redhat.com>
tests/functions.sh

index 66831afbb752b77eff17c7b9732a6ff2a11a9aa8..2585d78216f47561ee208da7f57d5f4667bbdf0d 100644 (file)
@@ -193,6 +193,9 @@ function ts_runs_on_qemu {
 function ts_failed_subtest {
        local msg="FAILED"
        local ret=1
+
+       TS_SUBFAILED="yes"
+
        if [ "$TS_KNOWN_FAIL" = "yes" ]; then
                msg="KNOWN FAILED"
                ret=0
@@ -458,7 +461,13 @@ function ts_init_env {
 
 function ts_init_subtest {
 
+       if [ -n "$TS_SUBNAME" ]; then
+               ts_failed "BUG: subtest '$TS_SUBNAME' not finalized"
+       fi
+
        TS_SUBNAME="$1"
+       TS_SUBFAILED=""
+       TS_SUBSKIPPED=""
        ts_init_core_subtest_env
        TS_NSUBTESTS=$(( $TS_NSUBTESTS + 1 ))
 
@@ -632,12 +641,18 @@ function tt_gen_mem_report {
 function ts_finalize_subtest {
        local res=0
 
-       ts_gen_diff
-       if [ $? -eq 1 ]; then
-               ts_failed_subtest "$1"
+       if [ "$TS_SUBSKIPPED" = "yes" ]; then
+               :
+       elif [ "$TS_SUBFAILED" = "yes" ]; then
                res=1
        else
-               ts_report_ok "$(tt_gen_mem_report "$1")"
+               ts_gen_diff
+               if [ $? -eq 1 ]; then
+                       ts_failed_subtest "$1"
+                       res=1
+               else
+                       ts_report_ok "$(tt_gen_mem_report "$1")"
+               fi
        fi
 
        [ $res -ne 0 ] && TS_NSUBFAILED=$(( $TS_NSUBFAILED + 1 ))
@@ -649,10 +664,8 @@ function ts_finalize_subtest {
 }
 
 function ts_skip_subtest {
+       TS_SUBSKIPPED="yes"
        ts_report_skip "$1"
-       # reset environment back to parental test
-       ts_init_core_env
-
 }
 
 # Specify the kernel version X.Y.Z you wish to compare against like:
@@ -679,6 +692,10 @@ function ts_kernel_ver_lt {
 function ts_finalize {
        ts_cleanup_on_exit
 
+       if [ -n "$TS_SUBNAME" ]; then
+               ts_failed "BUG: subtest '$TS_SUBNAME' not finalized"
+       fi
+
        if [ $TS_NSUBTESTS -ne 0 ]; then
                if ! ts_gen_diff || [ $TS_NSUBFAILED -ne 0 ]; then
                        ts_failed "$TS_NSUBFAILED from $TS_NSUBTESTS sub-tests"