diff mbox series

[blktests,v3,05/13] check: Introduce fallback_device() and cleanup_fallback_device()

Message ID 20190118094453.13773-6-shinichiro.kawasaki@wdc.com (mailing list archive)
State New, archived
Headers show
Series Implement zoned block device support | expand

Commit Message

Shinichiro Kawasaki Jan. 18, 2019, 9:44 a.m. UTC
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 | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Omar Sandoval Jan. 25, 2019, 9:14 p.m. UTC | #1
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 <shinichiro.kawasaki@wdc.com>
> ---
>  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
>
Shinichiro Kawasaki Jan. 28, 2019, 10:54 a.m. UTC | #2
On 1/26/19 6:14 AM, Omar Sandoval wrote:
> 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 <shinichiro.kawasaki@wdc.com>
>> ---
>>   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.

Thanks. Will change the patch as suggested. I noticed that fallback_device and 
cleanup_fallback_device should be unset at the beginning of _found_test. Will 
add it also.
diff mbox series

Patch

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
+			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
 }