DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chengwen Feng <fengchengwen@huawei.com>
To: <thomas@monjalon.net>, <honest.jiang@foxmail.com>
Cc: <dev@dpdk.org>, <liuyonglong@huawei.com>
Subject: [PATCH 10/10] app/dma-perf: support specific error info
Date: Tue, 12 Aug 2025 10:07:08 +0800	[thread overview]
Message-ID: <20250812020708.16186-11-fengchengwen@huawei.com> (raw)
In-Reply-To: <20250812020708.16186-1-fengchengwen@huawei.com>

If some entry was not provided in section, it will be segment fault
in original impl. For example:
	dpdk-test-dma-perf --config ./config.ini
	config file parsing...
	Segmentation fault (core dumped)

This commit support specific error information, the new output (e.g.):
	dpdk-test-dma-perf --config ./config.ini
	config file parsing...
	Error: can't get entry 'dst_numa_node' in section 'case1'

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-dma-perf/main.c | 67 +++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 42 deletions(-)

diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c
index d8d1e3d3f8..9d17212d4c 100644
--- a/app/test-dma-perf/main.c
+++ b/app/test-dma-perf/main.c
@@ -158,6 +158,18 @@ run_test(uint32_t case_id, struct test_configure *case_cfg)
 	}
 }
 
+/* Exit process if the entry couldn't find in the section. */
+static const char *
+get_cfgfile_entry(struct rte_cfgfile *cfgfile, const char *section_name, const char *entry_name)
+{
+	const char *entry = rte_cfgfile_get_entry(cfgfile, section_name, entry_name);
+	if (entry == NULL) {
+		printf("Error: can't get entry '%s' in section '%s'\n", entry_name, section_name);
+		exit(1);
+	}
+	return entry;
+}
+
 static int
 parse_lcore(struct test_configure *test_case, const char *value)
 {
@@ -165,9 +177,6 @@ parse_lcore(struct test_configure *test_case, const char *value)
 	char *input;
 	struct lcore_dma_map_t *lcore_dma_map;
 
-	if (test_case == NULL || value == NULL)
-		return -1;
-
 	len = strlen(value);
 	input = (char *)malloc((len + 1) * sizeof(char));
 	strlcpy(input, value, len + 1);
@@ -195,9 +204,7 @@ static void
 parse_cpu_config(struct test_configure *test_case, int case_id,
 		     struct rte_cfgfile *cfgfile, char *section_name)
 {
-	const char *lcore;
-
-	lcore = rte_cfgfile_get_entry(cfgfile, section_name, "lcore");
+	const char *lcore = get_cfgfile_entry(cfgfile, section_name, "lcore");
 	int lcore_ret = parse_lcore(test_case, lcore);
 	if (lcore_ret < 0) {
 		printf("parse lcore error in case %d.\n", case_id);
@@ -213,9 +220,6 @@ parse_entry(const char *value, struct test_configure_entry *entry)
 	int args_nr = -1;
 	int ret;
 
-	if (value == NULL || entry == NULL)
-		goto out;
-
 	strncpy(input, value, 254);
 	if (*input == '\0')
 		goto out;
@@ -294,7 +298,7 @@ parse_dma_config(struct test_configure *test_case, int case_id,
 	int args_nr;
 	int i;
 
-	ring_size_str = rte_cfgfile_get_entry(cfgfile, section_name, "dma_ring_size");
+	ring_size_str = get_cfgfile_entry(cfgfile, section_name, "dma_ring_size");
 	args_nr = parse_entry(ring_size_str, &test_case->ring_size);
 	if (args_nr < 0) {
 		printf("parse error in case %d.\n", case_id);
@@ -305,13 +309,11 @@ parse_dma_config(struct test_configure *test_case, int case_id,
 
 	src_sges_str = rte_cfgfile_get_entry(cfgfile, section_name, "dma_src_sge");
 	if (src_sges_str != NULL)
-		test_case->nb_src_sges = (int)atoi(rte_cfgfile_get_entry(cfgfile,
-						section_name, "dma_src_sge"));
+		test_case->nb_src_sges = (int)atoi(src_sges_str);
 
 	dst_sges_str = rte_cfgfile_get_entry(cfgfile, section_name, "dma_dst_sge");
 	if (dst_sges_str != NULL)
-		test_case->nb_dst_sges = (int)atoi(rte_cfgfile_get_entry(cfgfile,
-						section_name, "dma_dst_sge"));
+		test_case->nb_dst_sges = (int)atoi(dst_sges_str);
 
 	if ((src_sges_str != NULL && dst_sges_str == NULL) ||
 	    (src_sges_str == NULL && dst_sges_str != NULL)) {
@@ -327,7 +329,7 @@ parse_dma_config(struct test_configure *test_case, int case_id,
 		test_case->is_sg = true;
 	}
 
-	kick_batch_str = rte_cfgfile_get_entry(cfgfile, section_name, "kick_batch");
+	kick_batch_str = get_cfgfile_entry(cfgfile, section_name, "kick_batch");
 	args_nr = parse_entry(kick_batch_str, &test_case->kick_batch);
 	if (args_nr < 0) {
 		printf("parse error in case %d.\n", case_id);
@@ -384,11 +386,7 @@ parse_global_config(struct rte_cfgfile *cfgfile)
 		return -1;
 	}
 
-	entry = rte_cfgfile_get_entry(cfgfile, GLOBAL_SECTION_NAME, "eal_args");
-	if (entry == NULL) {
-		printf("Error: GLOBAL section must have 'eal_args' entry!\n");
-		return -1;
-	}
+	entry = get_cfgfile_entry(cfgfile, GLOBAL_SECTION_NAME, "eal_args");
 	args = strdup(entry);
 	if (args == NULL) {
 		printf("Error: dup GLOBAL 'eal_args' failed!\n");
@@ -399,18 +397,10 @@ parse_global_config(struct rte_cfgfile *cfgfile)
 		global_cfg.eal_argv[i] = tokens[i];
 	global_cfg.eal_argc = i;
 
-	entry = rte_cfgfile_get_entry(cfgfile, GLOBAL_SECTION_NAME, "cache_flush");
-	if (entry == NULL) {
-		printf("Error: GLOBAL section don't has 'cache_flush' entry!\n");
-		return -1;
-	}
+	entry = get_cfgfile_entry(cfgfile, GLOBAL_SECTION_NAME, "cache_flush");
 	global_cfg.cache_flush = (uint8_t)atoi(entry);
 
-	entry = rte_cfgfile_get_entry(cfgfile, GLOBAL_SECTION_NAME, "test_seconds");
-	if (entry == NULL) {
-		printf("Error: GLOBAL section don't has 'test_seconds' entry!\n");
-		return -1;
-	}
+	entry = get_cfgfile_entry(cfgfile, GLOBAL_SECTION_NAME, "test_seconds");
 	global_cfg.test_secs = (uint16_t)atoi(entry);
 
 	return 0;
@@ -455,14 +445,7 @@ load_configs(const char *path)
 		}
 
 		test_case->is_valid = true;
-		case_type = rte_cfgfile_get_entry(cfgfile, section_name, "type");
-		if (case_type == NULL) {
-			printf("Error: No case type in case %d, the test will be finished here.\n",
-				i + 1);
-			test_case->is_valid = false;
-			continue;
-		}
-
+		case_type = get_cfgfile_entry(cfgfile, section_name, "type");
 		if (strcmp(case_type, DMA_MEM_COPY) == 0) {
 			test_case->test_type = TEST_TYPE_DMA_MEM_COPY;
 		} else if (strcmp(case_type, CPU_MEM_COPY) == 0) {
@@ -473,12 +456,12 @@ load_configs(const char *path)
 			continue;
 		}
 
-		test_case->src_numa_node = (int)atoi(rte_cfgfile_get_entry(cfgfile,
+		test_case->src_numa_node = (int)atoi(get_cfgfile_entry(cfgfile,
 								section_name, "src_numa_node"));
-		test_case->dst_numa_node = (int)atoi(rte_cfgfile_get_entry(cfgfile,
+		test_case->dst_numa_node = (int)atoi(get_cfgfile_entry(cfgfile,
 								section_name, "dst_numa_node"));
 		nb_vp = 0;
-		mem_size_str = rte_cfgfile_get_entry(cfgfile, section_name, "mem_size");
+		mem_size_str = get_cfgfile_entry(cfgfile, section_name, "mem_size");
 		args_nr = parse_entry(mem_size_str, &test_case->mem_size);
 		if (args_nr < 0) {
 			printf("parse error in case %d.\n", i + 1);
@@ -487,7 +470,7 @@ load_configs(const char *path)
 		} else if (args_nr == 4)
 			nb_vp++;
 
-		buf_size_str = rte_cfgfile_get_entry(cfgfile, section_name, "buf_size");
+		buf_size_str = get_cfgfile_entry(cfgfile, section_name, "buf_size");
 		args_nr = parse_entry(buf_size_str, &test_case->buf_size);
 		if (args_nr < 0) {
 			printf("parse error in case %d.\n", i + 1);
-- 
2.17.1


      parent reply	other threads:[~2025-08-12  2:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-11 10:54 [PATCH 0/9] bugfix and refactor of dma-perf Chengwen Feng
2025-08-11 10:54 ` [PATCH 1/9] app/dma-perf: fix use-after-free Chengwen Feng
2025-08-11 10:54 ` [PATCH 2/9] app/dma-perf: add global section for config file Chengwen Feng
2025-08-11 10:54 ` [PATCH 3/9] app/dma-perf: use argparse lib to parse argument Chengwen Feng
2025-08-11 10:54 ` [PATCH 4/9] app/dma-perf: refactor output csv Chengwen Feng
2025-08-11 10:54 ` [PATCH 5/9] app/dma-perf: support list DMA devices Chengwen Feng
2025-08-11 10:54 ` [PATCH 6/9] app/dma-perf: add more global config Chengwen Feng
2025-08-11 10:54 ` [PATCH 7/9] app/dma-perf: remove invalid or redundant field Chengwen Feng
2025-08-11 10:54 ` [PATCH 8/9] app/dma-perf: refactor load config function Chengwen Feng
2025-08-11 10:54 ` [PATCH 9/9] app/dma-perf: refactor benchmark function Chengwen Feng
2025-08-12  2:06 ` [PATCH 00/10] bugfix and refactor of dma-perf Chengwen Feng
2025-08-12  2:06   ` [PATCH 01/10] app/dma-perf: fix use-after-free Chengwen Feng
2025-08-12  2:07   ` [PATCH 02/10] app/dma-perf: add global section for config file Chengwen Feng
2025-08-12  2:07   ` [PATCH 03/10] app/dma-perf: use argparse lib to parse argument Chengwen Feng
2025-08-12  2:07   ` [PATCH 04/10] app/dma-perf: refactor output csv Chengwen Feng
2025-08-12  2:07   ` [PATCH 05/10] app/dma-perf: support list DMA devices Chengwen Feng
2025-08-12  2:07   ` [PATCH 06/10] app/dma-perf: add more global config Chengwen Feng
2025-08-12  2:07   ` [PATCH 07/10] app/dma-perf: remove invalid or redundant field Chengwen Feng
2025-08-12  2:07   ` [PATCH 08/10] app/dma-perf: refactor load config function Chengwen Feng
2025-08-12  2:07   ` [PATCH 09/10] app/dma-perf: refactor benchmark function Chengwen Feng
2025-08-12  2:07   ` Chengwen Feng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250812020708.16186-11-fengchengwen@huawei.com \
    --to=fengchengwen@huawei.com \
    --cc=dev@dpdk.org \
    --cc=honest.jiang@foxmail.com \
    --cc=liuyonglong@huawei.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).