DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: stable@dpdk.org, weiyuanx.li@intel.com,
	Bruce Richardson <bruce.richardson@intel.com>,
	Pablo de Lara <pablo.de.lara.guarch@intel.com>,
	Harry van Haaren <harry.van.haaren@intel.com>,
	Aaron Conole <aconole@redhat.com>
Subject: [PATCH v2 2/2] test: use cmdline library to validate args
Date: Fri, 20 May 2022 16:12:40 +0100	[thread overview]
Message-ID: <20220520151240.139566-3-bruce.richardson@intel.com> (raw)
In-Reply-To: <20220520151240.139566-1-bruce.richardson@intel.com>

When passing in test names to run via either the DPDK_TEST environment
variable or via extra argv parameters, the checks run on those commands
can miss valid commands that are registered with the cmdline library in
the initial context used to set it up. This is seen in the fact that the
"dump_*" set of commands are not callable via argv parameters, but can
be called manually.

To fix this, just use the commandline library to validate each command
before executing it, stopping execution when an error is encountered.
This also has the benefit of not having the test binrary drop to
interactive mode if all commandline parameters given are invalid.

Fixes: 9b848774a5dc ("test: use env variable to run tests")
Fixes: ace2f054ed43 ("test: take test names from command line")
Bugzilla ID: 1002

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/test/commands.c | 11 -----------
 app/test/test.c     | 24 +++++++-----------------
 2 files changed, 7 insertions(+), 28 deletions(-)

diff --git a/app/test/commands.c b/app/test/commands.c
index 887cabad64..31259e5c21 100644
--- a/app/test/commands.c
+++ b/app/test/commands.c
@@ -378,14 +378,3 @@ int commands_init(void)
 	cmd_autotest_autotest.string_data.str = commands;
 	return 0;
 }
-
-int command_valid(const char *cmd)
-{
-	struct test_command *t;
-
-	TAILQ_FOREACH(t, &commands_list, next) {
-		if (strcmp(t->command, cmd) == 0)
-			return 1;
-	}
-	return 0;
-}
diff --git a/app/test/test.c b/app/test/test.c
index e69cae3eea..ce25f468a6 100644
--- a/app/test/test.c
+++ b/app/test/test.c
@@ -186,22 +186,10 @@ main(int argc, char **argv)
 #ifdef RTE_LIB_CMDLINE
 	char *dpdk_test = getenv("DPDK_TEST");
 
-	if (dpdk_test && strlen(dpdk_test) == 0)
-		dpdk_test = NULL;
-
-	if (dpdk_test && !command_valid(dpdk_test)) {
-		RTE_LOG(WARNING, APP, "Invalid DPDK_TEST value '%s'\n", dpdk_test);
-		dpdk_test = NULL;
-	}
-
-	if (dpdk_test)
+	if (dpdk_test && strlen(dpdk_test) > 0)
 		tests[test_count++] = dpdk_test;
-	for (i = 1; i < argc; i++) {
-		if (!command_valid(argv[i]))
-			RTE_LOG(WARNING, APP, "Invalid test requested: '%s'\n", argv[i]);
-		else
-			tests[test_count++] = argv[i];
-	}
+	for (i = 1; i < argc; i++)
+		tests[test_count++] = argv[i];
 
 	if (test_count > 0) {
 		char buf[1024];
@@ -214,9 +202,11 @@ main(int argc, char **argv)
 
 		for (i = 0; i < test_count; i++) {
 			snprintf(buf, sizeof(buf), "%s\n", tests[i]);
-			if (cmdline_in(cl, buf, strlen(buf)) < 0) {
+			if (cmdline_parse_check(cl, buf) < 0) {
+				printf("Error: invalid test command: '%s'\n", tests[i]);
+				ret = -1;
+			} else if (cmdline_in(cl, buf, strlen(buf)) < 0) {
 				printf("error on cmdline input\n");
-
 				ret = -1;
 			} else
 				ret = last_test_result;
-- 
2.34.1


  parent reply	other threads:[~2022-05-20 15:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-20 14:56 [PATCH 0/2] fix uncallable unit tests (Bugzilla 1002) Bruce Richardson
2022-05-20 14:56 ` [PATCH 1/2] cmdline: add function to verify valid commands Bruce Richardson
2022-05-24 14:57   ` Ray Kinsella
2022-05-20 14:56 ` [PATCH 2/2] test: use cmdline library to validate args Bruce Richardson
2022-05-20 15:12 ` [PATCH v2 0/2] fix uncallable unit tests (Bugzilla 1002) Bruce Richardson
2022-05-20 15:12   ` [PATCH v2 1/2] cmdline: add function to verify valid commands Bruce Richardson
2022-05-23  6:52     ` Li, WeiyuanX
2022-06-07  8:08     ` Olivier Matz
2022-06-10 14:08       ` Bruce Richardson
2022-06-10 14:21         ` Olivier Matz
2022-05-20 15:12   ` Bruce Richardson [this message]
2022-06-07  8:08     ` [PATCH v2 2/2] test: use cmdline library to validate args Olivier Matz
2022-06-10 14:24 ` [PATCH v3 0/2] fix uncallable unit tests (Bugzilla 1002) Bruce Richardson
2022-06-10 14:24   ` [PATCH v3 1/2] cmdline: add function to verify valid commands Bruce Richardson
2022-06-10 14:24   ` [PATCH v3 2/2] test: use cmdline library to validate args Bruce Richardson
2022-06-13  9:22   ` [PATCH v3 0/2] fix uncallable unit tests (Bugzilla 1002) David Marchand

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=20220520151240.139566-3-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=aconole@redhat.com \
    --cc=dev@dpdk.org \
    --cc=harry.van.haaren@intel.com \
    --cc=pablo.de.lara.guarch@intel.com \
    --cc=stable@dpdk.org \
    --cc=weiyuanx.li@intel.com \
    /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).