Thread (24 messages) 24 messages, 2 authors, 2019-01-28
STALE2737d
Revisions (3)
  1. v2 [diff vs current]
  2. v3 current
  3. v4 [diff vs current]

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

From: Shin'ichiro Kawasaki <hidden>
Date: 2019-01-18 09:45:20
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 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
+			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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help