From: Petr Vorel <pvorel@suse.cz>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [RFC PATCH 2/5] lib: Allow test to have positional args
Date: Mon, 10 Mar 2025 11:23:58 +0100 [thread overview]
Message-ID: <20250310102358.GB396000@pevik> (raw)
In-Reply-To: <Z8scAAdSbxjCjvV2@yuki.lan>
Hi Cyril,
> Hi!
> > diff --git a/doc/developers/writing_tests.rst b/doc/developers/writing_tests.rst
> > index 9b18ec059c..f5796ddc49 100644
> > --- a/doc/developers/writing_tests.rst
> > +++ b/doc/developers/writing_tests.rst
> > @@ -521,7 +521,7 @@ LTP C And Shell Test API Comparison
> > * - not applicable
> > - TST_NEEDS_MODULE
> > - * - not applicable
> > + * - .pos_args (internal use for tst_run_shell.c)
> > - TST_POS_ARGS
> > * - not applicable
> > diff --git a/include/tst_test.h b/include/tst_test.h
> > index eb73cd593c..b249f833ab 100644
> > --- a/include/tst_test.h
> > +++ b/include/tst_test.h
> > @@ -292,8 +292,11 @@ struct tst_fs {
> > *
> > * @tcnt: A number of tests. If set the test() callback is called tcnt times
> > * and each time passed an increasing counter value.
> > + *
> > * @options: An NULL optstr terminated array of struct tst_option.
> > *
> > + * @pos_args: An number of positional parameters passed to tst_run_shell.c.
> We do not support positional arguments for the C API. Do we really need
> them for shell?
I needed this for following change 4th commit ("shell lib: Add basic support for
test cleanup", which wrongly mentions cleanup instead of setup):
- tst_run_shell $(basename "$0") "$@"
+ tst_run_shell tst_exec.sh $(basename "$0") "$@"
I.e. it is only for tst_run_shell.c. I'll have look on it, if it's not needed
sure this commit would be useless. I would like to avoid this change as well.
> > * @min_kver: A minimal kernel version the test can run on. e.g. "3.10".
> > *
> > * @supported_archs: A NULL terminated array of architectures the test runs on
> > @@ -528,6 +531,7 @@ struct tst_fs {
> > unsigned int tcnt;
> > struct tst_option *options;
> > + int pos_args;
> > const char *min_kver;
> > @@ -555,7 +559,6 @@ struct tst_fs {
> > unsigned int skip_in_secureboot:1;
> > unsigned int skip_in_compat:1;
> > -
> > int needs_abi_bits;
> > unsigned int needs_hugetlbfs:1;
> > diff --git a/lib/tst_test.c b/lib/tst_test.c
> > index 3823ea109e..1c2cc5e3b2 100644
> > --- a/lib/tst_test.c
> > +++ b/lib/tst_test.c
> > @@ -711,6 +711,9 @@ static void parse_opts(int argc, char *argv[])
> > check_option_collision();
> > + if (tst_test->pos_args < 0)
> > + tst_brk(TBROK, ".pos_args must be >= 0");
> You can declare pos_args as unsigned and you don't have to add this
> condition.
Good point, thanks!
> > optstr[0] = 0;
> > for (i = 0; i < ARRAY_SIZE(options); i++)
> > @@ -751,8 +754,10 @@ static void parse_opts(int argc, char *argv[])
> > }
> > }
> > - if (optind < argc)
> > - tst_brk(TBROK, "Unexpected argument(s) '%s'...", argv[optind]);
> > + if (optind + tst_test->pos_args < argc) {
> > + tst_brk(TBROK, "Unexpected argument(s) '%s' (%d + %d < %d)",
> > + argv[optind], optind, tst_test->pos_args, argc);
> > + }
> And this half enables the positional arguments for the C API as well. If
> we set the pos_args in tst_test, then we can pass them, but there is no
> way how they can be passed to the test.
Again, this is only for tst_run_shell.c.
Kind regards,
Petr
> So if we are going to add them, we should pass then in
> extern char **tst_args or something like that.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-03-10 10:24 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-28 17:24 [LTP] [RFC PATCH 0/5] shell loader rewrite to support TST_SETUP Petr Vorel
2025-02-28 17:24 ` [LTP] [RFC PATCH 1/5] shell lib: Add support for test cleanup Petr Vorel
2025-03-04 12:57 ` Li Wang
2025-03-04 13:08 ` Petr Vorel
2025-03-04 13:15 ` Li Wang
2025-02-28 17:24 ` [LTP] [RFC PATCH 2/5] lib: Allow test to have positional args Petr Vorel
2025-02-28 17:43 ` Petr Vorel
2025-03-07 16:17 ` Cyril Hrubis
2025-03-10 10:23 ` Petr Vorel [this message]
2025-03-07 16:27 ` Cyril Hrubis
2025-03-10 10:16 ` Petr Vorel
2025-02-28 17:24 ` [LTP] [RFC PATCH 3/5] shell: Move shell code into functions Petr Vorel
2025-02-28 17:45 ` Petr Vorel
2025-02-28 17:24 ` [LTP] [RFC PATCH 4/5] shell lib: Add basic support for test cleanup Petr Vorel
2025-03-07 16:40 ` Cyril Hrubis
2025-03-10 10:27 ` Petr Vorel
2025-04-25 18:33 ` Petr Vorel
2025-04-30 8:52 ` Cyril Hrubis
2025-04-30 8:57 ` Cyril Hrubis
2025-04-30 11:47 ` Petr Vorel
2025-04-30 13:39 ` Cyril Hrubis
2025-02-28 17:24 ` [LTP] [RFC PATCH 5/5] shell: Add shell_loader_setup_cleanup.sh test Petr Vorel
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=20250310102358.GB396000@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.