On Tue, Mar 12, 2024 at 6:03 PM Ferruh Yigit <ferruh.yi...@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.march...@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