From: David Marchand <david.marchand@redhat.com>
To: Ferruh Yigit <ferruh.yigit@amd.com>
Cc: dev@dpdk.org, Aman Singh <aman.deep.singh@intel.com>,
Yuying Zhang <yuying.zhang@intel.com>
Subject: Re: [PATCH 4/4] app/testpmd: enhance getopt_long usage
Date: Wed, 13 Mar 2024 17:51:02 +0100 [thread overview]
Message-ID: <CAJFAV8xqS+aEa8QgtJFCD4ckK7RuhriDo=9_Xd+as8r-EnXwWA@mail.gmail.com> (raw)
In-Reply-To: <25bb9521-97fb-4466-8aca-237060d738ca@amd.com>
On Tue, Mar 12, 2024 at 6:03 PM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>
> On 3/8/2024 2:48 PM, David Marchand wrote:
> > This is a cleanup similar to previous ones in EAL and examples.
> > Instead of using strcmp for every long options while getopt_long already
> > did such parsing, rely on getopt_long return value.
> >
> > Note for reviewers: this patch is best reviewed once applied locally and
> > displayed with git show -w.
> >
>
> Thanks for the cleanup, it was needed.
Thanks for the in depth review.
>
>
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > ---
> > app/test-pmd/parameters.c | 1928 +++++++++++++++++++++----------------
> > 1 file changed, 1084 insertions(+), 844 deletions(-)
> >
> > diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
> > index 271f0c995a..58f43cb5a8 100644
> > --- a/app/test-pmd/parameters.c
> > +++ b/app/test-pmd/parameters.c
> > @@ -40,6 +40,346 @@
> >
> > #include "testpmd.h"
> >
> > +enum {
> > + /* long options mapped to a short option */
> > +#define TESTPMD_OPT_AUTO_START "auto-start"
> > + TESTPMD_OPT_AUTO_START_NUM = 'a',
> > +#define TESTPMD_OPT_HELP "help"
> > + TESTPMD_OPT_HELP_NUM = 'h',
> > +#define TESTPMD_OPT_INTERACTIVE "interactive"
> > + TESTPMD_OPT_INTERACTIVE_NUM = 'i',
> > +
> > + /* first long only option value must be >= 256 */
> > + TESTPMD_OPT_LONG_MIN_NUM = 256,
> >
>
> This is to be able to use all short options, not sure if this requires a
> comment.
Yes, those comments do not help.
>
> <...>
>
> > +};
> > +
> > +static struct option long_options[] = {
> >
>
> Can it be constant?
Yes.
>
> > + { TESTPMD_OPT_AUTO_START, 0, NULL, TESTPMD_OPT_AUTO_START_NUM },
> >
>
> In original version "auto-start" long version is enabled only if
> 'RTE_LIB_CMDLINE' enabled, not sure why, but not for short version, I
> think there is a confusion.
I guess one reason why the --auto-start option is under
RTE_LIB_CMDLINE is because forwarding is always started when in non
interactive mode.
https://git.dpdk.org/dpdk/tree/app/test-pmd/testpmd.c#n4722
-a is available without RTE_LIB_CMDLINE, but it was probably not intentional.
In both cases, -a / --auto-start are a nop when testpmd is compiled
without RTE_LIB_CMDLINE.
So moving it out of the RTE_LIB_CMDLINE is not an issue.
>
> OK to remove RTE_LIB_CMDLINE requirement for 'auto-start' but perhaps
> better to have it in separate patch, what do you think?
Yes, it is worth a separate patch but see below my next comment about
RTE_LIB_CMDLINE check.
>
>
> > + { TESTPMD_OPT_HELP, 0, NULL, TESTPMD_OPT_HELP_NUM },
> > +#ifdef RTE_LIB_CMDLINE
> > + { TESTPMD_OPT_INTERACTIVE, 0, NULL, TESTPMD_OPT_INTERACTIVE_NUM },
> > + { TESTPMD_OPT_CMDLINE_FILE, 1, NULL, TESTPMD_OPT_CMDLINE_FILE},
> >
>
> What about using 'no_argument' & 'required_argument' instead of '0' &
> '1', but I guess it will make lines too big,
Line length is the reason why I used the 0/1 but your suggestion looks
good to me.
> as flag will be always NULL in this approach, what about defining macros
> for arg and no_arg, like:
> ```
> #define ARG(name) (name), required_argument, NULL, name##_NUM
> #define NOARG(name) (name), no_argument, NULL, name##_NUM
> #define OPTARG(name) (name), optional_argument, NULL, name##_NUM
>
> { NOARG(TESTPMD_OPT_INTERACTIVE) },
> { ARG(TESTPMD_OPT_CMDLINE_FILE) },
> ```
It lgtm.
>
> > + { TESTPMD_OPT_ETH_PEERS_CONFIGFILE, 1, NULL, TESTPMD_OPT_ETH_PEERS_CONFIGFILE_NUM },
> > + { TESTPMD_OPT_ETH_PEER, 1, NULL, TESTPMD_OPT_ETH_PEER_NUM },
> >
>
> These long options are within "#ifdef RTE_LIB_CMDLINE" block, I don't
> know why, I guess above two can work without cmdline library.
Looking again at the options list, we have a nice mess in there... I
had not realised.
I think the only options that are conditional to RTE_LIB_CMDLINE should be:
-i, -a, --cmdline-file.
As I wrote above, leaving the -a/--auto-start option parsing out of
RTE_LIB_CMDLINE is not an issue.
So it would only leave -i/--interactive and --cmdline-file under
RTE_LIB_CMDLINE.
The rest can be moved out of RTE_LIB_CMDLINE.
And reading your next comment about RTE_LIB_CMDLINE, I think we are in sync.
>
> <...>
>
> > -
> > argvopt = argv;
> >
>
> Why 'argvopt' is required, why not use 'argv' directly?
I'll have to double check.
>
> <...>
>
> > #ifdef RTE_LIB_CMDLINE
> > ...
> > + case TESTPMD_OPT_ETH_PEER_NUM: {
> > + char *port_end;
> >
> > - if (rte_ether_unformat_addr(port_end,
> > - &peer_eth_addrs[n]) < 0)
> > - rte_exit(EXIT_FAILURE,
> > - "Invalid ethernet address: %s\n",
> > - port_end);
> > - nb_peer_eth_addrs++;
> > - }
> > + errno = 0;
> > + n = strtoul(optarg, &port_end, 10);
> > + if (errno != 0 || port_end == optarg || *port_end++ != ',')
> > + rte_exit(EXIT_FAILURE,
> > + "Invalid eth-peer: %s", optarg);
> > + if (n >= RTE_MAX_ETHPORTS)
> > + rte_exit(EXIT_FAILURE,
> > + "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
> > + n, RTE_MAX_ETHPORTS);
> > +
> > + if (rte_ether_unformat_addr(port_end,
> > + &peer_eth_addrs[n]) < 0)
> > + rte_exit(EXIT_FAILURE,
> > + "Invalid ethernet address: %s\n",
> > + port_end);
> > + nb_peer_eth_addrs++;
> > + break;
> > + }
> > #endif
> >
>
> Similar to the 'struct option long_options' comment, I think expect from
> "interactive" & "cmdline-file", rest can be moved out of "#ifdef
> RTE_LIB_CMDLINE" block, but not this patch in different patch.
Yes.
>
> <...>
>
> > default:
> > usage(argv[0]);
> >
>
> It is not shown in the patch, to print the error case it uses:
> `fprintf(stderr, "Invalid option: %s\n", argv[optind]);`
>
> But as far as I can see 'optind' is the next arg to call, so instead it
> should be 'optind - 1'.
Oh, good catch:
$ build-mini/app/dpdk-testpmd -c 3 --no-huge -m 40 -a 0:0.0 --vdev
net_null1 --vdev net_null2 -- -i --garbage
Invalid option: (null)
EAL: Error - exiting with code: 1
Cause: Command line is incomplete or incorrect
>
>
> And just after while loop, there is "if (optind != argc)" check, I don't
> see when this check will be hit, so it looks useless.
But this part actually looks correct to me.
We could still hit this part with non handled trailing strings:
$ build-mini/app/dpdk-testpmd -c 3 --no-huge -m 40 -a 0:0.0 --vdev
net_null1 --vdev net_null2 -- -i garbage
Invalid parameter: garbage
EAL: Error - exiting with code: 1
Cause: Command line is incorrect
Port 0 is closed
Port 1 is closed
--
David Marchand
next prev parent reply other threads:[~2024-03-13 16:51 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-08 14:48 [PATCH 0/4] testpmd options parsing cleanup David Marchand
2024-03-08 14:48 ` [PATCH 1/4] app/testpmd: fix stats-period option check David Marchand
2024-03-12 16:43 ` Ferruh Yigit
2024-03-08 14:48 ` [PATCH 2/4] app/testpmd: fix burst option parsing David Marchand
2024-03-12 16:47 ` Ferruh Yigit
2024-03-13 7:24 ` David Marchand
2024-03-13 10:37 ` Ferruh Yigit
2024-03-13 11:13 ` David Marchand
2024-03-13 12:09 ` Ferruh Yigit
2024-03-13 16:32 ` Stephen Hemminger
2024-03-08 14:48 ` [PATCH 3/4] app/testpmd: check queue count for related options David Marchand
2024-03-12 16:59 ` Ferruh Yigit
2024-03-13 7:37 ` David Marchand
2024-03-13 10:42 ` Ferruh Yigit
2024-03-13 11:10 ` David Marchand
2024-03-13 12:18 ` Ferruh Yigit
2024-03-08 14:48 ` [PATCH 4/4] app/testpmd: enhance getopt_long usage David Marchand
2024-03-12 17:03 ` Ferruh Yigit
2024-03-13 16:51 ` David Marchand [this message]
2024-03-13 17:20 ` David Marchand
2024-03-13 23:28 ` Ferruh Yigit
2024-03-13 23:28 ` Ferruh Yigit
2024-03-14 9:17 ` [PATCH v2 0/6] testpmd options parsing cleanup David Marchand
2024-03-14 9:17 ` [PATCH v2 1/6] app/testpmd: fix stats-period option check David Marchand
2024-03-14 9:17 ` [PATCH v2 2/6] app/testpmd: fix burst option parsing David Marchand
2024-03-14 9:22 ` Ferruh Yigit
2024-03-14 9:17 ` [PATCH v2 3/6] app/testpmd: fix error message for invalid option David Marchand
2024-03-14 9:23 ` Ferruh Yigit
2024-03-14 9:17 ` [PATCH v2 4/6] app/testpmd: enhance queue count check David Marchand
2024-03-14 9:23 ` Ferruh Yigit
2024-03-14 9:17 ` [PATCH v2 5/6] app/testpmd: remove dead code for disabling cmdline library David Marchand
2024-03-14 11:33 ` Ferruh Yigit
2024-03-14 9:17 ` [PATCH v2 6/6] app/testpmd: enhance getopt_long usage David Marchand
2024-03-14 11:43 ` Ferruh Yigit
2024-03-14 12:43 ` [PATCH v2 0/6] testpmd options parsing cleanup Ferruh Yigit
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='CAJFAV8xqS+aEa8QgtJFCD4ckK7RuhriDo=9_Xd+as8r-EnXwWA@mail.gmail.com' \
--to=david.marchand@redhat.com \
--cc=aman.deep.singh@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=yuying.zhang@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).