[RFC] app/test-pmd: add option to run startup cmds without echo
Checks
Commit Message
Depending on the scenario, a user may want to run testpmd with
pre-canned startup commands either with or without echoing of those
commands as they are executed. To observe progress of each command, or
to help determine what command an error response is printed for, echoing
is useful. When running a large number of commands, performance can be
improved by disabling the echo of each one.
Therefore, we can add a new cmdline-file-noecho command to testpmd to
allow running without echo. Behaviour is otherwise the same as
cmdline-file command.
When adding the new command also:
* fix leak of the fd when using the existing cmdline-file flag
* add cmdline-file (and cmdline-file-noecho) to the testpmd docs
Bugzilla ID: 1612
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test-pmd/cmdline.c | 29 ++++++++++++++++++---------
app/test-pmd/parameters.c | 9 ++++++++-
app/test-pmd/testpmd.c | 1 +
app/test-pmd/testpmd.h | 1 +
doc/guides/testpmd_app_ug/run_app.rst | 7 +++++++
5 files changed, 36 insertions(+), 11 deletions(-)
Comments
On Tue, 11 Feb 2025 16:44:02 +0000
Bruce Richardson <bruce.richardson@intel.com> wrote:
> Depending on the scenario, a user may want to run testpmd with
> pre-canned startup commands either with or without echoing of those
> commands as they are executed. To observe progress of each command, or
> to help determine what command an error response is printed for, echoing
> is useful. When running a large number of commands, performance can be
> improved by disabling the echo of each one.
>
> Therefore, we can add a new cmdline-file-noecho command to testpmd to
> allow running without echo. Behaviour is otherwise the same as
> cmdline-file command.
>
> When adding the new command also:
> * fix leak of the fd when using the existing cmdline-file flag
> * add cmdline-file (and cmdline-file-noecho) to the testpmd docs
>
> Bugzilla ID: 1612
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
The variable and option name seems awkward to me, but I can't think of
a better suggestion.
@@ -13855,24 +13855,29 @@ void
cmdline_read_from_file(const char *filename)
{
struct cmdline *cl;
+ int fd = -1;
- /* cmdline_file_new does not produce any output which is not ideal here.
- * Much better to show output of the commands, so we open filename directly
+ /* cmdline_file_new does not produce any output
+ * so when echoing is requested we open filename directly
* and then pass that to cmdline_new with stdout as the output path.
*/
- int fd = open(filename, O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "Failed to open file %s: %s\n",
- filename, strerror(errno));
- return;
- }
+ if (!echo_cmdline_file) {
+ cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
+ } else {
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to open file %s: %s\n",
+ filename, strerror(errno));
+ return;
+ }
- cl = cmdline_new(main_ctx, "testpmd> ", fd, STDOUT_FILENO);
+ cl = cmdline_new(main_ctx, "testpmd> ", fd, STDOUT_FILENO);
+ }
if (cl == NULL) {
fprintf(stderr,
"Failed to create file based cmdline context: %s\n",
filename);
- return;
+ goto end;
}
cmdline_interact(cl);
@@ -13881,6 +13886,10 @@ cmdline_read_from_file(const char *filename)
cmdline_free(cl);
printf("Read CLI commands from %s\n", filename);
+
+end:
+ if (fd >= 0)
+ close(fd);
}
void
@@ -51,6 +51,8 @@ enum {
TESTPMD_OPT_LONG_MIN_NUM = 256,
#define TESTPMD_OPT_CMDLINE_FILE "cmdline-file"
TESTPMD_OPT_CMDLINE_FILE_NUM,
+#define TESTPMD_OPT_CMDLINE_FILE_NOECHO "cmdline-file-noecho"
+ TESTPMD_OPT_CMDLINE_FILE_NOECHO_NUM,
#define TESTPMD_OPT_ETH_PEERS_CONFIGFILE "eth-peers-configfile"
TESTPMD_OPT_ETH_PEERS_CONFIGFILE_NUM,
#define TESTPMD_OPT_ETH_PEER "eth-peer"
@@ -269,6 +271,7 @@ static const struct option long_options[] = {
NO_ARG(TESTPMD_OPT_HELP),
NO_ARG(TESTPMD_OPT_INTERACTIVE),
REQUIRED_ARG(TESTPMD_OPT_CMDLINE_FILE),
+ REQUIRED_ARG(TESTPMD_OPT_CMDLINE_FILE_NOECHO),
REQUIRED_ARG(TESTPMD_OPT_ETH_PEERS_CONFIGFILE),
REQUIRED_ARG(TESTPMD_OPT_ETH_PEER),
NO_ARG(TESTPMD_OPT_TX_FIRST),
@@ -387,7 +390,8 @@ usage(char* progname)
printf("\nUsage: %s [EAL options] -- [testpmd options]\n\n",
progname);
printf(" --interactive: run in interactive mode.\n");
- printf(" --cmdline-file: execute cli commands before startup.\n");
+ printf(" --cmdline-file: execute cli commands before startup, echoing each command as it is run.\n");
+ printf(" --cmdline-file-noecho: execute cli commands before startup, without echoing each command.\n");
printf(" --auto-start: start forwarding on init "
"[always when non-interactive].\n");
printf(" --help: display this message and quit.\n");
@@ -956,6 +960,9 @@ launch_args_parse(int argc, char** argv)
exit(EXIT_SUCCESS);
break;
case TESTPMD_OPT_CMDLINE_FILE_NUM:
+ echo_cmdline_file = true;
+ /* fall-through */
+ case TESTPMD_OPT_CMDLINE_FILE_NOECHO_NUM:
printf("CLI commands to be read from %s\n",
optarg);
strlcpy(cmdline_filename, optarg,
@@ -106,6 +106,7 @@ uint8_t interactive = 0;
uint8_t auto_start = 0;
uint8_t tx_first;
char cmdline_filename[PATH_MAX] = {0};
+bool echo_cmdline_file;
/*
* NUMA support configuration.
@@ -508,6 +508,7 @@ extern uint8_t interactive;
extern uint8_t auto_start;
extern uint8_t tx_first;
extern char cmdline_filename[PATH_MAX]; /**< offline commands file */
+extern bool echo_cmdline_file; /** unset if cmdline-file-noecho is used */
extern uint8_t numa_support; /**< set by "--numa" parameter */
extern uint16_t port_topology; /**< set by "--port-topology" parameter */
extern uint8_t no_flush_rx; /**<set by "--no-flush-rx" parameter */
@@ -39,6 +39,13 @@ The command line options are:
Display a help message and quit.
+* ``--cmdline-file=filename, --cmdline-file-noecho=filename``
+
+ Read and execute commands from a file.
+ The file should contain the same commands that can be entered interactively.
+ When using ``cmdline-file``, each command is printed as it is executed.
+ When using ``cmdline-file-noecho``, the commands are executed silently.
+
* ``-a, --auto-start``
Start forwarding on initialization.