[PATCH] selftests: Fix duplicated test number reporting

Mark Brown posted 1 patch 2 months ago
tools/testing/selftests/kselftest/runner.sh | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
[PATCH] selftests: Fix duplicated test number reporting
Posted by Mark Brown 2 months ago
Commit 2964f6b816c2 ("selftests: Use ktap helpers for runner.sh") converted
the prints in runner.sh to use the relevant helpers from ktap_helpers.sh,
not modifying any of the strings printed in the process. This included
converting all the result reports to use the relevant ktap_test_ function.
Since the output was originally KTAP compliant the strings reported for
test names now include test numbers:

  ok 59 59 selftests: arm64: syscall-abi

instead of the expected format:

  ok 59 selftests: arm64: syscall-abi

which causes result parsers to interpret the second number as part of the
test name.

Given the use of the helpers the tracking of test numbers by runner.sh is
now redundant, remove it entirely to restore the expected output format.

Fixes: 2964f6b816c2 ("selftests: Use ktap helpers for runner.sh")
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 tools/testing/selftests/kselftest/runner.sh | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
index 1115ee7e525c..311811dc55a0 100644
--- a/tools/testing/selftests/kselftest/runner.sh
+++ b/tools/testing/selftests/kselftest/runner.sh
@@ -51,7 +51,6 @@ run_one()
 {
 	DIR="$1"
 	TEST="$2"
-	local rc test_num="$3"
 
 	BASENAME_TEST=$(basename $TEST)
 
@@ -108,7 +107,7 @@ run_one()
 	echo "# $TEST_HDR_MSG"
 	if [ ! -e "$TEST" ]; then
 		ktap_print_msg "Warning: file $TEST is missing!"
-		ktap_test_fail "$test_num $TEST_HDR_MSG"
+		ktap_test_fail "$TEST_HDR_MSG"
 		rc=$KSFT_FAIL
 	else
 		if [ -x /usr/bin/stdbuf ]; then
@@ -127,7 +126,7 @@ run_one()
 				interpreter=$(head -n 1 "$TEST" | cut -c 3-)
 				cmd="$stdbuf $interpreter ./$BASENAME_TEST"
 			else
-				ktap_test_fail "$test_num $TEST_HDR_MSG"
+				ktap_test_fail "$TEST_HDR_MSG"
 				return $KSFT_FAIL
 			fi
 		fi
@@ -138,15 +137,15 @@ run_one()
 		rc=$?
 		case "$rc" in
 		"$KSFT_PASS")
-			ktap_test_pass "$test_num $TEST_HDR_MSG";;
+			ktap_test_pass "$TEST_HDR_MSG";;
 		"$KSFT_SKIP")
-			ktap_test_skip "$test_num $TEST_HDR_MSG";;
+			ktap_test_skip "$TEST_HDR_MSG";;
 		"$KSFT_XFAIL")
-			ktap_test_xfail "$test_num $TEST_HDR_MSG";;
+			ktap_test_xfail "$TEST_HDR_MSG";;
 		"$timeout_rc")
-			ktap_test_fail "$test_num $TEST_HDR_MSG # TIMEOUT $kselftest_timeout seconds";;
+			ktap_test_fail "$TEST_HDR_MSG # TIMEOUT $kselftest_timeout seconds";;
 		*)
-			ktap_test_fail "$test_num $TEST_HDR_MSG # exit=$rc";;
+			ktap_test_fail "$TEST_HDR_MSG # exit=$rc";;
 		esac
 		cd - >/dev/null
 	fi
@@ -161,7 +160,7 @@ in_netns()
 		BASE_DIR=$BASE_DIR
 		source $BASE_DIR/kselftest/runner.sh
 		logfile=$logfile
-		run_one $DIR $TEST $test_num
+		run_one $DIR $TEST
 	EOF
 }
 
@@ -174,7 +173,7 @@ run_in_netns()
 	ip netns add $netns
 	if [ $? -ne 0 ]; then
 		ktap_print_msg "Warning: Create namespace failed for $BASENAME_TEST"
-		ktap_test_fail "$test_num selftests: $DIR: $BASENAME_TEST # Create NS failed"
+		ktap_test_fail "selftests: $DIR: $BASENAME_TEST # Create NS failed"
 	fi
 	ip -n $netns link set lo up
 
@@ -191,13 +190,11 @@ run_in_netns()
 run_many()
 {
 	DIR="${PWD#${BASE_DIR}/}"
-	test_num=0
 	local rc
 	pids=
 
 	for TEST in "$@"; do
 		BASENAME_TEST=$(basename $TEST)
-		test_num=$(( test_num + 1 ))
 		if [ -n "$per_test_logging" ]; then
 			logfile="$per_test_log_dir/$BASENAME_TEST"
 			cat /dev/null > "$logfile"
@@ -206,7 +203,7 @@ run_many()
 			run_in_netns &
 			pids="$pids $!"
 		else
-			run_one "$DIR" "$TEST" "$test_num"
+			run_one "$DIR" "$TEST"
 		fi
 	done
 

---
base-commit: c7275b05bc428c7373d97aa2da02d3a7fa6b9f66
change-id: 20260417-selftests-fix-double-number-99322f012bb1

Best regards,
--  
Mark Brown <broonie@kernel.org>
Re: [PATCH] selftests: Fix duplicated test number reporting
Posted by Shuah Khan 2 months ago
On 4/17/26 10:57, Mark Brown wrote:
> Commit 2964f6b816c2 ("selftests: Use ktap helpers for runner.sh") converted
> the prints in runner.sh to use the relevant helpers from ktap_helpers.sh,
> not modifying any of the strings printed in the process. This included
> converting all the result reports to use the relevant ktap_test_ function.
> Since the output was originally KTAP compliant the strings reported for
> test names now include test numbers:
> 
>    ok 59 59 selftests: arm64: syscall-abi
> 
> instead of the expected format:
> 
>    ok 59 selftests: arm64: syscall-abi
> 
> which causes result parsers to interpret the second number as part of the
> test name.
> 
> Given the use of the helpers the tracking of test numbers by runner.sh is
> now redundant, remove it entirely to restore the expected output format.
> 
> Fixes: 2964f6b816c2 ("selftests: Use ktap helpers for runner.sh")
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---

That was quick - I applied this one also to linux-kselftest next.
I will send one pr with all 4 fixes tomorrow.

thanks,
-- Shuah