Skip to content

Commit dff8574

Browse files
coolgwpevik
authored andcommitted
tst_test.c: Add tst_cmd_present check if a command is present
Link: https://lore.kernel.org/ltp/20260109061716.20258-3-wegao@suse.com/ Reviewed-by: Petr Vorel <pvorel@suse.cz> Reviewed-by: Cyril Hrubis <chrubis@suse.cz> Signed-off-by: Wei Gao <wegao@suse.com>
1 parent 39a2844 commit dff8574

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

include/tst_test.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,18 @@ int tst_creat_unlinked(const char *path, int flags, mode_t mode);
726726
*/
727727
const char *tst_get_tmpdir_root(void);
728728

729+
/**
730+
* tst_cmd_present() - Check if a command is present
731+
* @cmd: The name of the command to check for.
732+
*
733+
* This function iterates through the &tst_test->needs_cmds array. It compares
734+
* the given command name with each entry in the array and returns the
735+
* &tst_cmd->present flag for the matching command.
736+
*
737+
* Return: `true` if the command is present, `false` otherwise.
738+
*/
739+
bool tst_cmd_present(const char *cmd);
740+
729741
/*
730742
* Validates exit status of child processes
731743
*/

lib/tst_test.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,24 @@ static const char *default_fs_type(void)
13751375
return tst_dev_fs_type();
13761376
}
13771377

1378+
bool tst_cmd_present(const char *cmd)
1379+
{
1380+
struct tst_cmd *pcmd = tst_test->needs_cmds;
1381+
1382+
if (!cmd || cmd[0] == '\0')
1383+
tst_brk(TBROK, "Invalid cmd");
1384+
1385+
while (pcmd->cmd) {
1386+
if (!strcmp(pcmd->cmd, cmd))
1387+
return pcmd->present;
1388+
1389+
pcmd++;
1390+
}
1391+
1392+
tst_brk(TBROK, "'%s' not checked", cmd);
1393+
return false;
1394+
}
1395+
13781396
static void do_setup(int argc, char *argv[])
13791397
{
13801398
char *tdebug_env = getenv("LTP_ENABLE_DEBUG");

0 commit comments

Comments
 (0)