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 4397248984; Mon, 20 Oct 2025 06:11:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7AB0E42E37; Mon, 20 Oct 2025 06:11:20 +0200 (CEST) Received: from canpmsgout01.his.huawei.com (canpmsgout01.his.huawei.com [113.46.200.216]) by mails.dpdk.org (Postfix) with ESMTP id CAF38402A7 for ; Mon, 20 Oct 2025 06:11:14 +0200 (CEST) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=ATtFohmN4SgykGF0IHlsBWwptjb0FOWuY6q9k9zOHfA=; b=oSdgIC3Ic8UfgFpeyFFnc7f7qTlv1D/6f6ydgsHm/nwv/6VKGOv2vAhMeAtFUgR5q6whICCXJ UVABOu+nbtQQBo8vVf+bk8X8GKrgyyT1kh4uvKMy1ez9trAauIshsVjMhrWTZDPZMysl/SKKwi7 wDyTfFRkdYZtx80fUDHijTs= Received: from mail.maildlp.com (unknown [172.19.88.105]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4cqhmF40hTz1T4FV; Mon, 20 Oct 2025 12:10:21 +0800 (CST) Received: from kwepemk500009.china.huawei.com (unknown [7.202.194.94]) by mail.maildlp.com (Postfix) with ESMTPS id A81F71402CA; Mon, 20 Oct 2025 12:11:12 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by kwepemk500009.china.huawei.com (7.202.194.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 20 Oct 2025 12:11:12 +0800 From: Chengwen Feng To: , CC: , , Subject: [PATCH v4 03/14] app/dma-perf: use argparse lib to parse argument Date: Mon, 20 Oct 2025 12:10:54 +0800 Message-ID: <20251020041105.1590-4-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20251020041105.1590-1-fengchengwen@huawei.com> References: <20250811105430.55791-1-fengchengwen@huawei.com> <20251020041105.1590-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemk500009.china.huawei.com (7.202.194.94) 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 This commit uses argparse API to parse arguments. Signed-off-by: Chengwen Feng Acked-by: Vamsi Attunuru --- app/test-dma-perf/main.c | 94 +++++++++++++++++++++++------------ app/test-dma-perf/meson.build | 2 +- 2 files changed, 62 insertions(+), 34 deletions(-) diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c index 4a884567a0..c2b8544471 100644 --- a/app/test-dma-perf/main.c +++ b/app/test-dma-perf/main.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -26,13 +27,8 @@ #define DMA_MEM_COPY "DMA_MEM_COPY" #define CPU_MEM_COPY "CPU_MEM_COPY" -#define CMDLINE_CONFIG_ARG "--config" -#define CMDLINE_RESULT_ARG "--result" - #define MAX_PARAMS_PER_ENTRY 4 -#define MAX_LONG_OPT_SZ 64 - enum { TEST_TYPE_NONE = 0, TEST_TYPE_DMA_MEM_COPY, @@ -45,6 +41,9 @@ static struct test_configure test_cases[MAX_TEST_CASES]; #define GLOBAL_SECTION_NAME "GLOBAL" static struct global_configure global_cfg; +static char *config_path; +static char *result_path; + char output_str[MAX_WORKER_NB + 1][MAX_OUTPUT_STR_LEN]; static FILE *fd; @@ -535,54 +534,83 @@ load_configs(const char *path) return i; } -int -main(int argc, char *argv[]) +static int +parse_args(int argc, char **argv) { + static struct rte_argparse obj = { + .prog_name = "test-dma-perf", + .usage = "[optional parameters]", + .descriptor = NULL, + .epilog = NULL, + .exit_on_error = true, + .args = { + { "--config", NULL, "Specify a configuration file", + (void *)&config_path, NULL, + RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_STR, + }, + { "--result", NULL, "Optional, specify a result file name", + (void *)&result_path, NULL, + RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_STR, + }, + ARGPARSE_ARG_END(), + }, + }; + char rst_path[PATH_MAX + 16] = {0}; int ret; - uint16_t case_nb; - uint32_t i, nb_lcores; - pid_t cpid, wpid; - int wstatus; - char *cfg_path_ptr = NULL; - char *rst_path_ptr = NULL; - char rst_path[PATH_MAX]; - - 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) { + + ret = rte_argparse_parse(&obj, argc, argv); + if (ret < 0) + exit(1); + + if (config_path == NULL) { printf("Config file not assigned.\n"); - return -1; + exit(1); } - if (rst_path_ptr == NULL) { - rte_basename(cfg_path_ptr, rst_path, sizeof(rst_path)); + + if (result_path == NULL) { + rte_basename(config_path, rst_path, sizeof(rst_path)); char *token = strtok(rst_path, "."); if (token == NULL) { printf("Config file error.\n"); return -1; } strlcat(token, "_result.csv", sizeof(rst_path)); - rst_path_ptr = rst_path; + result_path = strdup(rst_path); + if (result_path == NULL) { + printf("Generate result file path error.\n"); + exit(1); + } } - - case_nb = load_configs(cfg_path_ptr); - fd = fopen(rst_path_ptr, "w"); + fd = fopen(result_path, "w"); if (fd == NULL) { printf("Open output CSV file error.\n"); - return -1; + exit(1); } fclose(fd); + return 0; +} + +int +main(int argc, char *argv[]) +{ + uint32_t i, nb_lcores; + pid_t cpid, wpid; + uint16_t case_nb; + int wstatus; + int ret; + + parse_args(argc, argv); + + case_nb = load_configs(config_path); + printf("Running cases...\n"); for (i = 0; i < case_nb; i++) { if (test_cases[i].is_skip) { printf("Test case %d configured to be skipped.\n\n", i + 1); snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Skip the test-case %d\n", i + 1); - if (open_output_csv(rst_path_ptr)) + if (open_output_csv(result_path)) return 0; continue; } @@ -590,7 +618,7 @@ main(int argc, char *argv[]) if (!test_cases[i].is_valid) { printf("Invalid test case %d.\n\n", i + 1); snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Invalid case %d\n", i + 1); - if (open_output_csv(rst_path_ptr)) + if (open_output_csv(result_path)) return 0; continue; } @@ -612,7 +640,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(result_path, "a"); if (!fd) { printf("Open output CSV file error.\n"); return 0; diff --git a/app/test-dma-perf/meson.build b/app/test-dma-perf/meson.build index 40d6b7f8e4..02af3128d8 100644 --- a/app/test-dma-perf/meson.build +++ b/app/test-dma-perf/meson.build @@ -7,7 +7,7 @@ if is_windows subdir_done() endif -deps += ['dmadev', 'mbuf', 'cfgfile'] +deps += ['dmadev', 'mbuf', 'cfgfile', 'argparse'] sources = files( 'main.c', -- 2.17.1