From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH v2 3/3] app/testpmd: improve output when processing cmdline files
Date: Fri, 4 Jul 2025 19:34:36 +0100 [thread overview]
Message-ID: <20250704183437.25901-4-bruce.richardson@intel.com> (raw)
In-Reply-To: <20250704183437.25901-1-bruce.richardson@intel.com>
Two small improvements for the cmdline file processing in testpmd.
* Now that we support multiple files, change the prompt to indicate what
file is currently being processed, and just print an EOF message when
done.
* When not echoing, the "Read" verb in the message "Read CLI commands..."
is a little ambiguous, as it could mean "I have read", or "Go and read",
i.e. job done or job about to start. Tweak the text to "Finished reading"
which is unambiguous.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test-pmd/cmdline.c | 27 ++++++++++++++++++---
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 4 +--
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 5433678b5e..b2a7aa8afd 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include <libgen.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
@@ -14195,6 +14196,7 @@ cmdline_read_from_file(const char *filename, bool echo)
struct cmdline *cl;
int fd = -1;
int ret = 0;
+ char *prompt = NULL;
/* cmdline_file_new does not produce any output
* so when echoing is requested we open filename directly
@@ -14203,6 +14205,18 @@ cmdline_read_from_file(const char *filename, bool echo)
if (!echo) {
cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
} else {
+ char *filename_copy = strdup(filename);
+
+ if (filename_copy == NULL) {
+ fprintf(stderr, "Failed to allocate memory for filename\n");
+ return -1;
+ }
+ if (asprintf(&prompt, "[%s] ", basename(filename_copy)) < 0) {
+ fprintf(stderr, "Failed to allocate prompt string\n");
+ return -1;
+ }
+ free(filename_copy);
+
fd = open(filename, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Failed to open file %s: %s\n",
@@ -14210,7 +14224,7 @@ cmdline_read_from_file(const char *filename, bool echo)
return -1;
}
- cl = cmdline_new(main_ctx, "testpmd> ", fd, STDOUT_FILENO);
+ cl = cmdline_new(main_ctx, prompt, fd, STDOUT_FILENO);
}
if (cl == NULL) {
fprintf(stderr,
@@ -14221,15 +14235,22 @@ cmdline_read_from_file(const char *filename, bool echo)
}
cmdline_interact(cl);
- cmdline_quit(cl);
+ /* when done, if we have echo, we only need to print end of file,
+ * but if no echo, we need to use printf and include the filename.
+ */
+ if (echo)
+ cmdline_printf(cl, "<End-Of-File>\n");
+ else
+ printf("Finished reading CLI commands from %s\n", filename);
+ cmdline_quit(cl);
cmdline_free(cl);
- printf("Read CLI commands from %s\n", filename);
end:
if (fd >= 0)
close(fd);
+ free(prompt);
return ret;
}
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index b8a401fa6f..2b0c4897ba 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -90,7 +90,7 @@ practical or possible testpmd supports alternative methods for executing command
...
Flow rule #498 created
Flow rule #499 created
- Read all CLI commands from /home/ubuntu/flow-create-commands.txt
+ Finished reading all CLI commands from /home/ubuntu/flow-create-commands.txt
testpmd>
@@ -106,7 +106,7 @@ practical or possible testpmd supports alternative methods for executing command
...
Flow rule #498 created
Flow rule #499 created
- Read all CLI commands from /home/ubuntu/flow-create-commands.txt
+ Finished reading all CLI commands from /home/ubuntu/flow-create-commands.txt
testpmd>
--
2.48.1
prev parent reply other threads:[~2025-07-04 18:35 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 ` [PATCH v2 2/3] app/testpmd: allow multiple commandline file parameters Bruce Richardson
2025-07-04 18:34 ` Bruce Richardson [this message]
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-4-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).