[LTP] [PATCH 1/1] lib: test.sh: Backport tst_cmd_available (DRY)

Petr Vorel pvorel@suse.cz
Tue Aug 25 06:55:15 CEST 2026


Backport tst_cmd_available() from tst_test.sh in order to have 'command -v'
used only once. That helps to maintain LTP preferred way to check
command in shell.

Follow-up: 772e7d6851 ("lib: test: check systemd in tst_virt_hyperv() as tst_test.sh")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/test.sh | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh
index edae1313ed..0d4f3fe4d2 100644
--- a/testcases/lib/test.sh
+++ b/testcases/lib/test.sh
@@ -148,6 +148,11 @@ tst_rmdir()
 	fi
 }
 
+tst_cmd_available()
+{
+	command -v $1 >/dev/null 2>&1
+}
+
 #
 # Checks if commands passed as arguments exists
 #
@@ -155,9 +160,7 @@ tst_require_cmds()
 {
 	local cmd
 	for cmd in $*; do
-		if ! command -v $cmd > /dev/null 2>&1; then
-			tst_brkm TCONF "'$cmd' not found"
-		fi
+		tst_cmd_available $cmd || tst_brkm TCONF "'$cmd' not found"
 	done
 }
 
@@ -331,7 +334,7 @@ tst_virt_hyperv()
 {
 	local v
 
-	command -v systemd-detect-virt > /dev/null 2>&1 || return 1
+	tst_cmd_available systemd-detect-virt || return 1
 
 	v="$(systemd-detect-virt)"
 
-- 
2.55.0



More information about the ltp mailing list