]> www.infradead.org Git - users/hch/blktests.git/commitdiff
blktests: Add _have_kernel_config_file() and _check_kernel_option()
authorXiao Yang <yangx.jy@fujitsu.com>
Mon, 27 Jun 2022 07:32:49 +0000 (15:32 +0800)
committerShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Tue, 28 Jun 2022 08:46:29 +0000 (17:46 +0900)
The helper function _have_kernel_option() sets SKIP_REASON when the
specified kernel config option is not set. Sometimes this SKIP_REASON
update is not desired and it is unset after _have_kernel_option() calls.
This unset is not straight-forward and confusing.

To avoid the unset operation, introduce two new helper functions:

1) _have_kernel_config_file() which sets SKIP_REASON when neither
   /boot/config* nor /proc/config.gz is available.
2) _check_kernel_option() which doesn't set SKIP_RESAON when
   the specified kernel option is not defined.

Also re-implement _have_kernel_option() with the new helper functions.
When SKIP_REASON update is not desired, call _check_kernel_option() in
place of _have_kernel_option().

Signed-off-by: Xiao Yang <yangx.jy@fujitsu.com>
[Shin'ichiro: added change purpose in the commit message]
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
common/multipath-over-rdma
common/rc
tests/nvme/039
tests/nvmeof-mp/rc

index f9d7b9a236ce7f1414d90e4bab5e3576d78608fb..8a2108f3f4b5ae5444aaea61687fb5b26731df8c 100644 (file)
@@ -19,7 +19,8 @@ if [ $ramdisk_size -gt $max_ramdisk_size ]; then
 fi
 
 _have_legacy_dm() {
-       if ! _have_kernel_option DM_MQ_DEFAULT; then
+       _have_kernel_config_file || return
+       if ! _check_kernel_option DM_MQ_DEFAULT; then
                SKIP_REASON="legacy device mapper support is missing"
                return 1
        fi
index d18144b84cc17a13c13bf5472688259dd57638ec..bf6cd10cfb7e626187cc9f18a9321703d31cebc5 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -149,25 +149,44 @@ _have_configfs() {
        return 0
 }
 
-_have_kernel_option() {
-       local f opt=$1
-
+# Check if the specified kernel config files are available.
+_have_kernel_config_file() {
        if [[ ! -f /proc/config.gz && ! -f /boot/config-$(uname -r) ]]; then
                SKIP_REASON="kernel $(uname -r) config not found"
                return 1
        fi
+
+       return 0
+}
+
+# Check if the specified kernel option is defined.
+_check_kernel_option() {
+       local f opt=$1
+
        for f in /proc/config.gz /boot/config-$(uname -r); do
                [ -e "$f" ] || continue
                if zgrep -q "^CONFIG_${opt}=[my]$" "$f"; then
                        return 0
-               else
-                       SKIP_REASON="kernel option $opt has not been enabled"
                fi
        done
 
        return 1
 }
 
+# Combine _have_kernel_config_file() and _check_kernel_option().
+# Set SKIP_RESAON when _check_kernel_option() returns false.
+_have_kernel_option() {
+       local opt=$1
+
+       _have_kernel_config_file || return
+       if ! _check_kernel_option "$opt"; then
+               SKIP_REASON="kernel option $opt has not been enabled"
+               return 1
+       fi
+
+       return 0
+}
+
 # Check whether the version of the running kernel is greater than or equal to
 # $1.$2.$3
 _have_kver() {
index 85827fae629d92e9f51364794b9b3dd131b0fcaa..e175055ddb06dd7caac6aeed85fd67b46db5f131 100755 (executable)
@@ -128,10 +128,9 @@ test_device() {
 
        echo "Running ${TEST_NAME}"
 
-       if _have_kernel_option NVME_VERBOSE_ERRORS; then
+       if _check_kernel_option NVME_VERBOSE_ERRORS; then
                nvme_verbose_errors=true
        else
-               unset SKIP_REASON
                nvme_verbose_errors=false
        fi
 
index 708196b4eeeedfb5b8533bdcd84eac48acb80aaf..2ae80c3d47e8c56c705614f9dc6ea28c033c6443 100755 (executable)
@@ -14,19 +14,17 @@ ini_timeout=1
 group_requires() {
        local m name p required_modules
 
+       _have_kernel_config_file || return
        # Since the nvmeof-mp tests are based on the dm-mpath driver, these
        # tests are incompatible with the NVME_MULTIPATH kernel configuration
        # option with multipathing enabled in the nvme_core kernel module.
-       if _have_kernel_option NVME_MULTIPATH && \
+       if _check_kernel_option NVME_MULTIPATH && \
                _have_module_param_value nvme_core multipath Y; then
                SKIP_REASON="CONFIG_NVME_MULTIPATH has been set in .config \
 and multipathing has been enabled in the nvme_core kernel module"
                return
        fi
 
-       # Avoid test skip due to SKIP_REASON set by _have_kernel_option().
-       unset SKIP_REASON
-
        _have_configfs || return
        required_modules=(
                dm_multipath