[LTP] [PATCH 1/4] tst_kernel: Add safe_check_driver()

Petr Vorel pvorel@suse.cz
Fri Oct 13 09:47:44 CEST 2023


And use it in tst_test.c. It will be more reused in the next commit.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/tst_kernel.h | 9 +++++++++
 lib/tst_kernel.c     | 6 ++++++
 lib/tst_test.c       | 3 +--
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/include/tst_kernel.h b/include/tst_kernel.h
index 9d3a8d315..8caf3f733 100644
--- a/include/tst_kernel.h
+++ b/include/tst_kernel.h
@@ -30,4 +30,13 @@ int tst_check_builtin_driver(const char *driver);
  */
 int tst_check_driver(const char *driver);
 
+/*
+ * Checks support for the kernel module (both built-in and loadable)
+ * and exit with TCONF if driver not available.
+ *
+ * @param driver The name of the driver.
+ * On Android it *always* passes (always expect the driver is available).
+ */
+void safe_check_driver(const char *driver);
+
 #endif	/* TST_KERNEL_H__ */
diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c
index 4b75ceadb..de4c28308 100644
--- a/lib/tst_kernel.c
+++ b/lib/tst_kernel.c
@@ -198,3 +198,9 @@ int tst_check_driver(const char *driver)
 
 	return -1;
 }
+
+void safe_check_driver(const char *driver)
+{
+	if (tst_check_driver(driver))
+		tst_brkm(TCONF, NULL, "%s driver not available", driver);
+}
diff --git a/lib/tst_test.c b/lib/tst_test.c
index c2f8f503f..087c62a16 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1191,8 +1191,7 @@ static void do_setup(int argc, char *argv[])
 		int i;
 
 		for (i = 0; (name = tst_test->needs_drivers[i]); ++i)
-			if (tst_check_driver(name))
-				tst_brk(TCONF, "%s driver not available", name);
+			safe_check_driver(name);
 	}
 
 	if (tst_test->mount_device)
-- 
2.42.0



More information about the ltp mailing list