[LTP] [PATCH v5 1/1] tst_res_: Print error to stderr, with filename and lineno

Li Wang liwang@redhat.com
Fri Aug 22 02:52:30 CEST 2025


Hi Petr,

On Mon, Aug 18, 2025 at 3:55 PM Petr Vorel <pvorel@suse.cz> wrote:

> Print not only tst_res_.c filename and lineno but also script which
> invoked tst_res_.c (if available). That helps find wrong tst_res_.c
> invocation:
>
>     tst_res_.c:42: Wrong type 'TPASS_EE' (invoked by shell_loader.sh:-1)
>     Usage: tst_{res,brk} filename lineno
> [TPASS|TBROK|TFAIL|TWARN|TCONF|TINFO|TDEBUG] 'A short description'
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
>

Reviewed-by: Li Wang <liwang@redhat.com>

---
> Changes v4->v5:
> * Use argv[1] and argv[2] (Cyril)
> https://lore.kernel.org/ltp/aIC1A9yNXKX6QN2N@yuki.lan/
> https://lore.kernel.org/ltp/aIIHh2CYcraAJHqG@yuki.lan/
>
> Link to v4:
>
> https://patchwork.ozlabs.org/project/ltp/patch/20250722125916.74967-5-pvorel@suse.cz/
> https://lore.kernel.org/ltp/20250722125916.74967-5-pvorel@suse.cz/
>
>  testcases/lib/tst_res_.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/testcases/lib/tst_res_.c b/testcases/lib/tst_res_.c
> index c09d689ee5..2cc31e740f 100644
> --- a/testcases/lib/tst_res_.c
> +++ b/testcases/lib/tst_res_.c
> @@ -1,6 +1,7 @@
>  // SPDX-License-Identifier: GPL-2.0-or-later
>  /*
>   * Copyright (c) 2024 Cyril Hrubis <chrubis@suse.cz>
> + * Copyright (c) Linux Test Project, 2025
>   */
>
>  #define TST_NO_DEFAULT_MAIN
> @@ -13,13 +14,15 @@ static void print_help(void)
>
>  int main(int argc, char *argv[])
>  {
> -       int type, i;
> +       int i, lineno, type;
>
>         if (argc < 5) {
> -               printf("argc = %i expected 5\n", argc);
> +               fprintf(stderr, "%s:%d: argc = %i expected 5\n", __FILE__,
> __LINE__, argc);
>

"argc = %i expected 5" is fine, but maybe "invalid argc=%i, expected 5"
would be clearer.

                goto help;
>         }
>
> +       lineno = atoi(argv[2]);

+
>         if (!strcmp(argv[3], "TPASS")) {
>                 type = TPASS;
>         } else if (!strcmp(argv[3], "TFAIL")) {
> @@ -35,7 +38,8 @@ int main(int argc, char *argv[])
>         } else if (!strcmp(argv[3], "TBROK")) {
>                 type = TBROK;
>         } else {
> -               printf("Wrong type '%s'\n", argv[3]);
> +               fprintf(stderr, "%s:%d: Wrong type '%s' (invoked by
> %s:%d)\n", __FILE__,
> +                               __LINE__, argv[3], argv[1], lineno);
>                 goto help;
>         }
>
> @@ -57,7 +61,7 @@ int main(int argc, char *argv[])
>
>         tst_reinit();
>
> -       tst_res_(argv[1], atoi(argv[2]), type, "%s", msg);
> +       tst_res_(argv[1], lineno, type, "%s", msg);
>
>         return 0;
>  help:
> --
> 2.50.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang


More information about the ltp mailing list