From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Cristian Dumitrescu <cristian.dumitrescu@intel.com>,
Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH v2 1/4] test/cfgfile: improve coverage for listing APIs
Date: Mon, 17 Aug 2026 15:57:21 +0100 [thread overview]
Message-ID: <20260817145855.1421504-2-bruce.richardson@intel.com> (raw)
In-Reply-To: <20260817145855.1421504-1-bruce.richardson@intel.com>
Improve cfgfile unit-test coverage for listing/index APIs, by adding
assertions for section and entry listing behavior, including:
* expected count validation
* listing sections and entries and checking expected results
* index-based listing checks
* sentinel verification to ensure only expected slots are written
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test/test_cfgfile.c | 53 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/app/test/test_cfgfile.c b/app/test/test_cfgfile.c
index 1e56473064..2f1c8ec423 100644
--- a/app/test/test_cfgfile.c
+++ b/app/test/test_cfgfile.c
@@ -93,7 +93,14 @@ static int
test_cfgfile_sample1(void)
{
struct rte_cfgfile *cfgfile;
+ struct rte_cfgfile_entry entries[4];
char filename[PATH_MAX];
+ char sec0[CFG_NAME_LEN] = {0};
+ char sec1[CFG_NAME_LEN] = {0};
+ char sec2[CFG_NAME_LEN] = "sentinel_section_2";
+ char sec3[CFG_NAME_LEN] = "sentinel_section_3";
+ char index_sec[CFG_NAME_LEN] = {0};
+ char *sections[] = { sec0, sec1, sec2, sec3 };
int ret;
ret = make_tmp_file(filename, "sample1", sample1_ini);
@@ -105,6 +112,52 @@ test_cfgfile_sample1(void)
ret = _test_cfgfile_sample(cfgfile);
TEST_ASSERT_SUCCESS(ret, "Failed to validate sample file: %d", ret);
+ ret = rte_cfgfile_num_sections(cfgfile, NULL, 0);
+ TEST_ASSERT(ret == 2, "Unexpected number of sections: %d", ret);
+
+ ret = rte_cfgfile_sections(cfgfile, sections, 4);
+ TEST_ASSERT(ret == 2, "Unexpected listed sections: %d", ret);
+ TEST_ASSERT(strcmp(sec0, "section1") == 0,
+ "Unexpected section at index 0: %s", sec0);
+ TEST_ASSERT(strcmp(sec1, "section2") == 0,
+ "Unexpected section at index 1: %s", sec1);
+ TEST_ASSERT(strcmp(sec2, "sentinel_section_2") == 0,
+ "Unexpected write past listed sections at index 2: %s", sec2);
+ TEST_ASSERT(strcmp(sec3, "sentinel_section_3") == 0,
+ "Unexpected write past listed sections at index 3: %s", sec3);
+
+ ret = rte_cfgfile_section_num_entries_by_index(cfgfile, index_sec, 0);
+ TEST_ASSERT(ret == 1, "Unexpected entry count at index 0: %d", ret);
+ TEST_ASSERT(strcmp(index_sec, "section1") == 0,
+ "Unexpected section name at index 0: %s", index_sec);
+
+ ret = rte_cfgfile_section_num_entries(cfgfile, "section2");
+ TEST_ASSERT(ret == 2, "Unexpected section2 entry count: %d", ret);
+
+ memset(entries, 0x5a, sizeof(entries));
+ ret = rte_cfgfile_section_entries(cfgfile, "section2", entries, 4);
+ TEST_ASSERT(ret == 2, "Unexpected section2 entry count: %d", ret);
+ TEST_ASSERT(strcmp(entries[0].name, "key2") == 0,
+ "Unexpected section2 first key: %s", entries[0].name);
+ TEST_ASSERT(strcmp(entries[0].value, "value2") == 0,
+ "Unexpected section2 first value: %s", entries[0].value);
+ TEST_ASSERT(strcmp(entries[1].name, "key3") == 0,
+ "Unexpected section2 second key: %s", entries[1].name);
+ TEST_ASSERT(strcmp(entries[1].value, "value3") == 0,
+ "Unexpected section2 second value: %s", entries[1].value);
+ TEST_ASSERT((unsigned char)entries[2].name[0] == 0x5a,
+ "Unexpected write past listed entries at index 2");
+ TEST_ASSERT((unsigned char)entries[3].name[0] == 0x5a,
+ "Unexpected write past listed entries at index 3");
+
+ memset(entries, 0x5a, sizeof(entries));
+ memset(index_sec, 0, sizeof(index_sec));
+ ret = rte_cfgfile_section_entries_by_index(cfgfile, 1, index_sec, entries, 4);
+ TEST_ASSERT(ret == 2,
+ "Unexpected entry count for section at index 1: %d", ret);
+ TEST_ASSERT(strcmp(index_sec, "section2") == 0,
+ "Unexpected section name at index 1: %s", index_sec);
+
ret = rte_cfgfile_close(cfgfile);
TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile");
--
2.53.0
next prev parent reply other threads:[~2026-08-17 14:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 16:23 [PATCH 26.11 0/4] extra unit tests for cfgfile library Bruce Richardson
2026-07-06 16:23 ` [PATCH 26.11 1/4] test/cfgfile: improve coverage for listing APIs Bruce Richardson
2026-07-06 16:23 ` [PATCH 26.11 2/4] test/cfgfile: validate config creation APIs Bruce Richardson
2026-07-06 16:23 ` [PATCH 26.11 3/4] test/cfgfile: verify file modification API Bruce Richardson
2026-07-06 16:23 ` [PATCH 26.11 4/4] test/cfgfile: test for long lines in file Bruce Richardson
2026-08-17 14:57 ` [PATCH v2 0/4] extra unit tests for cfgfile library Bruce Richardson
2026-08-17 14:57 ` Bruce Richardson [this message]
2026-08-17 14:57 ` [PATCH v2 2/4] test/cfgfile: validate config creation APIs Bruce Richardson
2026-08-17 14:57 ` [PATCH v2 3/4] test/cfgfile: verify file modification API Bruce Richardson
2026-08-17 14:57 ` [PATCH v2 4/4] test/cfgfile: test for long lines in file Bruce Richardson
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=20260817145855.1421504-2-bruce.richardson@intel.com \
--to=bruce.richardson@intel.com \
--cc=cristian.dumitrescu@intel.com \
--cc=dev@dpdk.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.