From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 9C01569D4 for ; Wed, 29 Mar 2017 11:33:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490779989; x=1522315989; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Wzc4aHheHCcBAlVqNPidcOvaHWDH9y0EiIvjn6Rocfg=; b=NVta/eOYS6JDmlTsTKcyyyYqRq2YS4QR9zBbZS0vZxqQr6boBm+yy9Zo 5tVwYTPxgqRX/KMvfVIr9PQ7MhitrA==; Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Mar 2017 02:33:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,240,1486454400"; d="scan'208";a="80520846" Received: from irsmsx106.ger.corp.intel.com ([163.33.3.31]) by orsmga005.jf.intel.com with ESMTP; 29 Mar 2017 02:33:04 -0700 Received: from irsmsx108.ger.corp.intel.com ([169.254.11.239]) by IRSMSX106.ger.corp.intel.com ([169.254.8.202]) with mapi id 14.03.0319.002; Wed, 29 Mar 2017 10:33:03 +0100 From: "Dumitrescu, Cristian" To: "Legacy, Allain (Wind River)" , "Richardson, Bruce" CC: "dev@dpdk.org" , "yuanhan.liu@linux.intel.com" , "thomas.monjalon@6wind.com" Thread-Topic: [PATCH v3 2/6] cfgfile: add support for global properties section Thread-Index: AQHSqCYZLfz1FhXKrE+XRWKDMdmwzaGrjh/Q Date: Wed, 29 Mar 2017 09:33:02 +0000 Message-ID: <3EB4FA525960D640B5BDFFD6A3D8912652781446@IRSMSX108.ger.corp.intel.com> References: <1489065060-98370-1-git-send-email-allain.legacy@windriver.com> <20170329004737.44249-1-allain.legacy@windriver.com> <20170329004737.44249-3-allain.legacy@windriver.com> In-Reply-To: <20170329004737.44249-3-allain.legacy@windriver.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMGMyNWU1NTctNThiNC00NmU3LWJhNjgtOThlNzhmNjFmNDFmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6InRcL0UrXC9xeHJhcnNVZXlMYkhMUHZGSUhVV0RIXC91T01xVmxZNStLcCtrcWM9In0= x-ctpclassification: CTP_IC x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v3 2/6] cfgfile: add support for global properties section X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Mar 2017 09:33:10 -0000 > -----Original Message----- > From: Allain Legacy [mailto:allain.legacy@windriver.com] > Sent: Wednesday, March 29, 2017 1:48 AM > To: Dumitrescu, Cristian ; Richardson, Bru= ce > > Cc: dev@dpdk.org; yuanhan.liu@linux.intel.com; > thomas.monjalon@6wind.com > Subject: [PATCH v3 2/6] cfgfile: add support for global properties sectio= n >=20 > The current implementation of the cfgfile library requires that all > key=3Dvalue pairs be within [SECTION] definitions. The ini file standard > allows for key=3Dvalue pairs in an unnamed section. >=20 > https://en.wikipedia.org/wiki/INI_file#Global_properties >=20 > This commit adds the capability of parsing key=3Dvalue pairs from such an > unnamed section. The CFG_FLAG_GLOBAL_SECTION flag must be passed to > the > rte_cfgfile_load() API to enable this functionality. Any key=3Dvalue pai= rs > found before the first section can be accessed in the section named > "GLOBAL". >=20 > Signed-off-by: Allain Legacy > --- > lib/librte_cfgfile/rte_cfgfile.c | 16 ++++++++++++++++ > lib/librte_cfgfile/rte_cfgfile.h | 10 +++++++++- > test/test/test_cfgfile.c | 33 +++++++++++++++++++++++++++++++++ > 3 files changed, 58 insertions(+), 1 deletion(-) >=20 > diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cf= gfile.c > index 829109a77..832fea829 100644 > --- a/lib/librte_cfgfile/rte_cfgfile.c > +++ b/lib/librte_cfgfile/rte_cfgfile.c > @@ -107,6 +107,22 @@ rte_cfgfile_load(const char *filename, int flags) >=20 > memset(cfg->sections, 0, sizeof(cfg->sections[0]) * > allocated_sections); >=20 > + if (flags & CFG_FLAG_GLOBAL_SECTION) { > + curr_section =3D 0; > + allocated_entries =3D CFG_ALLOC_ENTRY_BATCH; > + cfg->sections[curr_section] =3D malloc( > + sizeof(*cfg->sections[0]) + > + sizeof(cfg->sections[0]->entries[0]) * > + allocated_entries); > + if (cfg->sections[curr_section] =3D=3D NULL) { > + printf("Error - no memory for global section\n"); > + goto error1; > + } > + > + snprintf(cfg->sections[curr_section]->name, > + sizeof(cfg->sections[0]->name), "GLOBAL"); > + } > + > while (fgets(buffer, sizeof(buffer), f) !=3D NULL) { > char *pos =3D NULL; > size_t len =3D strnlen(buffer, sizeof(buffer)); > diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cf= gfile.h > index b40e6a135..0e805c268 100644 > --- a/lib/librte_cfgfile/rte_cfgfile.h > +++ b/lib/librte_cfgfile/rte_cfgfile.h > @@ -66,13 +66,21 @@ struct rte_cfgfile_entry { > char value[CFG_VALUE_LEN]; /**< Value */ > }; >=20 > +/**@{ cfgfile load operation flags */ > +/** > + * Indicates that the file supports key value entries before the first d= efined > + * section. These entries can be accessed in the "GLOBAL" section. > + */ > +#define CFG_FLAG_GLOBAL_SECTION (1 << 0) > +/**@} */ > + > /** > * Open config file > * > * @param filename > * Config file name > * @param flags > -* Config file flags, Reserved for future use. Must be set to 0. > +* Config file flags > * @return > * Handle to configuration file on success, NULL otherwise > */ > diff --git a/test/test/test_cfgfile.c b/test/test/test_cfgfile.c > index faca89696..ad293cc89 100644 > --- a/test/test/test_cfgfile.c > +++ b/test/test/test_cfgfile.c > @@ -163,6 +163,36 @@ test_cfgfile_missing_section(void) > } >=20 > static int > +test_cfgfile_global_properties(void) > +{ > + struct rte_cfgfile *cfgfile; > + const char *value; > + int ret; > + > + cfgfile =3D rte_cfgfile_load(CFG_FILES_ETC "/missing_section.ini", > + CFG_FLAG_GLOBAL_SECTION); > + TEST_ASSERT_NOT_NULL(cfgfile, "Expected failured did not occur"); > + > + ret =3D rte_cfgfile_num_sections(cfgfile, NULL, 0); > + TEST_ASSERT(ret =3D=3D 1, "Unexpected number of sections: %d", ret); > + > + ret =3D rte_cfgfile_has_section(cfgfile, "GLOBAL"); > + TEST_ASSERT(ret, "global section missing"); > + > + ret =3D rte_cfgfile_section_num_entries(cfgfile, "GLOBAL"); > + TEST_ASSERT(ret =3D=3D 1, "GLOBAL unexpected number of entries: %d", > ret); > + > + value =3D rte_cfgfile_get_entry(cfgfile, "GLOBAL", "key"); > + TEST_ASSERT(strcmp("value", value) =3D=3D 0, > + "key unexpected value: %s", value); > + > + ret =3D rte_cfgfile_close(cfgfile); > + TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile"); > + > + return 0; > +} > + Can we please add a test to check that error is triggered for keys defined = outside any section when the CFG_FLAG_GLOBAL_SECTION is NOT provided to rte= _cfgfile_load()? Thank you! > +static int > test_cfgfile_empty_file(void) > { > struct rte_cfgfile *cfgfile; > @@ -198,6 +228,9 @@ test_cfgfile(void) > if (test_cfgfile_missing_section()) > return -1; >=20 > + if (test_cfgfile_global_properties()) > + return -1; > + > if (test_cfgfile_empty_file()) > return -1; >=20 > -- > 2.12.1