From patchwork Tue Jul 18 13:11:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyang He X-Patchwork-Id: 129614 X-Patchwork-Delegate: thomas@monjalon.net 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 E04AD42EA2; Tue, 18 Jul 2023 07:47:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7883A410D3; Tue, 18 Jul 2023 07:47:55 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id E6BCA40A84; Tue, 18 Jul 2023 07:47:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689659274; x=1721195274; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=dphi9lkjcXAJsGnvcLl71rUi2nx+2a3HjjSvJLEDD9k=; b=YT79JiNGioLKtXbtuqoSSws+WW9UVSLVGQjVdsBlYycBkaHKgn+STZOv bruHrIXvOqFblAy7OmbE03e9DeVSGGYMMnW+4wyf4iaq6sbMENUDxWcZJ 3h2ODlJUyfKQZdGgFmDt8G73LN+ZMZ0Rl6PKIFcCIpGOiMuoXKAwcg0Zo nTmveSd3JQV9/3kK8lMIbNON3FoNySOR8ssUWp8KP6u651rfVWhOoJgUE pwdjJCKr1fmgq3UIDDR4yIbKOWIiOtXbCkJfZMM8fv0lJ6orOH5Oa5szq 7JWq2g3S/HyRM3Scxtzum6Va8V1bFT7sEQLT+mi01Og2pqIJTj4MR5MgW Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10774"; a="432297739" X-IronPort-AV: E=Sophos;i="6.01,213,1684825200"; d="scan'208";a="432297739" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2023 22:43:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10774"; a="970106923" X-IronPort-AV: E=Sophos;i="6.01,213,1684825200"; d="scan'208";a="970106923" Received: from unknown (HELO root..) ([10.239.252.115]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2023 22:43:16 -0700 From: Shiyang He To: dev@dpdk.org Cc: yidingx.zhou@intel.com, Shiyang He , stable@dpdk.org, Cheng Jiang , Chengwen Feng , Yuan Wang , Jiayu Hu , Anoob Joseph Subject: [PATCH] app/dma-perf: parse the cmdline with getopt_long Date: Tue, 18 Jul 2023 13:11:17 +0000 Message-Id: <20230718131117.684986-1-shiyangx.he@intel.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 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 Use getopt_long to parse the command line for ease of extension and improved code readability. Fixes: 623dc9364dc6 ("app/dma-perf: introduce DMA performance test") Cc: stable@dpdk.org Signed-off-by: Shiyang He --- app/test-dma-perf/main.c | 60 ++++++++++++++++++++++++++---------- app/test-dma-perf/main.h | 4 +++ doc/guides/tools/dmaperf.rst | 2 +- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c index e5bccc27da..a7e00998e6 100644 --- a/app/test-dma-perf/main.c +++ b/app/test-dma-perf/main.c @@ -472,6 +472,36 @@ append_eal_args(int argc, char **argv, const char *eal_args, char **new_argv) return new_argc; } +/* + * Parse command line options. + */ +static void +parse_opts(struct test_options *options, int argc, char **argv) +{ + static const struct option long_options[] = { + { "config", required_argument, NULL, 0}, + { "result", required_argument, NULL, 1}, + { NULL }, + }; + + int opt_idx; + int opt; + + while ((opt = getopt_long(argc, argv, "", long_options, &opt_idx)) + != EOF) { + switch (opt) { + case 0: + options->cfg_path_ptr = optarg; + break; + case 1: + options->rst_path_ptr = optarg; + break; + default: + break; + } + } +} + int main(int argc, char *argv[]) { @@ -482,39 +512,35 @@ main(int argc, char *argv[]) int wstatus; char args[MAX_EAL_PARAM_NB][MAX_EAL_PARAM_LEN]; char *pargs[MAX_EAL_PARAM_NB]; - char *cfg_path_ptr = NULL; - char *rst_path_ptr = NULL; char rst_path[PATH_MAX]; int new_argc; + struct test_options opt; memset(args, 0, sizeof(args)); + memset(&opt, 0, sizeof(opt)); for (i = 0; i < RTE_DIM(pargs); i++) pargs[i] = args[i]; - for (i = 0; i < (uint32_t)argc; i++) { - if (strncmp(argv[i], CMDLINE_CONFIG_ARG, MAX_LONG_OPT_SZ) == 0) - cfg_path_ptr = argv[i + 1]; - if (strncmp(argv[i], CMDLINE_RESULT_ARG, MAX_LONG_OPT_SZ) == 0) - rst_path_ptr = argv[i + 1]; - } - if (cfg_path_ptr == NULL) { + parse_opts(&opt, argc, argv); + + if (opt.cfg_path_ptr == NULL) { printf("Config file not assigned.\n"); return -1; } - if (rst_path_ptr == NULL) { - strlcpy(rst_path, cfg_path_ptr, PATH_MAX); + if (opt.rst_path_ptr == NULL) { + strlcpy(rst_path, opt.cfg_path_ptr, PATH_MAX); char *token = strtok(basename(rst_path), "."); if (token == NULL) { printf("Config file error.\n"); return -1; } strcat(token, "_result.csv"); - rst_path_ptr = rst_path; + opt.rst_path_ptr = rst_path; } - case_nb = load_configs(cfg_path_ptr); - fd = fopen(rst_path_ptr, "w"); + case_nb = load_configs(opt.cfg_path_ptr); + fd = fopen(opt.rst_path_ptr, "w"); if (fd == NULL) { printf("Open output CSV file error.\n"); return -1; @@ -527,7 +553,7 @@ main(int argc, char *argv[]) printf("Invalid test case %d.\n\n", i + 1); snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Invalid case %d\n", i + 1); - fd = fopen(rst_path_ptr, "a"); + fd = fopen(opt.rst_path_ptr, "a"); if (!fd) { printf("Open output CSV file error.\n"); return 0; @@ -541,7 +567,7 @@ main(int argc, char *argv[]) printf("No valid test type in test case %d.\n\n", i + 1); snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Invalid case %d\n", i + 1); - fd = fopen(rst_path_ptr, "a"); + fd = fopen(opt.rst_path_ptr, "a"); if (!fd) { printf("Open output CSV file error.\n"); return 0; @@ -569,7 +595,7 @@ main(int argc, char *argv[]) rte_exit(EXIT_FAILURE, "There should be at least 2 worker lcores.\n"); - fd = fopen(rst_path_ptr, "a"); + fd = fopen(opt.rst_path_ptr, "a"); if (!fd) { printf("Open output CSV file error.\n"); return 0; diff --git a/app/test-dma-perf/main.h b/app/test-dma-perf/main.h index f65e264378..b2f870a4e0 100644 --- a/app/test-dma-perf/main.h +++ b/app/test-dma-perf/main.h @@ -18,6 +18,10 @@ extern char output_str[MAX_WORKER_NB + 1][MAX_OUTPUT_STR_LEN]; +struct test_options { + char *cfg_path_ptr; + char *rst_path_ptr; +}; typedef enum { OP_NONE = 0, OP_ADD, diff --git a/doc/guides/tools/dmaperf.rst b/doc/guides/tools/dmaperf.rst index 9e3e78a6b7..9fc77ca943 100644 --- a/doc/guides/tools/dmaperf.rst +++ b/doc/guides/tools/dmaperf.rst @@ -119,7 +119,7 @@ Typical command-line invocation to execute the application: .. code-block:: console - dpdk-test-dma-perf --config=./config_dma.ini --result=./res_dma.csv + dpdk-test-dma-perf --config ./config_dma.ini --result ./res_dma.csv Where ``config_dma.ini`` is the configuration file, and ``res_dma.csv`` will be the generated result file.