[LTP] [PATCH v6 2/4] tst_test.c: Add tst_cmd_present check if a command is present
Wei Gao
wegao@suse.com
Tue Dec 23 03:08:16 CET 2025
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/tst_test.h | 12 ++++++++++++
lib/tst_test.c | 13 +++++++++++++
2 files changed, 25 insertions(+)
diff --git a/include/tst_test.h b/include/tst_test.h
index 38a9d0d54..89dd31582 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -721,6 +721,18 @@ int tst_creat_unlinked(const char *path, int flags, mode_t mode);
*/
const char *tst_get_tmpdir_root(void);
+/**
+ * tst_cmd_present() - Check if a command is present
+ * @cmd: The name of the command to check for.
+ *
+ * This function iterates through the &tst_test->needs_cmds array. It compares
+ * the given command name with each entry in the array and returns the
+ * &tst_cmd->present flag for the matching command.
+ *
+ * Return: `true` if the command is present, `false` otherwise.
+ */
+bool tst_cmd_present(const char *cmd);
+
/*
* Validates exit status of child processes
*/
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 42a54621e..67553f65d 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1365,6 +1365,19 @@ static const char *default_fs_type(void)
return tst_dev_fs_type();
}
+bool tst_cmd_present(const char *cmd)
+{
+ struct tst_cmd *pcmd = tst_test->needs_cmds;
+
+ while (pcmd->cmd) {
+ if (!strcmp(pcmd->cmd, cmd))
+ return pcmd->present;
+
+ pcmd++;
+ }
+ return false;
+}
+
static void do_setup(int argc, char *argv[])
{
char *tdebug_env = getenv("LTP_ENABLE_DEBUG");
--
2.52.0
More information about the ltp
mailing list