[LTP] [PATCH v7 2/4] tst_test.c: Add tst_cmd_present check if a command is present

Li Wang liwang@redhat.com
Fri Jan 16 14:58:17 CET 2026


Hi Wei,

I don't get the point why we needs seperately define the tst_cmd_present()
function, from what I understand, as long as we fill "commands" in the
new struct field, that would be completed the check and store the state
in .present, right?

Shouldn't we use that .present value in testcase directly?



On Fri, Jan 9, 2026 at 2:18 PM Wei Gao via ltp <ltp@lists.linux.it> wrote:
>
> Signed-off-by: Wei Gao <wegao@suse.com>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---
>  include/tst_test.h | 12 ++++++++++++
>  lib/tst_test.c     | 18 ++++++++++++++++++
>  2 files changed, 30 insertions(+)
>
> diff --git a/include/tst_test.h b/include/tst_test.h
> index dc2e9a397..d15bf87fd 100644
> --- a/include/tst_test.h
> +++ b/include/tst_test.h
> @@ -726,6 +726,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 09aa7fce2..0c2bbbbd6 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1375,6 +1375,24 @@ 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;
> +
> +       if (!cmd || cmd[0] == '\0')
> +               tst_brk(TBROK, "Invalid cmd");
> +
> +       while (pcmd->cmd) {
> +               if (!strcmp(pcmd->cmd, cmd))
> +                       return pcmd->present;
> +
> +               pcmd++;
> +       }
> +
> +       tst_brk(TBROK, "'%s' not checked", cmd);
> +       return false;
> +}
> +
>  static void do_setup(int argc, char *argv[])
>  {
>         char *tdebug_env = getenv("LTP_ENABLE_DEBUG");
> --
> 2.52.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>


-- 
Regards,
Li Wang



More information about the ltp mailing list