]> www.infradead.org Git - users/hch/blktests.git/commitdiff
check: Introduce fallback_device() and cleanup_fallback_device()
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Mon, 28 Jan 2019 13:14:48 +0000 (22:14 +0900)
committerOmar Sandoval <osandov@fb.com>
Tue, 5 Feb 2019 18:46:01 +0000 (10:46 -0800)
These optional functions can be defined by a test case script. When
defined and TEST_DEVS is empty, the fallback_device() is executed before
runing the test case. The fallback_device() function intializes a virtual
device to run the test case and return the device to be set in TEST_DEVS.
After running the test case, cleanup_fallback_device() is executed to
clean up the device.

This feature allows to run test cases with test_device() function even if
TEST_DEVS is not set in the config, using virtaul devices such as null_blk.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
check

diff --git a/check b/check
index 22b456e215009e8a8d7b742216146d8849d4730d..f41ecbadd3f6080c0286c4c1269de0ca7c36acfd 100755 (executable)
--- a/check
+++ b/check
@@ -17,7 +17,7 @@ _found_test() {
        local test_name="$1"
        local explicit="$2"
 
-       unset CAN_BE_ZONED DESCRIPTION QUICK TIMED requires device_requires test test_device
+       unset CAN_BE_ZONED DESCRIPTION QUICK TIMED requires device_requires test test_device fallback_device cleanup_fallback_device
 
        # shellcheck disable=SC1090
        if ! . "tests/${test_name}"; then
@@ -44,6 +44,16 @@ _found_test() {
                return 1
        fi
 
+       if declare -fF fallback_device >/dev/null && ! declare -fF cleanup_fallback_device >/dev/null; then
+               _warning "${test_name} defines fallback_device() but not cleanup_fallback_device()"
+               return 1
+       fi
+
+       if declare -fF cleanup_fallback_device >/dev/null && ! declare -fF fallback_device >/dev/null; then
+               _warning "${test_name} defines cleanup_fallback_device() but not fallback_device()"
+               return 1
+       fi
+
        if (( QUICK && TIMED )); then
                _warning "${test_name} cannot be both QUICK and TIMED"
                return 1
@@ -407,6 +417,7 @@ _run_test() {
        CHECK_DMESG=1
        DMESG_FILTER="cat"
        RUN_FOR_ZONED=0
+       FALLBACK_DEVICE=0
 
        # shellcheck disable=SC1090
        . "tests/${TEST_NAME}"
@@ -425,6 +436,22 @@ _run_test() {
                        _call_test test
                fi
        else
+               if [[ ${#TEST_DEVS[@]} -eq 0 ]] && \
+                       declare -fF fallback_device >/dev/null; then
+                       if ! test_dev=$(fallback_device); then
+                               _warning "$TEST_NAME: fallback_device call failure"
+                               return 0
+                       fi
+                       if ! sysfs_dir="$(_find_sysfs_dir "$test_dev")"; then
+                               _warning "$TEST_NAME: could not find sysfs directory for ${test_dev}"
+                               cleanup_fallback_device
+                               return 0
+                       fi
+                       TEST_DEVS=( "${test_dev}" )
+                       TEST_DEV_SYSFS_DIRS["$test_dev"]="$sysfs_dir"
+                       FALLBACK_DEVICE=1
+               fi
+
                if [[ ${#TEST_DEVS[@]} -eq 0 ]]; then
                        return 0
                fi
@@ -452,6 +479,13 @@ _run_test() {
                                ret=1
                        fi
                done
+
+               if (( FALLBACK_DEVICE )); then
+                       cleanup_fallback_device
+                       unset TEST_DEV_SYSFS_DIRS["${TEST_DEVS[0]}"]
+                       TEST_DEVS=()
+               fi
+
                return $ret
        fi
 }