diff mbox series

[blktests,1/2] common/rc: introduce _kver_gt_or_eq

Message ID 20231115055220.2656965-2-shinichiro.kawasaki@wdc.com (mailing list archive)
State New, archived
Headers show
Series nvme: require kernel config NVME_HOST_AUTH | expand

Commit Message

Shin'ichiro Kawasaki Nov. 15, 2023, 5:52 a.m. UTC
To adjust test conditions per kernel version, introduce the new helper
function _kver_gt_or_eq. Also simplify the similar function _have_kver
using _kver_gt_or_eq.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 common/rc | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index c3680f5..a3cdfa6 100644
--- a/common/rc
+++ b/common/rc
@@ -206,15 +206,22 @@  _have_kernel_option() {
 
 # Check whether the version of the running kernel is greater than or equal to
 # $1.$2.$3
-_have_kver() {
+_kver_gt_or_eq() {
+	local a b c
 	local d=$1 e=$2 f=$3
 
 	IFS='.' read -r a b c < <(uname -r | sed 's/-.*//;s/[^.0-9]//')
-	if [ $((a * 65536 + b * 256 + c)) -lt $((d * 65536 + e * 256 + f)) ];
-	then
-		SKIP_REASONS+=("Kernel version too old")
-		return 1
+	(((a * 65536 + b * 256 + c) >= (d * 65536 + e * 256 + f)))
+}
+
+# Check whether the version of the running kernel is greater than or equal to
+# $1.$2.$3 and set SKIP_REASONS.
+_have_kver() {
+	if _kver_gt_or_eq "$1" "$2" "$3"; then
+		return 0
 	fi
+	SKIP_REASONS+=("Kernel version too old")
+	return 1
 }
 
 _have_tracefs() {