Linux Test Project
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4 4/6] tst_res_: Print error to stderr, with filename and lineno
Date: Wed, 23 Jul 2025 21:38:20 +0200	[thread overview]
Message-ID: <20250723193820.GC162896@pevik> (raw)
In-Reply-To: <aIC1A9yNXKX6QN2N@yuki.lan>

Hi Cyril,

> 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.

Thanks for a hint! I see I was blind (it's used below :)).

Because I really want whole functionality merged, I merged all but this patch.
And for this single patch I'll send v6.

> 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.

Maybe to detect if argv[2] is a number and then use argv[1] and argv[2],
otherwise use __FILE__ and __LINE__ ? But since atoi() does not detect errors,
we would have to use something smarter - safe_strtol() if possible to use LTP
API otherwise strtol()?

Or is it just too complicated and we can use argv[1] and argv[2] if argc > 2
and fallback to __FILE__ and __LINE__ otherwise?

Anyway, thanks a lot for your work and help to slowly move shell tests to shell
loader.  Hopefully we are getting closer to have shell tests more reliable
without a need to rewrite everything to C.

Kind regards,
Petr

> >  		goto help;
> >  	}

> > -- 
> > 2.50.1

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

  reply	other threads:[~2025-07-23 19:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-22 12:59 [LTP] [PATCH v4 0/6] shell lib: Add support for test cleanup Petr Vorel
2025-07-22 12:59 ` [LTP] [PATCH v4 1/6] " Petr Vorel
2025-07-22 12:59 ` [LTP] [PATCH v4 2/6] shell: Move shell code into functions Petr Vorel
2025-07-22 12:59 ` [LTP] [PATCH v4 3/6] tst_res_: Add support for TWARN Petr Vorel
2025-07-23 10:05   ` Cyril Hrubis
2025-07-22 12:59 ` [LTP] [PATCH v4 4/6] tst_res_: Print error to stderr, with filename and lineno Petr Vorel
2025-07-23 10:10   ` Cyril Hrubis
2025-07-23 19:38     ` Petr Vorel [this message]
2025-07-24 10:14       ` Cyril Hrubis
2025-07-22 12:59 ` [LTP] [PATCH v4 5/6] shell lib: Add basic support for test setup Petr Vorel
2025-07-23 10:35   ` Cyril Hrubis
2025-07-22 12:59 ` [LTP] [PATCH v4 6/6] shell: Add shell_loader_setup_cleanup.sh test Petr Vorel
2025-07-23 10:39   ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250723193820.GC162896@pevik \
    --to=pvorel@suse.cz \
    --cc=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox