[PATCH blktests 03/10] common/rc,fio: factor out _compare_three_version_numbers()
Shin'ichiro Kawasaki
shinichiro.kawasaki at wdc.com
Wed Apr 2 00:08:59 PDT 2025
The helper functions _have_kver() and _have_fio_ver() have the common
logic that compares three numbers with the version string in the format
"a.b.c". Factor out the common logic to the new helper function
_compare_three_version_numbers(). This prepares for to introduce more
functions for version checks.
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
common/fio | 9 +++------
common/rc | 25 +++++++++++++++++++------
2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/common/fio b/common/fio
index 046791f..7c88460 100644
--- a/common/fio
+++ b/common/fio
@@ -28,14 +28,11 @@ _have_fio_zbd_zonemode() {
# Check whether the version of the fio is greater than or equal to $1.$2.$3
_have_fio_ver() {
- local d=$1 e=$2 f=$3
-
_have_fio || return $?
- IFS='.' read -r a b c < <(fio --version | cut -c 5- | sed 's/-.*//')
- if [ $((a * 65536 + b * 256 + c)) -lt $((d * 65536 + e * 256 + f)) ];
- then
- SKIP_REASONS+=("fio version too old")
+ if _compare_three_version_numbers \
+ "$(fio --version | cut -c 5- | sed 's/-.*//')" "$1" "$2" "$3"; then
+ SKIP_REASONS+=("fio version is older than ${1}.${2}.${3:-0}")
return 1
fi
return 0
diff --git a/common/rc b/common/rc
index 068a676..ff3f0a3 100644
--- a/common/rc
+++ b/common/rc
@@ -226,15 +226,28 @@ _have_kernel_option() {
return 0
}
+# Compare the version string in $1 in "a.b.c" format with "$2.$3.$4".
+# If "a.b.c" is smaller than "$2.$3.$4", return true. Otherwise, return
+# false.
+_compare_three_version_numbers() {
+ local -i a b c d e f
+
+ IFS='.' read -r a b c <<< "$1"
+ d=${2:0}
+ e=${3:0}
+ f=${4:0}
+ if ((a * 65536 + b * 256 + c < d * 65536 + e * 256 + f)); then
+ return 0
+ fi
+ return 1
+}
+
# Check whether the version of the running kernel is greater than or equal to
# $1.$2.$3
_have_kver() {
- 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")
+ if _compare_three_version_numbers \
+ "$(uname -r | sed 's/-.*//;s/[^.0-9]//')" "$1" "$2" "$3"; then
+ SKIP_REASONS+=("Kernel version is older than ${1}.${2}.${3}")
return 1
fi
}
--
2.49.0
More information about the Linux-nvme
mailing list