Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH v5 1/1] tst_res_: Print error to stderr, with filename and lineno
@ 2025-08-18  7:54 Petr Vorel
  2025-08-22  0:52 ` Li Wang via ltp
  2025-08-29 10:07 ` Cyril Hrubis
  0 siblings, 2 replies; 4+ messages in thread
From: Petr Vorel @ 2025-08-18  7:54 UTC (permalink / raw)
  To: ltp

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>
---
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);
 		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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v5 1/1] tst_res_: Print error to stderr, with filename and lineno
  2025-08-18  7:54 [LTP] [PATCH v5 1/1] tst_res_: Print error to stderr, with filename and lineno Petr Vorel
@ 2025-08-22  0:52 ` Li Wang via ltp
  2025-08-29 10:07 ` Cyril Hrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Li Wang via ltp @ 2025-08-22  0:52 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v5 1/1] tst_res_: Print error to stderr, with filename and lineno
  2025-08-18  7:54 [LTP] [PATCH v5 1/1] tst_res_: Print error to stderr, with filename and lineno Petr Vorel
  2025-08-22  0:52 ` Li Wang via ltp
@ 2025-08-29 10:07 ` Cyril Hrubis
  2025-08-29 14:10   ` Petr Vorel
  1 sibling, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2025-08-29 10:07 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v5 1/1] tst_res_: Print error to stderr, with filename and lineno
  2025-08-29 10:07 ` Cyril Hrubis
@ 2025-08-29 14:10   ` Petr Vorel
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2025-08-29 14:10 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Li, Cyril,

thanks for your review.

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

Merged with this formatting change proposed by Li.

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-29 14:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18  7:54 [LTP] [PATCH v5 1/1] tst_res_: Print error to stderr, with filename and lineno Petr Vorel
2025-08-22  0:52 ` Li Wang via ltp
2025-08-29 10:07 ` Cyril Hrubis
2025-08-29 14:10   ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox