* [RFC PATCH] app/test-pmd: add option to run startup cmds without echo
@ 2025-02-11 16:44 Bruce Richardson
2025-02-11 17:42 ` Stephen Hemminger
0 siblings, 1 reply; 2+ messages in thread
From: Bruce Richardson @ 2025-02-11 16:44 UTC (permalink / raw)
To: dev; +Cc: pdamouny, Bruce Richardson
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(-)
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 2897e44c34..1381ee6874 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -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
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 7b31b94542..1132972913 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -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,
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index ac654048df..f7dc6a9590 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -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.
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 260e4761bd..425b608e3e 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -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 */
diff --git a/doc/guides/testpmd_app_ug/run_app.rst b/doc/guides/testpmd_app_ug/run_app.rst
index 48717707a7..330c37f2d9 100644
--- a/doc/guides/testpmd_app_ug/run_app.rst
+++ b/doc/guides/testpmd_app_ug/run_app.rst
@@ -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.
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [RFC PATCH] app/test-pmd: add option to run startup cmds without echo
2025-02-11 16:44 [RFC PATCH] app/test-pmd: add option to run startup cmds without echo Bruce Richardson
@ 2025-02-11 17:42 ` Stephen Hemminger
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2025-02-11 17:42 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev, pdamouny
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-11 17:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-11 16:44 [RFC PATCH] app/test-pmd: add option to run startup cmds without echo Bruce Richardson
2025-02-11 17:42 ` Stephen Hemminger
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).