MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_valid_kvargs

Function test_valid_kvargs

dpdk/app/test/test_kvargs.c:58–246  ·  view source on GitHub ↗

test a valid case */

Source from the content-addressed store, hash-verified

56
57/* test a valid case */
58static int test_valid_kvargs(void)
59{
60 struct rte_kvargs *kvlist;
61 const char *args;
62 const char *valid_keys_list[] = { "foo", "check", NULL };
63 const char **valid_keys;
64 static const struct {
65 unsigned int expected;
66 const char *input;
67 } valid_inputs[] = {
68 { 2, "foo=1,foo=" },
69 { 2, "foo=1,foo=" },
70 { 2, "foo=1,foo" },
71 { 2, "foo=1,=2" },
72 { 1, "foo=[1,2" },
73 { 1, ",=" },
74 { 1, "foo=[" },
75 };
76 unsigned int i;
77
78 /* empty args is valid */
79 args = "";
80 valid_keys = NULL;
81 kvlist = rte_kvargs_parse(args, valid_keys);
82 if (kvlist == NULL) {
83 printf("rte_kvargs_parse() error");
84 goto fail;
85 }
86 rte_kvargs_free(kvlist);
87
88 /* first test without valid_keys */
89 args = "foo=1234,check=value0,check=value1";
90 valid_keys = NULL;
91 kvlist = rte_kvargs_parse(args, valid_keys);
92 if (kvlist == NULL) {
93 printf("rte_kvargs_parse() error");
94 goto fail;
95 }
96 /* call check_handler() for all entries with key="check" */
97 count = 0;
98 if (rte_kvargs_process(kvlist, "check", check_handler, NULL) < 0) {
99 printf("rte_kvargs_process() error\n");
100 rte_kvargs_free(kvlist);
101 goto fail;
102 }
103 if (count != 2) {
104 printf("invalid count value %d after rte_kvargs_process(check)\n",
105 count);
106 rte_kvargs_free(kvlist);
107 goto fail;
108 }
109 count = 0;
110 /* call check_handler() for all entries with key="nonexistent_key" */
111 if (rte_kvargs_process(kvlist, "nonexistent_key", check_handler, NULL) < 0) {
112 printf("rte_kvargs_process() error\n");
113 rte_kvargs_free(kvlist);
114 goto fail;
115 }

Callers 1

test_kvargsFunction · 0.85

Calls 7

rte_kvargs_parseFunction · 0.85
rte_kvargs_freeFunction · 0.85
rte_kvargs_processFunction · 0.85
rte_kvargs_countFunction · 0.85
strcmpFunction · 0.85
test_kvargs_parsingFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected