Skip to contentSkip to conversation

test/common: make kernel version checks RC-aware

PATCH Applied Alison Schofield 2 participants 3 messages Nov 19 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH 1/1 test/common: make kernel version checks RC-aware

check_min_kver() ignores RC numbers. When a kernel fix lands during an RC cycle, tests that depend on it use the next kernel release as their minimum. This avoids failures on earlier RCs but delays CI coverage after the fix is available.

Honor explicit X.Y-rcN minimums so CI can run a test starting with the first RC that contains the fix. A bare X.Y minimum continues to accept all RCs in that cycle.

---

This came up recently as we have a test case for a kernel fix that is expected to be in 7.4-rc4. This change supports exercising that test case asap, rather than waiting for 7.5-rc1.

 test/common | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)
test/common +36 -4
index d60d9e046445..ed533cd92a42 100644
@@ -89,16 +89,48 @@ reset1()
 }
 
 
+# __kver_key
+# $1: Kernel version in X.Y[.Z][-rcN] format, trailing text is ignored
+# $2: RC number to use when $1 has no -rc suffix
+#
+# Print a fixed-width key with four digits per field and a missing Z
+# treated as 0. Reserve RC value 9999 for final releases so they sort
+# after their RCs. A minimum without -rcN uses 0 so it accepts every
+# RC of that version.
+#
+__kver_key()
+{
+	local re='^([0-9]+)\.([0-9]+)(\.([0-9]+))?(-rc([0-9]+))?'
+	local i
+
+	[[ "$1" =~ $re ]] || return 1
+	for i in 1 2 4 6; do
+		(( ${#BASH_REMATCH[i]} <= 4 )) || return 1
+	done
+	(( 10#${BASH_REMATCH[6]:-0} < 9999 )) || return 1
+	printf "%04d%04d%04d%04d" \
+		"$((10#${BASH_REMATCH[1]}))" "$((10#${BASH_REMATCH[2]}))" \
+		"$((10#${BASH_REMATCH[4]:-0}))" "$((10#${BASH_REMATCH[6]:-$2}))"
+}
+
 # check_min_kver
-# $1: Supported kernel version. format: X.Y
+# $1: Minimum kernel version in X.Y[.Z][-rcN] format
+#
+# X.Y passes from X.Y-rc1 on. Use X.Y-rcN to set a specific RC as
+# the minimum. The argument must match the full version format above.
 #
 check_min_kver()
 {
-	local ver="$1"
+	local want have
 	: "${KVER:=$(uname -r)}"
 
-	[ -n "$ver" ] || return 1
-	[[ "$ver" == "$(echo -e "$ver\n$KVER" | sort -V | head -1)" ]]
+	if [[ ! "$1" =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?(-rc[0-9]+)?$ ]]; then
+		echo "test/$test_basename: invalid kernel version '$1'" >&2
+		return 1
+	fi
+	want=$(__kver_key "$1" 0) || return 1
+	have=$(__kver_key "$KVER" 9999) || return 1
+	(( 10#$have >= 10#$want ))
 }
 
 # check_eq_kver
Signature · 1 line
2.37.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Alison Schofield

check_min_kver() ignores RC numbers. When a kernel fix lands during an RC cycle, tests that depend on it use the next kernel release as their minimum. This avoids failures on earlier RCs but delays CI coverage after the fix is available.

Honor explicit X.Y-rcN minimums so CI can run a test starting with the first RC that contains the fix. A bare X.Y minimum continues to accept all RCs in that cycle.

Quoted 67 lines

---

This came up recently as we have a test case for a kernel fix that is expected to be in 7.4-rc4. This change supports exercising that test case asap, rather than waiting for 7.5-rc1.

 test/common | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)
test/common +36 -4
index d60d9e046445..ed533cd92a42 100644
@@ -89,16 +89,48 @@ reset1()
 }
 
 
+# __kver_key
+# $1: Kernel version in X.Y[.Z][-rcN] format, trailing text is ignored
+# $2: RC number to use when $1 has no -rc suffix
+#
+# Print a fixed-width key with four digits per field and a missing Z
+# treated as 0. Reserve RC value 9999 for final releases so they sort
+# after their RCs. A minimum without -rcN uses 0 so it accepts every
+# RC of that version.
+#
+__kver_key()
+{
+	local re='^([0-9]+)\.([0-9]+)(\.([0-9]+))?(-rc([0-9]+))?'
+	local i
+
+	[[ "$1" =~ $re ]] || return 1
+	for i in 1 2 4 6; do
+		(( ${#BASH_REMATCH[i]} <= 4 )) || return 1
+	done
+	(( 10#${BASH_REMATCH[6]:-0} < 9999 )) || return 1
+	printf "%04d%04d%04d%04d" \
+		"$((10#${BASH_REMATCH[1]}))" "$((10#${BASH_REMATCH[2]}))" \
+		"$((10#${BASH_REMATCH[4]:-0}))" "$((10#${BASH_REMATCH[6]:-$2}))"
+}
+
 # check_min_kver
-# $1: Supported kernel version. format: X.Y
+# $1: Minimum kernel version in X.Y[.Z][-rcN] format
+#
+# X.Y passes from X.Y-rc1 on. Use X.Y-rcN to set a specific RC as
+# the minimum. The argument must match the full version format above.
 #
 check_min_kver()
 {
-	local ver="$1"
+	local want have
 	: "${KVER:=$(uname -r)}"
 
-	[ -n "$ver" ] || return 1
-	[[ "$ver" == "$(echo -e "$ver\n$KVER" | sort -V | head -1)" ]]
+	if [[ ! "$1" =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?(-rc[0-9]+)?$ ]]; then
+		echo "test/$test_basename: invalid kernel version '$1'" >&2
+		return 1
+	fi
+	want=$(__kver_key "$1" 0) || return 1
+	have=$(__kver_key "$KVER" 9999) || return 1
+	(( 10#$have >= 10#$want ))
 }
 
 # check_eq_kver
author maintainer Applied
#2 lore raw
In reply to Alison Schofield
Quoted 11 lines · Alison Schofield

check_min_kver() ignores RC numbers. When a kernel fix lands during an RC cycle, tests that depend on it use the next kernel release as their minimum. This avoids failures on earlier RCs but delays CI coverage after the fix is available.

Honor explicit X.Y-rcN minimums so CI can run a test starting with the first RC that contains the fix. A bare X.Y minimum continues to accept all RCs in that cycle.

---

Applied to pending for NDCTL v86
https://github.com/pmem/ndctl/commits/pending/