diff mbox series

[blktests,2/7] common: add a helper if a driver is available

Message ID 20220601064837.3473709-3-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [blktests,1/7] nvme: use _have_loop instead of _have_modules loop | expand

Commit Message

Christoph Hellwig June 1, 2022, 6:48 a.m. UTC
Unlike _have_modules this allows allows for a built-in driver.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 common/rc | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 5e35e21..2d0fd88 100644
--- a/common/rc
+++ b/common/rc
@@ -28,6 +28,18 @@  _have_root() {
 	return 0
 }
 
+_have_driver()
+{
+	local modname="${1/-/_}"
+
+	if [ ! -d "/sys/module/${modname}" ] && ! modprobe -q "${modname}"; then
+		SKIP_REASON="driver ${modname} is not available"
+		return 1
+	fi
+
+	return 0
+}
+
 _have_modules() {
 	local missing=()
 	local module