[LTP] [PATCH v4 4/6] tst_res_: Print error to stderr, with filename and lineno
Cyril Hrubis
chrubis@suse.cz
Wed Jul 23 12:10:11 CEST 2025
Hi!
> Printing to stderr, tst_res_ filename and lineno helps debugging wrong
> code. Best would be if it prints either code which invoked it or the
> original message, but at least this is an improvement.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> * New in v4
>
> testcases/lib/tst_res_.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/testcases/lib/tst_res_.c b/testcases/lib/tst_res_.c
> index c09d689ee5..5b255d4d54 100644
> --- a/testcases/lib/tst_res_.c
> +++ b/testcases/lib/tst_res_.c
> @@ -16,7 +16,7 @@ int main(int argc, char *argv[])
> int type, i;
>
> if (argc < 5) {
> - printf("argc = %i expected 5\n", argc);
> + fprintf(stderr, "%s:%d: argc = %i expected 5\n", __FILE__, __LINE__, argc);
> goto help;
> }
>
> @@ -35,7 +35,7 @@ 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'\n", __FILE__, __LINE__, argv[3]);
In this case we cantually have file and line in argv[1] and argv[2] and
we can print that as well.
And possibly in the case that argc < 5 we can attempt to print argv[1]
and argv[2] as well, but it's likely going to be wrong data since the
number of arguments does not match in that case.
> goto help;
> }
>
> --
> 2.50.1
>
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list