From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1F4A043CA0; Wed, 13 Mar 2024 17:51:20 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BD7AD410E3; Wed, 13 Mar 2024 17:51:19 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 954F040A84 for ; Wed, 13 Mar 2024 17:51:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710348678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c6cHX4wLo9WJX6pdQZkkeP0aj32eOEFlQvlyTMPU+eY=; b=Fl2uwqcn429iPlMRpF4hrbJ5O6Pz/mFKyXVkubYVbn1D/Yd+yaS2JLzKUFUtNjWf8FHQg0 o3tF/BZonXmNgMeXfRyjHhUOU6josqUKWKLVkGe1db7DMeLrpwQtzU84gs94Vkj9t0PgoH jKq4cYeRLuK7OohuAZC5j/PRg9TeupM= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-650-7ffgkK0BP7WblxqDCzq-Tg-1; Wed, 13 Mar 2024 12:51:16 -0400 X-MC-Unique: 7ffgkK0BP7WblxqDCzq-Tg-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-5135aa34125so50550e87.0 for ; Wed, 13 Mar 2024 09:51:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710348675; x=1710953475; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c6cHX4wLo9WJX6pdQZkkeP0aj32eOEFlQvlyTMPU+eY=; b=Hl04blxPbdqfeVr9vC6eznFE3SjJpy7x7FQv/bZHP0D3GjFbWpfpF5qRN69YuD0n8U br68xLPf9erTF3QIPPmsNk5zjGTpQdFbCmuJxfgH+ymQhIbpTe9VRN07bEj6R1L/1wbG KJuGUUxVnj4RV4+vIQNEGV+bv36WzfirsqP01T+o6a5iatroHwRdw8kI620Aojpy6Lo2 aZFKw9raO3doqRGrw/sK/v4OdUCTPWjzg06uSJDJXC4c2Zsj7Zea5FWVnryoaYp3+z+j tWRdxT0KQ+2WyGR6uVg+CpPb02Ixy6wNu3GJb+QWs9CTY6fXii0T9RhCAMtEb9vwxhwo 7qRQ== X-Gm-Message-State: AOJu0YyxVFu9YqmpUZcGkWUQdvW1ZWoBqDyevDBsPUBIPWXduJILpDR9 QJOisZe/1H2n0wjWByo+bm0gJOTpkrd4PAogPkD8VLiOZvdQDjZLKFzoZcc/9swI4PZNrx9cxTd zJ2s+XxNGD27kgffIDdbBkyUnN9INdg/7YtucJuNPE2RmKc3ybg/xaXn5ttn1Cak+LP78G65iDD p485fC6Z8RGjV/j48= X-Received: by 2002:a19:9114:0:b0:513:cd08:4d46 with SMTP id t20-20020a199114000000b00513cd084d46mr379286lfd.26.1710348674770; Wed, 13 Mar 2024 09:51:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIh4xxbd2mhX+mN12RXMfxiKWMN7Z5FMuBw3+THUeJO2s1snXsKlGM7ZV/klmQZ18tnWeYedSyaMl+3IoE1g0= X-Received: by 2002:a19:9114:0:b0:513:cd08:4d46 with SMTP id t20-20020a199114000000b00513cd084d46mr379270lfd.26.1710348674380; Wed, 13 Mar 2024 09:51:14 -0700 (PDT) MIME-Version: 1.0 References: <20240308144841.3615262-1-david.marchand@redhat.com> <20240308144841.3615262-5-david.marchand@redhat.com> <25bb9521-97fb-4466-8aca-237060d738ca@amd.com> In-Reply-To: <25bb9521-97fb-4466-8aca-237060d738ca@amd.com> From: David Marchand Date: Wed, 13 Mar 2024 17:51:02 +0100 Message-ID: Subject: Re: [PATCH 4/4] app/testpmd: enhance getopt_long usage To: Ferruh Yigit Cc: dev@dpdk.org, Aman Singh , Yuying Zhang X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Tue, Mar 12, 2024 at 6:03=E2=80=AFPM Ferruh Yigit = 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 alread= y > > did such parsing, rely on getopt_long return value. > > > > Note for reviewers: this patch is best reviewed once applied locally an= d > > displayed with git show -w. > > > > Thanks for the cleanup, it was needed. Thanks for the in depth review. > > > > Signed-off-by: David Marchand > > --- > > 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 =3D 'a', > > +#define TESTPMD_OPT_HELP "help" > > + TESTPMD_OPT_HELP_NUM =3D 'h', > > +#define TESTPMD_OPT_INTERACTIVE "interactive" > > + TESTPMD_OPT_INTERACTIVE_NUM =3D 'i', > > + > > + /* first long only option value must be >=3D 256 */ > > + TESTPMD_OPT_LONG_MIN_NUM =3D 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[] =3D { > > > > 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 intentiona= l. 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_PEER= S_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 =3D 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 addres= s: %s\n", > > - port_end); > > - nb_peer_eth_addrs++; > > - } > > + errno =3D 0; > > + n =3D strtoul(optarg, &port_end, 10); > > + if (errno !=3D 0 || port_end =3D=3D optarg || *po= rt_end++ !=3D ',') > > + rte_exit(EXIT_FAILURE, > > + "Invalid eth-peer: %s", optarg); > > + if (n >=3D RTE_MAX_ETHPORTS) > > + rte_exit(EXIT_FAILURE, > > + "eth-peer: port %d >=3D RTE_MAX_E= THPORTS(%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 !=3D 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 --=20 David Marchand