From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BCAAAA0503; Fri, 20 May 2022 16:57:02 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 49F4642B70; Fri, 20 May 2022 16:57:02 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id 723A5427F8; Fri, 20 May 2022 16:57:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653058620; x=1684594620; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fQleqdprc8AbxgntnmqoxqIqkz/nj+F7LqOX7L5iSyA=; b=T2tpem8u7jNZ9djHlkAQMIjW+Nm3FFXNMIFkY685dF+yX15S7uy15NoD 80TG+/FcdkPTkjCXk5GPj7zU4z/uXaY4IOYXm5iUFz0zWlODIM3ByEMeD i1CzTul6S+WnsjUaclzE/46DaxYhwqvC+ST879uw+SOhwe5PyUhScYZlb TiCh2a1PueLokRv0ZatGzBMfbh7uamue90FDzhg3nPuC9iawMXo3FHHlq PZi6lAPk2BnOyE8JVi31N2/oBLH+MaGdORT2LwuSxCg1oGW85Zo0rEp0k iyEzHFthHdTr5JSzliEdU0XYR23GDnEL72Z6hYGJ2cfGIkNwTsi5bFqXf Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10353"; a="271444697" X-IronPort-AV: E=Sophos;i="5.91,239,1647327600"; d="scan'208";a="271444697" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2022 07:56:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,239,1647327600"; d="scan'208";a="599257521" Received: from silpixa00401385.ir.intel.com (HELO silpixa00401385.ger.corp.intel.com.) ([10.237.223.87]) by orsmga008.jf.intel.com with ESMTP; 20 May 2022 07:56:57 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: stable@dpdk.org, weiyuanx.li@intel.com, xuemingx.zhang@intel.com, Bruce Richardson , Pablo de Lara , Harry van Haaren , Aaron Conole Subject: [PATCH 2/2] test: use cmdline library to validate args Date: Fri, 20 May 2022 15:56:31 +0100 Message-Id: <20220520145631.137962-3-bruce.richardson@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220520145631.137962-1-bruce.richardson@intel.com> References: <20220520145631.137962-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- app/test/commands.c | 11 ----------- app/test/test.c | 25 ++++++++----------------- 2 files changed, 8 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..5b308ea6a3 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,12 @@ 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