Skip to content

Commit

Permalink
app/testpmd: report invalid command line parameter
Browse files Browse the repository at this point in the history
[ upstream commit 8fad2e5 ]

We currently do not check that a non option string has been passed to
testpmd.

Example:
$ ./master/app/testpmd --no-huge -m 512 --vdev net_null0 \
	--vdev net_null1 -- -i nb-cores=2 --total-num-mbuf 2048
[...]
testpmd> show config fwd
io packet forwarding - ports=2 - cores=1 - streams=2 - NUMA support
enabled, MP allocation mode: native
Logical Core 1 (socket 0) forwards packets on 2 streams:
  RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
  RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00

Here nb-cores=2 is just ignored, while the (probably sleepy) user did not
notice this.

Validate that all strings passed to testpmd are part of a known option.

After this patch:
$ ./master/app/testpmd --no-huge -m 512 --vdev net_null0 \
	--vdev net_null1 -- -i nb-cores=2 --total-num-mbuf 2048
[...]
Invalid parameter: nb-cores=2
EAL: Error - exiting with code: 1
  Cause: Command line incorrect

While at it, when passing an unknown option, print the string that gets
refused by getopt_long to help the user.

Fixes: af75078 ("first public release")

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
  • Loading branch information
david-marchand authored and kevintraynor committed Dec 11, 2019
1 parent 65bcaa3 commit 6abcaab
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/test-pmd/parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -1245,12 +1245,19 @@ launch_args_parse(int argc, char** argv)
break;
default:
usage(argv[0]);
printf("Invalid option: %s\n", argv[optind]);
rte_exit(EXIT_FAILURE,
"Command line is incomplete or incorrect\n");
break;
}
}

if (optind != argc) {
usage(argv[0]);
printf("Invalid parameter: %s\n", argv[optind]);
rte_exit(EXIT_FAILURE, "Command line is incorrect\n");
}

/* Set offload configuration from command line parameters. */
rx_mode.offloads = rx_offloads;
tx_mode.offloads = tx_offloads;
Expand Down

0 comments on commit 6abcaab

Please sign in to comment.