From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Subject: [PATCH 26.11 2/4] test/cfgfile: validate config creation APIs
Date: Mon, 6 Jul 2026 17:23:45 +0100 [thread overview]
Message-ID: <20260706162348.460489-3-bruce.richardson@intel.com> (raw)
In-Reply-To: <20260706162348.460489-1-bruce.richardson@intel.com>
Add a test case creating a new configfile and then saving that to disk.
Verify the result by reading the file back in and checking entries are
as expected.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test/test_cfgfile.c | 69 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/app/test/test_cfgfile.c b/app/test/test_cfgfile.c
index 2f1c8ec423..5ed116866d 100644
--- a/app/test/test_cfgfile.c
+++ b/app/test/test_cfgfile.c
@@ -197,6 +197,74 @@ test_cfgfile_sample2(void)
return 0;
}
+static int
+test_cfgfile_create_add_save_reload(void)
+{
+ struct rte_cfgfile *cfgfile;
+ struct rte_cfgfile *loaded;
+ const char *value;
+ char filename[PATH_MAX];
+ int ret;
+
+ cfgfile = rte_cfgfile_create(0);
+ TEST_ASSERT_NOT_NULL(cfgfile, "Failed to create cfgfile");
+
+ ret = rte_cfgfile_add_section(cfgfile, "section1");
+ TEST_ASSERT_SUCCESS(ret, "Failed to add section1");
+ ret = rte_cfgfile_add_entry(cfgfile, "section1", "key1", "value1");
+ TEST_ASSERT_SUCCESS(ret, "Failed to add section1 key1");
+ ret = rte_cfgfile_add_entry(cfgfile, "section1", "key2", "value2");
+ TEST_ASSERT_SUCCESS(ret, "Failed to add section1 key2");
+
+ ret = rte_cfgfile_add_section(cfgfile, "section2");
+ TEST_ASSERT_SUCCESS(ret, "Failed to add section2");
+ ret = rte_cfgfile_add_entry(cfgfile, "section2", "key3", "value3");
+ TEST_ASSERT_SUCCESS(ret, "Failed to add section2 key3");
+ ret = rte_cfgfile_add_entry(cfgfile, "section2", "key4", "value4");
+ TEST_ASSERT_SUCCESS(ret, "Failed to add section2 key4");
+
+ ret = make_tmp_file(filename, "create_save", "");
+ TEST_ASSERT_SUCCESS(ret, "Failed to make temporary output file");
+
+ ret = rte_cfgfile_save(cfgfile, filename);
+ TEST_ASSERT_SUCCESS(ret, "Failed to save cfgfile");
+
+ ret = rte_cfgfile_close(cfgfile);
+ TEST_ASSERT_SUCCESS(ret, "Failed to close created cfgfile");
+
+ loaded = rte_cfgfile_load(filename, 0);
+ TEST_ASSERT_NOT_NULL(loaded, "Failed to load saved cfgfile");
+
+ ret = rte_cfgfile_num_sections(loaded, NULL, 0);
+ TEST_ASSERT(ret == 2, "Unexpected number of sections: %d", ret);
+
+ ret = rte_cfgfile_section_num_entries(loaded, "section1");
+ TEST_ASSERT(ret == 2, "Unexpected section1 entries: %d", ret);
+ ret = rte_cfgfile_section_num_entries(loaded, "section2");
+ TEST_ASSERT(ret == 2, "Unexpected section2 entries: %d", ret);
+
+ value = rte_cfgfile_get_entry(loaded, "section1", "key1");
+ TEST_ASSERT(strcmp("value1", value) == 0,
+ "section1 key1 unexpected value: %s", value);
+ value = rte_cfgfile_get_entry(loaded, "section1", "key2");
+ TEST_ASSERT(strcmp("value2", value) == 0,
+ "section1 key2 unexpected value: %s", value);
+ value = rte_cfgfile_get_entry(loaded, "section2", "key3");
+ TEST_ASSERT(strcmp("value3", value) == 0,
+ "section2 key3 unexpected value: %s", value);
+ value = rte_cfgfile_get_entry(loaded, "section2", "key4");
+ TEST_ASSERT(strcmp("value4", value) == 0,
+ "section2 key4 unexpected value: %s", value);
+
+ ret = rte_cfgfile_close(loaded);
+ TEST_ASSERT_SUCCESS(ret, "Failed to close loaded cfgfile");
+
+ ret = remove(filename);
+ TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
+
+ return 0;
+}
+
static int
test_cfgfile_realloc_sections(void)
{
@@ -437,6 +505,7 @@ unit_test_suite test_cfgfile_suite = {
TEST_CASE(test_cfgfile_missing_section),
TEST_CASE(test_cfgfile_global_properties),
TEST_CASE(test_cfgfile_empty_file),
+ TEST_CASE(test_cfgfile_create_add_save_reload),
TEST_CASES_END()
}
--
2.53.0
next prev parent reply other threads:[~2026-07-06 16:24 UTC|newest]
Thread overview: 5+ 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 ` Bruce Richardson [this message]
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
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=20260706162348.460489-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox