DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ferruh Yigit <ferruh.yigit@amd.com>
To: David Marchand <david.marchand@redhat.com>, dev@dpdk.org
Cc: 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: Tue, 12 Mar 2024 17:03:00 +0000	[thread overview]
Message-ID: <25bb9521-97fb-4466-8aca-237060d738ca@amd.com> (raw)
In-Reply-To: <20240308144841.3615262-5-david.marchand@redhat.com>

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.


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

<...>

> +};
> +
> +static struct option long_options[] = {
>

Can it be constant?

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

OK to remove RTE_LIB_CMDLINE requirement for 'auto-start' but perhaps
better to have it in separate patch, what do you think?


> +	{ 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,
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) },
```

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

<...>

> -
>  	argvopt = argv;
>  

Why 'argvopt' is required, why not use 'argv' directly?

<...>

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

<...>

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


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.



  reply	other threads:[~2024-03-12 17:03 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 [this message]
2024-03-13 16:51     ` David Marchand
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=25bb9521-97fb-4466-8aca-237060d738ca@amd.com \
    --to=ferruh.yigit@amd.com \
    --cc=aman.deep.singh@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --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).