On Fri, Jan 18, 2019 at 06:44:45PM +0900, Shin'ichiro Kawasaki wrote:
> 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 <[email protected]>
> ---
>  check | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/check b/check
> index 4563d62..4b66995 100755
> --- a/check
> +++ b/check
> @@ -407,6 +407,7 @@ _run_test() {
>       CHECK_DMESG=1
>       DMESG_FILTER="cat"
>       RUN_FOR_ZONED=0
> +     FALLBACK_DEVICE=0
>  
>       # shellcheck disable=SC1090
>       . "tests/${TEST_NAME}"
> @@ -425,6 +426,23 @@ _run_test() {
>                       _call_test test
>               fi
>       else
> +             if [[ ${#TEST_DEVS[@]} -eq 0 ]] && \
> +                     declare -fF fallback_device >/dev/null && \
> +                     declare -fF cleanup_fallback_device >/dev/null; then

We should check in _found_test that cleanup_fallback_device is defined
if fallback_device is defined, and vice versa. Then, we can just check
for fallback_device here.

> +                     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
> @@ -451,6 +469,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
>  }
> -- 
> 2.20.1
> 

Reply via email to