Skip to content

Commit 16ebb78

Browse files
robncalccrypto
authored andcommitted
ZTS: handle FreeBSD version numbers correctly (openzfs#16340)
FreeBSD patchlevel versions are optional and, if present, in a different location in the version string. Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Tino Reichardt <[email protected]> Reviewed-by: Tony Hutter <[email protected]>
1 parent eabc8c8 commit 16ebb78

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tests/zfs-tests/include/libtest.shlib

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,39 @@ function compare_version_gte
6262
}
6363

6464
# Helper function used by linux_version() and freebsd_version()
65+
# $1, if provided, should be a MAJOR, MAJOR.MINOR or MAJOR.MINOR.PATCH
66+
# version number
6567
function kernel_version
6668
{
6769
typeset ver="$1"
6870

69-
[ -z "$ver" ] && ver=$(uname -r | grep -Eo "^[0-9]+\.[0-9]+\.[0-9]+")
71+
[ -z "$ver" ] && case "$UNAME" in
72+
Linux)
73+
# Linux version numbers are X.Y.Z followed by optional
74+
# vendor/distro specific stuff
75+
# RHEL7: 3.10.0-1160.108.1.el7.x86_64
76+
# Fedora 37: 6.5.12-100.fc37.x86_64
77+
# Debian 12.6: 6.1.0-22-amd64
78+
ver=$(uname -r | grep -Eo "^[0-9]+\.[0-9]+\.[0-9]+")
79+
;;
80+
FreeBSD)
81+
# FreeBSD version numbers are X.Y-BRANCH-pZ. Depending on
82+
# branch, -pZ may not be present, but this is typically only
83+
# on pre-release or true .0 releases, so can be assumed 0
84+
# if not present.
85+
# eg:
86+
# 13.2-RELEASE-p4
87+
# 14.1-RELEASE
88+
# 15.0-CURRENT
89+
ver=$(uname -r | \
90+
grep -Eo "[0-9]+\.[0-9]+(-[A-Z0-9]+-p[0-9]+)?" | \
91+
sed -E "s/-[^-]+-p/./")
92+
;;
93+
*)
94+
# Unknown system
95+
log_fail "Don't know how to get kernel version for '$UNAME'"
96+
;;
97+
esac
7098

7199
typeset version major minor _
72100
IFS='.' read -r version major minor _ <<<"$ver"

0 commit comments

Comments
 (0)