common/rc: add _require_kernel_config and _has_kernel_config
authorLukas Czerner <lczerner@redhat.com>
Mon, 8 Nov 2021 21:04:23 +0000 (22:04 +0100)
committerEryu Guan <guaneryu@gmail.com>
Sun, 14 Nov 2021 10:56:56 +0000 (18:56 +0800)
Add _require_kernel_config() and _has_kernel_config() helpers to check
whether a specific kernel configuration is enabled on the kernel.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
README
common/config
common/rc

diff --git a/README b/README
index 63f0641a3af0d740962cbc187f66da625e52bdc9..e9284b229eca3eb5e9bcebccfbf1f7ebe743548e 100644 (file)
--- a/README
+++ b/README
@@ -129,6 +129,8 @@ Preparing system for tests:
                xfs_check to check the filesystem.  As of August 2021,
                xfs_repair finds all filesystem corruptions found by xfs_check,
                and more, which means that xfs_check is no longer run by default.
+            - Set KCONFIG_PATH to specify your preferred location of kernel
+              config file.
 
         - or add a case to the switch in common/config assigning
           these variables based on the hostname of your test
index 164381b75c6c57a193c94a5b9ffdf393c9ed0756..e0a5c5df58ffbdd0c81ddf7b2d4037a6230d09e1 100644 (file)
@@ -226,6 +226,7 @@ export OPENSSL_PROG="$(type -P openssl)"
 export ACCTON_PROG="$(type -P accton)"
 export E2IMAGE_PROG="$(type -P e2image)"
 export BLKZONE_PROG="$(type -P blkzone)"
+export GZIP_PROG="$(type -P gzip)"
 
 # use 'udevadm settle' or 'udevsettle' to wait for lv to be settled.
 # newer systems have udevadm command but older systems like RHEL5 don't.
index 0d261184c11e87c8670e281d51525faf3e0e286f..89e90d9b933048f01d2c3f086d08be9bbfc433ee 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -4703,6 +4703,35 @@ _require_names_are_bytes() {
         esac
 }
 
+_has_kernel_config()
+{
+       local option=$1
+       local uname=$(uname -r)
+       local config_list="$KCONFIG_PATH
+                    /proc/config.gz
+                    /lib/modules/$uname/build/.config
+                    /boot/config-$uname
+                    /lib/kernel/config-$uname"
+
+       for config in $config_list; do
+               [ ! -f $config ] && continue
+               [ $config = "/proc/config.gz" ] && break
+               grep -qE "^${option}=[my]" $config
+               return
+       done
+
+       [ ! -f $config ] && _notrun "Could not locate kernel config file"
+
+       # We can only get here with /proc/config.gz
+       _require_command "$GZIP_PROG" gzip
+       $GZIP_PROG -cd $config | grep -qE "^${option}=[my]"
+}
+
+_require_kernel_config()
+{
+       _has_kernel_config $1 || _notrun "Installed kernel not built with $1"
+}
+
 init_rc
 
 ################################################################################