DPDK patches and discussions
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com,
	ferruh.yigit@intel.com, arybchenko@solarflare.com,
	olivier.matz@6wind.com, remy.horton@intel.com
Subject: [dpdk-dev] [PATCH 1/4] kvargs: support list value
Date: Tue,  9 Oct 2018 04:18:55 +0200	[thread overview]
Message-ID: <20181009021858.19216-2-thomas@monjalon.net> (raw)
In-Reply-To: <20181009021858.19216-1-thomas@monjalon.net>

If a value contains a comma, rte_kvargs_tokenize() will split here.
In order to support list syntax [a,b] as value, an extra parsing of
the square brackets is added.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_kvargs/rte_kvargs.c | 10 ++++++++++
 test/test/test_kvargs.c        | 17 +++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index a28f76945..b0774effb 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -44,6 +44,16 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 		    kvlist->pairs[i].value == NULL)
 			return -1;
 
+		/* Detect list [a,b] to skip comma delimiter in list. */
+		if (kvlist->pairs[i].value[0] == '[') {
+			/* Parse the end of the list. */
+			str = strtok_r(NULL, "]", &ctx1);
+			if (str == NULL)
+				return -1; /* no closing bracket */
+			/* Add back the bracket erased by strtok_t(). */
+			*(str - 1) = ']';
+		}
+
 		kvlist->count++;
 		str = NULL;
 	}
diff --git a/test/test/test_kvargs.c b/test/test/test_kvargs.c
index e6738624e..cb38b385c 100644
--- a/test/test/test_kvargs.c
+++ b/test/test/test_kvargs.c
@@ -137,6 +137,22 @@ static int test_valid_kvargs(void)
 	}
 	rte_kvargs_free(kvlist);
 
+	/* third test using list as value */
+	args = "foo=[0,1],check=value2";
+	valid_keys = valid_keys_list;
+	kvlist = rte_kvargs_parse(args, valid_keys);
+	if (kvlist == NULL) {
+		printf("rte_kvargs_parse() error");
+		goto fail;
+	}
+	count = kvlist->count;
+	if (count != 2) {
+		printf("invalid count value %d\n", count);
+		rte_kvargs_free(kvlist);
+		goto fail;
+	}
+	rte_kvargs_free(kvlist);
+
 	return 0;
 
  fail:
@@ -162,6 +178,7 @@ static int test_invalid_kvargs(void)
 		"foo=1,,foo=2",    /* empty key/value */
 		"foo=1,foo",       /* no value */
 		"foo=1,=2",        /* no key */
+		"foo=[1,2",        /* no closing bracket in value */
 		",=",              /* also test with a smiley */
 		NULL };
 	const char **args;
-- 
2.19.0

  reply	other threads:[~2018-10-09  2:19 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09  2:18 [dpdk-dev] [PATCH 0/4] support more ethdev iterator filters Thomas Monjalon
2018-10-09  2:18 ` Thomas Monjalon [this message]
2018-10-09 14:14   ` [dpdk-dev] [PATCH 1/4] kvargs: support list value Gaëtan Rivet
2018-10-09 14:31     ` Thomas Monjalon
2018-10-09 15:11       ` Stephen Hemminger
2018-10-09 17:11         ` Thomas Monjalon
2018-10-10 13:12         ` Remy Horton
2018-10-09  2:18 ` [dpdk-dev] [PATCH 2/4] mk: remove broken check Thomas Monjalon
2018-10-09 11:43   ` Neil Horman
2018-10-09 11:53     ` Thomas Monjalon
2018-10-09 18:11       ` Neil Horman
2018-10-09  2:18 ` [dpdk-dev] [PATCH 3/4] ethdev: move representor parsing functions Thomas Monjalon
2018-10-09  9:06   ` Andrew Rybchenko
2018-10-09 12:38   ` Remy Horton
2018-10-09 13:25     ` Thomas Monjalon
2018-10-09  2:18 ` [dpdk-dev] [PATCH 4/4] ethdev: support representor id for iterating ports Thomas Monjalon
2018-10-09  9:14   ` Andrew Rybchenko
2018-10-10 19:23 ` [dpdk-dev] [PATCH v2 0/4] support more ethdev iterator filters Thomas Monjalon
2018-10-10 19:23   ` [dpdk-dev] [PATCH v2 1/4] kvargs: support list value Thomas Monjalon
2018-10-10 19:23   ` [dpdk-dev] [PATCH v2 2/4] ethdev: move representor parsing functions Thomas Monjalon
2018-10-10 19:23   ` [dpdk-dev] [PATCH v2 3/4] ethdev: support representor id as iterator filter Thomas Monjalon
2018-10-10 19:23   ` [dpdk-dev] [PATCH v2 4/4] ethdev: support MAC address " Thomas Monjalon
2018-10-22 13:15 ` [dpdk-dev] [PATCH v3 0/4] support more ethdev iterator filters Thomas Monjalon
2018-10-22 13:15   ` [dpdk-dev] [PATCH v3 1/4] kvargs: support list value Thomas Monjalon
2018-10-22 13:15   ` [dpdk-dev] [PATCH v3 2/4] ethdev: move representor parsing functions Thomas Monjalon
2018-10-22 13:15   ` [dpdk-dev] [PATCH v3 3/4] ethdev: support representor id as iterator filter Thomas Monjalon
2018-10-22 13:15   ` [dpdk-dev] [PATCH v3 4/4] ethdev: support MAC address " Thomas Monjalon
2018-10-22 13:37     ` Andrew Rybchenko
2018-10-22 14:02       ` Thomas Monjalon
2018-10-22 14:18         ` Andrew Rybchenko
2018-10-22 21:24         ` Ananyev, Konstantin
2018-10-23  7:20           ` Thomas Monjalon
2018-10-23  8:33             ` Ananyev, Konstantin
2018-10-23  8:53               ` Thomas Monjalon
2018-10-23 21:45                 ` Ananyev, Konstantin
2018-10-22 14:25     ` Andrew Rybchenko
2018-10-24  8:27   ` [dpdk-dev] [PATCH v3 0/4] support more ethdev iterator filters Ferruh Yigit

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=20181009021858.19216-2-thomas@monjalon.net \
    --to=thomas@monjalon.net \
    --cc=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=gaetan.rivet@6wind.com \
    --cc=olivier.matz@6wind.com \
    --cc=ophirmu@mellanox.com \
    --cc=remy.horton@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).