ZTS: handle FreeBSD version numbers correctly (#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 <robn@despairlabs.com>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
This commit is contained in:
Rob Norris 2024-07-13 03:58:03 +10:00 committed by GitHub
parent a10faf5ce6
commit cbd95a950a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 1 deletions

View File

@ -62,11 +62,39 @@ function compare_version_gte
} }
# Helper function used by linux_version() and freebsd_version() # Helper function used by linux_version() and freebsd_version()
# $1, if provided, should be a MAJOR, MAJOR.MINOR or MAJOR.MINOR.PATCH
# version number
function kernel_version function kernel_version
{ {
typeset ver="$1" typeset ver="$1"
[ -z "$ver" ] && ver=$(uname -r | grep -Eo "^[0-9]+\.[0-9]+\.[0-9]+") [ -z "$ver" ] && case "$UNAME" in
Linux)
# Linux version numbers are X.Y.Z followed by optional
# vendor/distro specific stuff
# RHEL7: 3.10.0-1160.108.1.el7.x86_64
# Fedora 37: 6.5.12-100.fc37.x86_64
# Debian 12.6: 6.1.0-22-amd64
ver=$(uname -r | grep -Eo "^[0-9]+\.[0-9]+\.[0-9]+")
;;
FreeBSD)
# FreeBSD version numbers are X.Y-BRANCH-pZ. Depending on
# branch, -pZ may not be present, but this is typically only
# on pre-release or true .0 releases, so can be assumed 0
# if not present.
# eg:
# 13.2-RELEASE-p4
# 14.1-RELEASE
# 15.0-CURRENT
ver=$(uname -r | \
grep -Eo "[0-9]+\.[0-9]+(-[A-Z0-9]+-p[0-9]+)?" | \
sed -E "s/-[^-]+-p/./")
;;
*)
# Unknown system
log_fail "Don't know how to get kernel version for '$UNAME'"
;;
esac
typeset version major minor _ typeset version major minor _
IFS='.' read -r version major minor _ <<<"$ver" IFS='.' read -r version major minor _ <<<"$ver"