]> git.droids-corp.org - dpdk.git/commitdiff
test: validate test names in non interactive mode
authorBruce Richardson <bruce.richardson@intel.com>
Fri, 10 Jun 2022 14:24:06 +0000 (15:24 +0100)
committerDavid Marchand <david.marchand@redhat.com>
Mon, 13 Jun 2022 09:18:39 +0000 (11:18 +0200)
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 binary drop to
interactive mode if all commandline parameters given are invalid.

Bugzilla ID: 1002
Fixes: 9b848774a5dc ("test: use env variable to run tests")
Fixes: ace2f054ed43 ("test: take test names from command line")
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
app/test/commands.c
app/test/test.c

index 887cabad64cfc685f694f20cefa08e615e0c7c5d..31259e5c21384145a86cfcc34d2f37f64658da60 100644 (file)
@@ -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;
-}
index 8a7dddde9b189401bc0eb874dfb916636e4a432f..fb073ff79590139032d966fc11818c4b48798f24 100644 (file)
@@ -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;