From patchwork Wed Jan 27 17:42:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 87452 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 92ABEA052A; Wed, 27 Jan 2021 18:43:12 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1C9A4141009; Wed, 27 Jan 2021 18:43:12 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 0DDDF140FDD for ; Wed, 27 Jan 2021 18:43:09 +0100 (CET) IronPort-SDR: 2vYys8BoBU9nLYv8kuADXtUvzt37UV6QBw7Zx7n+OLtSbu3QvzJFQg8FmnIN++kacoPMXj127l NLl+4F+eATag== X-IronPort-AV: E=McAfee;i="6000,8403,9877"; a="244183406" X-IronPort-AV: E=Sophos;i="5.79,380,1602572400"; d="scan'208";a="244183406" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 09:43:08 -0800 IronPort-SDR: UjyTEhKpTd4/5MrsichtKYQpk7ttnDZcESvwtHuKNlka693dyQCncPpzpTL1rknQJAjbDBNoXe 1nLtNMkSEpFw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,380,1602572400"; d="scan'208";a="578226595" Received: from silpixa00399126.ir.intel.com ([10.237.222.4]) by fmsmga005.fm.intel.com with ESMTP; 27 Jan 2021 09:43:07 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: aconole@redhat.com, Bruce Richardson Date: Wed, 27 Jan 2021 17:42:55 +0000 Message-Id: <20210127174255.1671738-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH] test: allow taking test names from commandline 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 Sender: "dev" While having the ability to run a test based off the DPDK_TEST environment variable is useful, it's often easier to specify the test name as a commandline parameter to a test binary. This also allows the test runs to be saved as part of the shell cmdline history. This patch adds support for checking all parameters after the EAL ones, and running all valid autotests requested - either from DPDK_TEST or on the commandline. This also allows multiple tests to be run in a single automated session, which is useful for working with components which have multiple test suites. Signed-off-by: Bruce Richardson Acked-by: Aaron Conole --- app/test/commands.c | 11 +++++++++++ app/test/test.c | 40 +++++++++++++++++++++++++++++++++------- app/test/test.h | 1 + 3 files changed, 45 insertions(+), 7 deletions(-) -- 2.27.0 diff --git a/app/test/commands.c b/app/test/commands.c index d48dd513d7..76f6ee5d23 100644 --- a/app/test/commands.c +++ b/app/test/commands.c @@ -381,3 +381,14 @@ 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 624dd48042..b4ef2bf22b 100644 --- a/app/test/test.c +++ b/app/test/test.c @@ -93,6 +93,9 @@ main(int argc, char **argv) { #ifdef RTE_LIB_CMDLINE struct cmdline *cl; + char *tests[argc]; /* store an array of tests to run */ + int test_count = 0; + int i; #endif char *extra_args; int ret; @@ -147,6 +150,7 @@ main(int argc, char **argv) } argv += ret; + argc -= ret; prgname = argv[0]; @@ -165,7 +169,25 @@ main(int argc, char **argv) #ifdef RTE_LIB_CMDLINE char *dpdk_test = getenv("DPDK_TEST"); - if (dpdk_test && strlen(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) + 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]; + } + + if (test_count > 0) { char buf[1024]; cl = cmdline_new(main_ctx, "RTE>>", 0, 1); @@ -174,13 +196,17 @@ main(int argc, char **argv) goto out; } - snprintf(buf, sizeof(buf), "%s\n", dpdk_test); - if (cmdline_in(cl, buf, strlen(buf)) < 0) { - printf("error on cmdline input\n"); + for (i = 0; i < test_count; i++) { + snprintf(buf, sizeof(buf), "%s\n", tests[i]); + if (cmdline_in(cl, buf, strlen(buf)) < 0) { + printf("error on cmdline input\n"); - ret = -1; - } else { - ret = last_test_result; + ret = -1; + } else + ret = last_test_result; + + if (ret != 0) + break; } cmdline_free(cl); goto out; diff --git a/app/test/test.h b/app/test/test.h index b07f6c1ef0..cd047eb26c 100644 --- a/app/test/test.h +++ b/app/test/test.h @@ -152,6 +152,7 @@ extern int last_test_result; extern const char *prgname; int commands_init(void); +int command_valid(const char *cmd); int test_mp_secondary(void); int test_timer_secondary(void);