[Devel] [PATCH hci-8.1 v3 4/7] selftests/zram: fail when a step fails

Eva Kurchatova eva.kurchatova at virtuozzo.com
Tue Oct 27 20:34:20 MSK 2026


The library prints FAIL for a step that fails and carries on, zram01
and zram02 print their verdict and exit 0 either way, and zram.sh
exits with the status of zram02 alone, so no zram failure reached the
runner. A step that reports FAIL now fails its test, and the suite
takes the worst result of its two tests, a failure over a skip over a
pass. A compression algorithm the kernel is built without, or a tool
the tests need that is not installed, skips them instead of failing.

https://virtuozzo.atlassian.net/browse/VSTOR-134205
Feature: fix selftests

Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
---
 tools/testing/selftests/zram/zram.sh     | 11 ++++--
 tools/testing/selftests/zram/zram01.sh   |  8 +++++
 tools/testing/selftests/zram/zram02.sh   |  1 +
 tools/testing/selftests/zram/zram_lib.sh | 45 +++++++++++++++++++-----
 4 files changed, 54 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/zram/zram.sh b/tools/testing/selftests/zram/zram.sh
index b0b91d9b0dc2..56adeb17768f 100755
--- a/tools/testing/selftests/zram/zram.sh
+++ b/tools/testing/selftests/zram/zram.sh
@@ -4,15 +4,22 @@ TCID="zram.sh"
 
 . ./zram_lib.sh
 
+# A failure outranks a skip, a skip outranks a pass
+result () {
+	[ $1 -eq $ksft_skip ] && [ $ret -ne 0 ] || ret=$1
+}
+
 run_zram () {
 echo "--------------------"
 echo "running zram tests"
 echo "--------------------"
-./zram01.sh
+./zram01.sh || result $?
 echo ""
-./zram02.sh
+./zram02.sh || result $?
 }
 
 check_prereqs
 
+ret=0
 run_zram
+exit $ret
diff --git a/tools/testing/selftests/zram/zram01.sh b/tools/testing/selftests/zram/zram01.sh
index 8f4affe34f3e..8f337e6adf8b 100755
--- a/tools/testing/selftests/zram/zram01.sh
+++ b/tools/testing/selftests/zram/zram01.sh
@@ -10,6 +10,7 @@
 
 TCID="zram01"
 ERR_CODE=0
+SKIP_CODE=0
 
 . ./zram_lib.sh
 
@@ -33,6 +34,9 @@ zram_algs="lzo"
 
 zram_fill_fs()
 {
+	# An earlier step failed, and after a failed mount the directory
+	# would be filled on the host's filesystem
+	[ $ERR_CODE -ne 0 ] && return
 	for i in $(seq $dev_start $dev_end); do
 		echo "fill zram$i..."
 		local b=0
@@ -70,6 +74,10 @@ zram_cleanup
 
 if [ $ERR_CODE -ne 0 ]; then
 	echo "$TCID : [FAIL]"
+	exit 1
+elif [ $SKIP_CODE -ne 0 ]; then
+	echo "$TCID : [SKIP]"
+	exit $SKIP_CODE
 else
 	echo "$TCID : [PASS]"
 fi
diff --git a/tools/testing/selftests/zram/zram02.sh b/tools/testing/selftests/zram/zram02.sh
index 2418b0c4ed13..54e17bbfdbb7 100755
--- a/tools/testing/selftests/zram/zram02.sh
+++ b/tools/testing/selftests/zram/zram02.sh
@@ -39,6 +39,7 @@ zram_cleanup
 
 if [ $ERR_CODE -ne 0 ]; then
 	echo "$TCID : [FAIL]"
+	exit 1
 else
 	echo "$TCID : [PASS]"
 fi
diff --git a/tools/testing/selftests/zram/zram_lib.sh b/tools/testing/selftests/zram/zram_lib.sh
index 21ec1966de76..6d71022296e5 100755
--- a/tools/testing/selftests/zram/zram_lib.sh
+++ b/tools/testing/selftests/zram/zram_lib.sh
@@ -28,6 +28,13 @@ check_prereqs()
 		echo $msg must be run as root >&2
 		exit $ksft_skip
 	fi
+
+	for cmd in mkfs.ext2 mkswap swapon swapoff; do
+		if ! command -v $cmd > /dev/null 2>&1; then
+			echo $msg $cmd is not installed >&2
+			exit $ksft_skip
+		fi
+	done
 }
 
 kernel_gte()
@@ -131,12 +138,14 @@ zram_max_streams()
 	for max_s in $zram_max_streams; do
 		local sys_path="/sys/block/zram${i}/max_comp_streams"
 		echo $max_s > $sys_path || \
-			echo "FAIL failed to set '$max_s' to $sys_path"
+			{ echo "FAIL failed to set '$max_s' to $sys_path"; ERR_CODE=-1; }
 		sleep 1
 		local max_streams=$(cat $sys_path)
 
-		[ "$max_s" -ne "$max_streams" ] && \
-			echo "FAIL can't set max_streams '$max_s', get $max_stream"
+		if [ "$max_s" -ne "$max_streams" ]; then
+			echo "FAIL can't set max_streams '$max_s', get $max_streams"
+			ERR_CODE=-1
+		fi
 
 		i=$(($i + 1))
 		echo "$sys_path = '$max_streams'"
@@ -152,11 +161,25 @@ zram_compress_alg()
 	local i=$dev_start
 	local algs=$(cat /sys/block/zram${i}/comp_algorithm)
 	echo "supported algs: $algs"
+	if [ -z "$algs" ]; then
+		echo "FAIL can't read /sys/block/zram${i}/comp_algorithm"
+		ERR_CODE=-1
+	fi
 
 	for alg in $zram_algs; do
 		local sys_path="/sys/block/zram${i}/comp_algorithm"
+		# A kernel built without the algorithm is not a zram failure
+		case " $(echo "$algs" | tr -d '[]') " in
+		*" $alg "*) ;;
+		*)
+			echo "SKIP '$alg' is not supported by this kernel"
+			SKIP_CODE=$ksft_skip
+			i=$(($i + 1))
+			continue
+			;;
+		esac
 		echo "$alg" >	$sys_path || \
-			echo "FAIL can't set '$alg' to $sys_path"
+			{ echo "FAIL can't set '$alg' to $sys_path"; ERR_CODE=-1; }
 		i=$(($i + 1))
 		echo "$sys_path = '$alg'"
 	done
@@ -171,7 +194,7 @@ zram_set_disksizes()
 	for ds in $zram_sizes; do
 		local sys_path="/sys/block/zram${i}/disksize"
 		echo "$ds" >	$sys_path || \
-			echo "FAIL can't set '$ds' to $sys_path"
+			{ echo "FAIL can't set '$ds' to $sys_path"; ERR_CODE=-1; }
 
 		i=$(($i + 1))
 		echo "$sys_path = '$ds'"
@@ -188,7 +211,7 @@ zram_set_memlimit()
 	for ds in $zram_mem_limits; do
 		local sys_path="/sys/block/zram${i}/mem_limit"
 		echo "$ds" >	$sys_path || \
-			echo "FAIL can't set '$ds' to $sys_path"
+			{ echo "FAIL can't set '$ds' to $sys_path"; ERR_CODE=-1; }
 
 		i=$(($i + 1))
 		echo "$sys_path = '$ds'"
@@ -205,13 +228,15 @@ zram_makeswap()
 		mkswap /dev/zram$i > err.log 2>&1
 		if [ $? -ne 0 ]; then
 			cat err.log
-			echo "FAIL mkswap /dev/zram$1 failed"
+			echo "FAIL mkswap /dev/zram$i failed"
+			ERR_CODE=-1
 		fi
 
 		swapon /dev/zram$i > err.log 2>&1
 		if [ $? -ne 0 ]; then
 			cat err.log
-			echo "FAIL swapon /dev/zram$1 failed"
+			echo "FAIL swapon /dev/zram$i failed"
+			ERR_CODE=-1
 		fi
 
 		echo "done with /dev/zram$i"
@@ -229,6 +254,7 @@ zram_swapoff()
 		if [ $? -ne 0 ]; then
 			cat err.log
 			echo "FAIL swapoff /dev/zram$i failed"
+			ERR_CODE=-1
 		fi
 	done
 	dev_makeswap=-1
@@ -248,6 +274,7 @@ zram_makefs()
 		if [ $? -ne 0 ]; then
 			cat err.log
 			echo "FAIL failed to make $fs on /dev/zram$i"
+			ERR_CODE=-1
 		fi
 		i=$(($i + 1))
 		echo "zram mkfs.$fs: OK"
@@ -261,7 +288,7 @@ zram_mount()
 		echo "mount /dev/zram$i"
 		mkdir zram$i
 		mount /dev/zram$i zram$i > /dev/null || \
-			echo "FAIL mount /dev/zram$i failed"
+			{ echo "FAIL mount /dev/zram$i failed"; ERR_CODE=-1; }
 		dev_mounted=$i
 	done
 
-- 
2.56.0



More information about the Devel mailing list