From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by smtp.lore.kernel.org (Postfix) with ESMTP id 560E8C43458 for ; Mon, 6 Jul 2026 16:24:19 +0000 (UTC) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 115A44069D; Mon, 6 Jul 2026 18:24:09 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by mails.dpdk.org (Postfix) with ESMTP id BF62D4025F for ; Mon, 6 Jul 2026 18:24:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783355047; x=1814891047; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3TKE/DgICmZY1JIWgugnqbH7yct1+u2TEOVA3DDJpUk=; b=Gb9ZD5KVPAHqutILaqBbLUjJSF2aSStwjblzyeGRseXk2wBmndYieofh XKLXO++HZ3tJcoWSEbMYzgnL02cTFUeLo+TUopwrPdawOUMo/O3zDfDXd suUmk0NWYPJeyhv3WBZyLhjVh2S2WG024jaCjIxbGL6JMdAQp6HciFiQd vYxClZeOt7FpJmnfrOaSdj22rYC4z5hMflsagjwMmaMqGTRUhRpIDJ8uh Z5o+d28GEF/D0SNlzKtEgc68hAk1hM2sqm9F8GeidaLPctgrh2DGx4IWl FB9F2zowtmfJZYP570+QjzTao46z/qHqV1mlQKw0US27c20h5iEasI6a5 g==; X-CSE-ConnectionGUID: 6ToillO3TfqyRvdlnGtZ0w== X-CSE-MsgGUID: 5tqLSZaTRjqmOlr4UCG6BQ== X-IronPort-AV: E=McAfee;i="6800,10657,11838"; a="95148825" X-IronPort-AV: E=Sophos;i="6.25,151,1779174000"; d="scan'208";a="95148825" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2026 09:24:05 -0700 X-CSE-ConnectionGUID: mRhvMorlR+GuVc3BNqnuUQ== X-CSE-MsgGUID: JRreU+VkSCK08rZHK30g0w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,149,1779174000"; d="scan'208";a="257335626" Received: from silpixa00401385.ir.intel.com ([10.20.224.226]) by orviesa003.jf.intel.com with ESMTP; 06 Jul 2026 09:24:05 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , Cristian Dumitrescu Subject: [PATCH 26.11 2/4] test/cfgfile: validate config creation APIs Date: Mon, 6 Jul 2026 17:23:45 +0100 Message-ID: <20260706162348.460489-3-bruce.richardson@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260706162348.460489-1-bruce.richardson@intel.com> References: <20260706162348.460489-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 --- 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