From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH v2 2/3] app/testpmd: allow multiple commandline file parameters
Date: Fri, 4 Jul 2025 19:34:35 +0100 [thread overview]
Message-ID: <20250704183437.25901-3-bruce.richardson@intel.com> (raw)
In-Reply-To: <20250704183437.25901-1-bruce.richardson@intel.com>
While testpmd allows a set of pre-prepared commands to be passed into it
at startup via the "cmdline-file" (and cmdline-file-noecho) parameters,
this is currently limited to a single file. By extending this support
to allow the parameter to be passed multiple (up to 16) times, we enable
users to have a library of pre-canned cmdline files and pass multiple of
these in to the same run, e.g. have one cmdline file per NIC feature and
enable multiple features by passing in multiple filenames.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test-pmd/parameters.c | 17 +++++++++++------
app/test-pmd/testpmd.c | 13 +++++++++----
app/test-pmd/testpmd.h | 13 +++++++++++--
doc/guides/testpmd_app_ug/run_app.rst | 3 ++-
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 6 +++---
5 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 1132972913..ce2ba1c826 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -960,13 +960,18 @@ 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,
- sizeof(cmdline_filename));
+ if (cmdline_file_count >= RTE_DIM(cmdline_files)) {
+ fprintf(stderr, "Too many cmdline files specified (maximum %zu)\n",
+ RTE_DIM(cmdline_files));
+ exit(EXIT_FAILURE);
+ }
+ printf("CLI commands to be read from %s\n", optarg);
+ strlcpy(cmdline_files[cmdline_file_count].filename, optarg,
+ sizeof(cmdline_files[cmdline_file_count].filename));
+ cmdline_files[cmdline_file_count].echo =
+ (opt == TESTPMD_OPT_CMDLINE_FILE_NUM);
+ cmdline_file_count++;
break;
case TESTPMD_OPT_TX_FIRST_NUM:
printf("Ports to start sending a burst of "
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index b498e6d9fe..505e0283fa 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -105,8 +105,8 @@ int testpmd_logtype; /**< Log type for testpmd logs */
uint8_t interactive = 0;
uint8_t auto_start = 0;
uint8_t tx_first;
-char cmdline_filename[PATH_MAX] = {0};
-bool echo_cmdline_file;
+struct cmdline_file_info cmdline_files[MAX_CMDLINE_FILENAMES] = {0};
+unsigned int cmdline_file_count;
/*
* NUMA support configuration.
@@ -4508,8 +4508,13 @@ main(int argc, char** argv)
rte_exit(EXIT_FAILURE,
"Could not initialise cmdline context.\n");
- if (strlen(cmdline_filename) != 0)
- cmdline_read_from_file(cmdline_filename, echo_cmdline_file);
+ for (unsigned int i = 0; i < cmdline_file_count; i++) {
+ if (cmdline_read_from_file(cmdline_files[i].filename, cmdline_files[i].echo) != 0) {
+ fprintf(stderr, "Failed to process cmdline file: %s\n",
+ cmdline_files[i].filename);
+ break;
+ }
+ }
if (interactive == 1) {
if (auto_start) {
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 1d34f40deb..6ee229cb5c 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -36,6 +36,15 @@
extern uint8_t cl_quit;
extern volatile uint8_t f_quit;
+/* Max number of cmdline files we can take on testpmd cmdline */
+#define MAX_CMDLINE_FILENAMES 16
+
+/* Structure to track cmdline files and their echo settings */
+struct cmdline_file_info {
+ char filename[PATH_MAX]; /**< Path to the cmdline file */
+ bool echo; /**< Whether to echo commands from this file */
+};
+
/*
* It is used to allocate the memory for hash key.
* The hash key size is NIC dependent.
@@ -509,8 +518,8 @@ extern int testpmd_logtype; /**< Log type for testpmd logs */
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 struct cmdline_file_info cmdline_files[MAX_CMDLINE_FILENAMES]; /**< offline commands files */
+extern unsigned int cmdline_file_count; /**< number of cmdline files */
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 330c37f2d9..680ecefac2 100644
--- a/doc/guides/testpmd_app_ug/run_app.rst
+++ b/doc/guides/testpmd_app_ug/run_app.rst
@@ -41,8 +41,9 @@ The command line options are:
* ``--cmdline-file=filename, --cmdline-file-noecho=filename``
- Read and execute commands from a file.
+ At startup, read and execute commands from a file.
The file should contain the same commands that can be entered interactively.
+ This option can be specified multiple times to process several files in sequence.
When using ``cmdline-file``, each command is printed as it is executed.
When using ``cmdline-file-noecho``, the commands are executed silently.
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index e12585f025..b8a401fa6f 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -67,13 +67,13 @@ Command File Functions
To facilitate loading large number of commands or to avoid cutting and pasting where not
practical or possible testpmd supports alternative methods for executing commands.
-* If started with the ``--cmdline-file=FILENAME`` command line argument testpmd
- will execute all CLI commands contained within the file immediately before
+* If started with the ``--cmdline-file=FILENAME`` or ``--cmdline-file-noecho=FILENAME`` command line argument,
+ testpmd will execute all CLI commands contained within the file immediately before
starting packet forwarding or entering interactive mode.
.. code-block:: console
- ./dpdk-testpmd -n4 -r2 ... -- -i --cmdline-file=/home/ubuntu/flow-create-commands.txt
+ ./dpdk-testpmd ... -- -i --cmdline-file-noecho=/home/ubuntu/flow-create-commands.txt
Interactive-mode selected
CLI commands to be read from /home/ubuntu/flow-create-commands.txt
Configuring Port 0 (socket 0)
--
2.48.1
next prev parent reply other threads:[~2025-07-04 18:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-04 14:05 [PATCH] app/testpmd: allow multiple cmdline-file parameters Bruce Richardson
2025-07-04 18:34 ` [PATCH v2 0/3] improve cmdline file handling in testpmd Bruce Richardson
2025-07-04 18:34 ` [PATCH v2 1/3] app/testpmd: explicitly set command echoing on file load Bruce Richardson
2025-07-04 18:34 ` Bruce Richardson [this message]
2025-07-04 18:34 ` [PATCH v2 3/3] app/testpmd: improve output when processing cmdline files Bruce Richardson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250704183437.25901-3-bruce.richardson@intel.com \
--to=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).