X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest%2Ftest_kvargs.c;h=a91ea8dc47150093959e87713bdfb6d66cc9af59;hb=f0243339496d48e6f5d76e6ef6741d6986b965d0;hp=d3db88a57a9ac6ab9c725e70d5c6e615ce91c551;hpb=55fa01f7edfc9d2fa5af57ffb8991750fbdb1528;p=dpdk.git diff --git a/app/test/test_kvargs.c b/app/test/test_kvargs.c index d3db88a57a..a91ea8dc47 100644 --- a/app/test/test_kvargs.c +++ b/app/test/test_kvargs.c @@ -35,6 +35,25 @@ static int check_handler(const char *key, const char *value, return 0; } +/* test parsing. */ +static int test_kvargs_parsing(const char *args, unsigned int n) +{ + struct rte_kvargs *kvlist; + + kvlist = rte_kvargs_parse(args, NULL); + if (kvlist == NULL) { + printf("rte_kvargs_parse() error: %s\n", args); + return -1; + } + if (kvlist->count != n) { + printf("invalid count value %d: %s\n", kvlist->count, args); + rte_kvargs_free(kvlist); + return -1; + } + rte_kvargs_free(kvlist); + return 0; +} + /* test a valid case */ static int test_valid_kvargs(void) { @@ -42,6 +61,19 @@ static int test_valid_kvargs(void) const char *args; const char *valid_keys_list[] = { "foo", "check", NULL }; const char **valid_keys; + static const struct { + unsigned int expected; + const char *input; + } valid_inputs[] = { + { 2, "foo=1,foo=" }, + { 2, "foo=1,foo=" }, + { 2, "foo=1,foo" }, + { 2, "foo=1,=2" }, + { 1, "foo=[1,2" }, + { 1, ",=" }, + { 1, "foo=[" }, + }; + unsigned int i; /* empty args is valid */ args = ""; @@ -191,6 +223,14 @@ static int test_valid_kvargs(void) } rte_kvargs_free(kvlist); + valid_keys = NULL; + + for (i = 0; i < RTE_DIM(valid_inputs); ++i) { + args = valid_inputs[i].input; + if (test_kvargs_parsing(args, valid_inputs[i].expected)) + goto fail; + } + return 0; fail: @@ -212,11 +252,6 @@ static int test_invalid_kvargs(void) /* list of argument that should fail */ const char *args_list[] = { "wrong-key=x", /* key not in valid_keys_list */ - "foo=1,foo=", /* empty 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; const char *valid_keys_list[] = { "foo", "check", NULL }; @@ -230,8 +265,8 @@ static int test_invalid_kvargs(void) rte_kvargs_free(kvlist); goto fail; } - return 0; } + return 0; fail: printf("while processing <%s>", *args);