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 3/4] test/cfgfile: verify file modification API
Date: Mon, 6 Jul 2026 17:23:46 +0100 [thread overview]
Message-ID: <20260706162348.460489-4-bruce.richardson@intel.com> (raw)
In-Reply-To: <20260706162348.460489-1-bruce.richardson@intel.com>
Check that the has_entry API correctly reports the presence of a valid
entry, and then verify that if we use set_entry we can modify the value
- a modification that persists if we use the save API. In the same test,
also check that we can't use add_entry to modify an existing entry, and
that we can't use set_entry to add a missing entry.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test/test_cfgfile.c | 55 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/app/test/test_cfgfile.c b/app/test/test_cfgfile.c
index 5ed116866d..12da87aa5a 100644
--- a/app/test/test_cfgfile.c
+++ b/app/test/test_cfgfile.c
@@ -491,6 +491,60 @@ test_cfgfile_empty_file(void)
return 0;
}
+static int
+test_cfgfile_modify_entry(void)
+{
+ struct rte_cfgfile *cfgfile;
+ struct rte_cfgfile *loaded;
+ const char *value;
+ char filename[PATH_MAX];
+ int ret;
+
+ ret = make_tmp_file(filename, "sample1_set", sample1_ini);
+ TEST_ASSERT_SUCCESS(ret, "Failed to setup temp file");
+
+ cfgfile = rte_cfgfile_load(filename, 0);
+ TEST_ASSERT_NOT_NULL(cfgfile, "Failed to load config file");
+
+ ret = rte_cfgfile_has_entry(cfgfile, "section2", "key2");
+ TEST_ASSERT(ret == 1, "section2 key2 entry missing");
+
+ ret = rte_cfgfile_has_entry(cfgfile, "section2", "invalid_key");
+ TEST_ASSERT(ret == 0, "section2 'invalid_key' entry should be missing");
+
+ ret = rte_cfgfile_set_entry(cfgfile, "section2", "key2", "value_of_key2");
+ TEST_ASSERT_SUCCESS(ret, "Failed to set section2 key2");
+
+ /* check we can't set a nonexistent key */
+ ret = rte_cfgfile_set_entry(cfgfile, "section2", "invalid_key", "value_of_key4");
+ TEST_ASSERT(ret < 0, "Error, unexpectedly able to set nonexistent 'invalid_key'");
+
+ /* check we can't add an existing key */
+ ret = rte_cfgfile_add_entry(cfgfile, "section2", "key2", "value_of_key2");
+ TEST_ASSERT(ret < 0, "Error, unexpectedly able to add existing key2");
+
+ 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 cfgfile");
+
+ loaded = rte_cfgfile_load(filename, 0);
+ TEST_ASSERT_NOT_NULL(loaded, "Failed to reload saved cfgfile");
+
+ value = rte_cfgfile_get_entry(loaded, "section2", "key2");
+ TEST_ASSERT(strcmp("value_of_key2", value) == 0,
+ "Unexpected section2 key2 value: %s", value);
+
+ ret = rte_cfgfile_close(loaded);
+ TEST_ASSERT_SUCCESS(ret, "Failed to close reloaded cfgfile");
+
+ ret = remove(filename);
+ TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
+
+ return 0;
+}
+
static struct
unit_test_suite test_cfgfile_suite = {
.suite_name = "Test Cfgfile Unit Test Suite",
@@ -506,6 +560,7 @@ unit_test_suite test_cfgfile_suite = {
TEST_CASE(test_cfgfile_global_properties),
TEST_CASE(test_cfgfile_empty_file),
TEST_CASE(test_cfgfile_create_add_save_reload),
+ TEST_CASE(test_cfgfile_modify_entry),
TEST_CASES_END()
}
--
2.53.0
next prev parent reply other threads:[~2026-07-06 16:24 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 ` Bruce Richardson [this message]
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 ` [PATCH v2 1/4] test/cfgfile: improve coverage for listing APIs Bruce Richardson
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=20260706162348.460489-4-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.