xref: /dpdk/app/test/test_cmdline_string.c (revision 71bdd8a1785d25f91de7908ff915e4db7871eb2b)
1a9de470cSBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2a9de470cSBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
3a9de470cSBruce Richardson  */
4a9de470cSBruce Richardson 
5a9de470cSBruce Richardson #include <stdio.h>
6a9de470cSBruce Richardson #include <string.h>
7a9de470cSBruce Richardson #include <inttypes.h>
8a9de470cSBruce Richardson 
9a9de470cSBruce Richardson #include <rte_common.h>
10a9de470cSBruce Richardson #include <rte_string_fns.h>
11a9de470cSBruce Richardson 
12a9de470cSBruce Richardson #include <cmdline_parse.h>
13a9de470cSBruce Richardson #include <cmdline_parse_string.h>
14a9de470cSBruce Richardson 
15a9de470cSBruce Richardson #include "test_cmdline.h"
16a9de470cSBruce Richardson 
17a9de470cSBruce Richardson /* structures needed to run tests */
18a9de470cSBruce Richardson 
19a9de470cSBruce Richardson struct string_elt_str {
20a9de470cSBruce Richardson 	const char * str;	/* parsed string */
21a9de470cSBruce Richardson 	const char * result;	/* expected string */
22a9de470cSBruce Richardson 	int idx;	/* position at which result is expected to be */
23a9de470cSBruce Richardson };
24a9de470cSBruce Richardson 
25a9de470cSBruce Richardson struct string_elt_str string_elt_strs[] = {
26a9de470cSBruce Richardson 		{"one#two#three", "three", 2},
27a9de470cSBruce Richardson 		{"one#two with spaces#three", "three", 2},
28a9de470cSBruce Richardson 		{"one#two\twith\ttabs#three", "three", 2},
29a9de470cSBruce Richardson 		{"one#two\rwith\rreturns#three", "three", 2},
30a9de470cSBruce Richardson 		{"one#two\nwith\nnewlines#three", "three", 2},
31a9de470cSBruce Richardson 		{"one#two#three", "one", 0},
32a9de470cSBruce Richardson 		{"one#two#three", "two", 1},
33a9de470cSBruce Richardson 		{"one#two\0three", "two", 1},
34a9de470cSBruce Richardson 		{"one#two with spaces#three", "two with spaces", 1},
35a9de470cSBruce Richardson 		{"one#two\twith\ttabs#three", "two\twith\ttabs", 1},
36a9de470cSBruce Richardson 		{"one#two\rwith\rreturns#three", "two\rwith\rreturns", 1},
37a9de470cSBruce Richardson 		{"one#two\nwith\nnewlines#three", "two\nwith\nnewlines", 1},
38a9de470cSBruce Richardson };
39a9de470cSBruce Richardson 
40a9de470cSBruce Richardson #if (CMDLINE_TEST_BUFSIZE < STR_TOKEN_SIZE) \
41a9de470cSBruce Richardson || (CMDLINE_TEST_BUFSIZE < STR_MULTI_TOKEN_SIZE)
42a9de470cSBruce Richardson #undef CMDLINE_TEST_BUFSIZE
43a9de470cSBruce Richardson #define CMDLINE_TEST_BUFSIZE RTE_MAX(STR_TOKEN_SIZE, STR_MULTI_TOKEN_SIZE)
44a9de470cSBruce Richardson #endif
45a9de470cSBruce Richardson 
46a9de470cSBruce Richardson struct string_nb_str {
47a9de470cSBruce Richardson 	const char * str;	/* parsed string */
48a9de470cSBruce Richardson 	int nb_strs;	/* expected number of strings in str */
49a9de470cSBruce Richardson };
50a9de470cSBruce Richardson 
51a9de470cSBruce Richardson struct string_nb_str string_nb_strs[] = {
52a9de470cSBruce Richardson 		{"one#two#three", 3},
53a9de470cSBruce Richardson 		{"one", 1},
54a9de470cSBruce Richardson 		{"one# \t two \r # three \n #four", 4},
55a9de470cSBruce Richardson };
56a9de470cSBruce Richardson 
57a9de470cSBruce Richardson 
58a9de470cSBruce Richardson 
59a9de470cSBruce Richardson struct string_parse_str {
60a9de470cSBruce Richardson 	const char * str;	/* parsed string */
61a9de470cSBruce Richardson 	const char * fixed_str;	/* parsing mode (any, fixed or multi) */
62a9de470cSBruce Richardson 	const char * result;	/* expected result */
63a9de470cSBruce Richardson };
64a9de470cSBruce Richardson 
65a9de470cSBruce Richardson struct string_parse_str string_parse_strs[] = {
66a9de470cSBruce Richardson 		{"one", NULL, "one"},	/* any string */
67a9de470cSBruce Richardson 		{"two", "one#two#three", "two"},	/* multiple choice string */
68a9de470cSBruce Richardson 		{"three", "three", "three"},	/* fixed string */
69a9de470cSBruce Richardson 		{"three", "one#two with\rgarbage\tcharacters\n#three", "three"},
70a9de470cSBruce Richardson 		{"two with\rgarbage\tcharacters\n",
71a9de470cSBruce Richardson 				"one#two with\rgarbage\tcharacters\n#three",
72a9de470cSBruce Richardson 				"two with\rgarbage\tcharacters\n"},
73a9de470cSBruce Richardson 		{"one two", "one", "one"}, /* fixed string */
74a9de470cSBruce Richardson 		{"one two", TOKEN_STRING_MULTI, "one two"}, /* multi string */
75a9de470cSBruce Richardson 		{"one two", NULL, "one"}, /* any string */
76a9de470cSBruce Richardson 		{"one two #three", TOKEN_STRING_MULTI, "one two "},
77a9de470cSBruce Richardson 		/* multi string with comment */
78a9de470cSBruce Richardson };
79a9de470cSBruce Richardson 
80a9de470cSBruce Richardson 
81a9de470cSBruce Richardson 
82a9de470cSBruce Richardson struct string_invalid_str {
83a9de470cSBruce Richardson 	const char * str;	/* parsed string */
84a9de470cSBruce Richardson 	const char * fixed_str;	/* parsing mode (any, fixed or multi) */
85a9de470cSBruce Richardson };
86a9de470cSBruce Richardson 
87a9de470cSBruce Richardson struct string_invalid_str string_invalid_strs[] = {
88a9de470cSBruce Richardson 		{"invalid", "one"},	/* fixed string */
89a9de470cSBruce Richardson 		{"invalid", "one#two#three"},	/* multiple choice string */
90a9de470cSBruce Richardson 		{"invalid", "invalidone"},	/* string that starts the same */
91a9de470cSBruce Richardson 		{"invalidone", "invalid"},	/* string that starts the same */
92a9de470cSBruce Richardson 		{"toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
93a9de470cSBruce Richardson 		 "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
94a9de470cSBruce Richardson 		 "toolong!!!", NULL },
95a9de470cSBruce Richardson 		{"toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
96a9de470cSBruce Richardson 		 "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
97a9de470cSBruce Richardson 		 "toolong!!!", "fixed" },
98a9de470cSBruce Richardson 		{"toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
99a9de470cSBruce Richardson 		 "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
100a9de470cSBruce Richardson 		 "toolong!!!", "multi#choice#string" },
101a9de470cSBruce Richardson 		{"invalid",
102a9de470cSBruce Richardson 		 "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
103a9de470cSBruce Richardson 		 "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!"
104a9de470cSBruce Richardson 		 "toolong!!!" },
105a9de470cSBruce Richardson 		 {"", "invalid"}
106a9de470cSBruce Richardson };
107a9de470cSBruce Richardson 
108a9de470cSBruce Richardson 
109a9de470cSBruce Richardson 
110a9de470cSBruce Richardson const char * string_help_strs[] = {
111a9de470cSBruce Richardson 		NULL,
112a9de470cSBruce Richardson 		"fixed_str",
113a9de470cSBruce Richardson 		"multi#str",
114a9de470cSBruce Richardson };
115a9de470cSBruce Richardson 
116a9de470cSBruce Richardson #define SMALL_BUF 8
117a9de470cSBruce Richardson 
118a9de470cSBruce Richardson /* test invalid parameters */
119a9de470cSBruce Richardson int
test_parse_string_invalid_param(void)120a9de470cSBruce Richardson test_parse_string_invalid_param(void)
121a9de470cSBruce Richardson {
122a9de470cSBruce Richardson 	cmdline_parse_token_string_t token;
123a9de470cSBruce Richardson 	int result;
124a9de470cSBruce Richardson 	char buf[CMDLINE_TEST_BUFSIZE];
125a9de470cSBruce Richardson 
126a9de470cSBruce Richardson 	memset(&token, 0, sizeof(token));
127a9de470cSBruce Richardson 
128a9de470cSBruce Richardson 	snprintf(buf, sizeof(buf), "buffer");
129a9de470cSBruce Richardson 
130a9de470cSBruce Richardson 	/* test null token */
131a9de470cSBruce Richardson 	if (cmdline_get_help_string(
132a9de470cSBruce Richardson 		NULL, buf, 0) != -1) {
133a9de470cSBruce Richardson 		printf("Error: function accepted null token!\n");
134a9de470cSBruce Richardson 		return -1;
135a9de470cSBruce Richardson 	}
136a9de470cSBruce Richardson 	if (cmdline_complete_get_elt_string(
137a9de470cSBruce Richardson 			NULL, 0, buf, 0) != -1) {
138a9de470cSBruce Richardson 		printf("Error: function accepted null token!\n");
139a9de470cSBruce Richardson 		return -1;
140a9de470cSBruce Richardson 	}
141a9de470cSBruce Richardson 	if (cmdline_complete_get_nb_string(NULL) != -1) {
142a9de470cSBruce Richardson 		printf("Error: function accepted null token!\n");
143a9de470cSBruce Richardson 		return -1;
144a9de470cSBruce Richardson 	}
145a9de470cSBruce Richardson 	if (cmdline_parse_string(NULL, buf, NULL, 0) != -1) {
146a9de470cSBruce Richardson 		printf("Error: function accepted null token!\n");
147a9de470cSBruce Richardson 		return -1;
148a9de470cSBruce Richardson 	}
149a9de470cSBruce Richardson 	/* test null buffer */
150a9de470cSBruce Richardson 	if (cmdline_complete_get_elt_string(
151a9de470cSBruce Richardson 			(cmdline_parse_token_hdr_t*)&token, 0, NULL, 0) != -1) {
152a9de470cSBruce Richardson 		printf("Error: function accepted null buffer!\n");
153a9de470cSBruce Richardson 		return -1;
154a9de470cSBruce Richardson 	}
155a9de470cSBruce Richardson 	if (cmdline_parse_string(
156a9de470cSBruce Richardson 			(cmdline_parse_token_hdr_t*)&token, NULL,
157a9de470cSBruce Richardson 			(void*)&result, sizeof(result)) != -1) {
158a9de470cSBruce Richardson 		printf("Error: function accepted null buffer!\n");
159a9de470cSBruce Richardson 		return -1;
160a9de470cSBruce Richardson 	}
161a9de470cSBruce Richardson 	if (cmdline_get_help_string(
162a9de470cSBruce Richardson 			(cmdline_parse_token_hdr_t*)&token, NULL, 0) != -1) {
163a9de470cSBruce Richardson 		printf("Error: function accepted null buffer!\n");
164a9de470cSBruce Richardson 		return -1;
165a9de470cSBruce Richardson 	}
166a9de470cSBruce Richardson 	/* test null result */
167a9de470cSBruce Richardson 	if (cmdline_parse_string(
168a9de470cSBruce Richardson 			(cmdline_parse_token_hdr_t*)&token, buf, NULL, 0) == -1) {
169a9de470cSBruce Richardson 		printf("Error: function rejected null result!\n");
170a9de470cSBruce Richardson 		return -1;
171a9de470cSBruce Richardson 	}
172a9de470cSBruce Richardson 	/* test negative index */
173a9de470cSBruce Richardson 	if (cmdline_complete_get_elt_string(
174a9de470cSBruce Richardson 			(cmdline_parse_token_hdr_t*)&token, -1, buf, 0) != -1) {
175a9de470cSBruce Richardson 		printf("Error: function accepted negative index!\n");
176a9de470cSBruce Richardson 		return -1;
177a9de470cSBruce Richardson 	}
178a9de470cSBruce Richardson 	return 0;
179a9de470cSBruce Richardson }
180a9de470cSBruce Richardson 
181a9de470cSBruce Richardson /* test valid parameters but invalid data */
182a9de470cSBruce Richardson int
test_parse_string_invalid_data(void)183a9de470cSBruce Richardson test_parse_string_invalid_data(void)
184a9de470cSBruce Richardson {
185a9de470cSBruce Richardson 	cmdline_parse_token_string_t token;
186a9de470cSBruce Richardson 	cmdline_parse_token_string_t help_token;
187a9de470cSBruce Richardson 	char buf[CMDLINE_TEST_BUFSIZE];
188a9de470cSBruce Richardson 	char help_str[CMDLINE_TEST_BUFSIZE];
189a9de470cSBruce Richardson 	char small_buf[SMALL_BUF];
190a9de470cSBruce Richardson 	unsigned i;
191a9de470cSBruce Richardson 
192a9de470cSBruce Richardson 	/* test parsing invalid strings */
193*71bdd8a1SPavan Nikhilesh 	for (i = 0; i < RTE_DIM(string_invalid_strs); i++) {
194a9de470cSBruce Richardson 		memset(&token, 0, sizeof(token));
195a9de470cSBruce Richardson 		memset(buf, 0, sizeof(buf));
196a9de470cSBruce Richardson 
197a9de470cSBruce Richardson 		/* prepare test token data */
198a9de470cSBruce Richardson 		token.string_data.str = string_invalid_strs[i].fixed_str;
199a9de470cSBruce Richardson 
200a9de470cSBruce Richardson 		if (cmdline_parse_string((cmdline_parse_token_hdr_t*)&token,
201a9de470cSBruce Richardson 				string_invalid_strs[i].str, (void*)buf,
202a9de470cSBruce Richardson 				sizeof(buf)) != -1) {
203a9de470cSBruce Richardson 			memset(help_str, 0, sizeof(help_str));
204a9de470cSBruce Richardson 			memset(&help_token, 0, sizeof(help_token));
205a9de470cSBruce Richardson 
206a9de470cSBruce Richardson 			help_token.string_data.str = string_invalid_strs[i].fixed_str;
207a9de470cSBruce Richardson 
208a9de470cSBruce Richardson 			/* get parse type so we can give a good error message */
209a9de470cSBruce Richardson 			cmdline_get_help_string((cmdline_parse_token_hdr_t*)&token, help_str,
210a9de470cSBruce Richardson 					sizeof(help_str));
211a9de470cSBruce Richardson 
212a9de470cSBruce Richardson 			printf("Error: parsing %s as %s succeeded!\n",
213a9de470cSBruce Richardson 					string_invalid_strs[i].str, help_str);
214a9de470cSBruce Richardson 			return -1;
215a9de470cSBruce Richardson 		}
216a9de470cSBruce Richardson 	}
217a9de470cSBruce Richardson 
218a9de470cSBruce Richardson 	/* misc tests (big comments signify test cases) */
219a9de470cSBruce Richardson 	memset(&token, 0, sizeof(token));
220a9de470cSBruce Richardson 	memset(small_buf, 0, sizeof(small_buf));
221a9de470cSBruce Richardson 
222a9de470cSBruce Richardson 	/*
223a9de470cSBruce Richardson 	 * try to get element from a null token
224a9de470cSBruce Richardson 	 */
225a9de470cSBruce Richardson 	token.string_data.str = NULL;
226a9de470cSBruce Richardson 	if (cmdline_complete_get_elt_string(
227a9de470cSBruce Richardson 			(cmdline_parse_token_hdr_t*)&token, 1,
228a9de470cSBruce Richardson 			buf, sizeof(buf)) != -1) {
229a9de470cSBruce Richardson 		printf("Error: getting token from null token string!\n");
230a9de470cSBruce Richardson 		return -1;
231a9de470cSBruce Richardson 	}
232a9de470cSBruce Richardson 
233a9de470cSBruce Richardson 	/*
234a9de470cSBruce Richardson 	 * try to get element into a buffer that is too small
235a9de470cSBruce Richardson 	 */
236a9de470cSBruce Richardson 	token.string_data.str = "too_small_buffer";
237a9de470cSBruce Richardson 	if (cmdline_complete_get_elt_string(
238a9de470cSBruce Richardson 			(cmdline_parse_token_hdr_t*)&token, 0,
239a9de470cSBruce Richardson 			small_buf, sizeof(small_buf)) != -1) {
240a9de470cSBruce Richardson 		printf("Error: writing token into too small a buffer succeeded!\n");
241a9de470cSBruce Richardson 		return -1;
242a9de470cSBruce Richardson 	}
243a9de470cSBruce Richardson 
244a9de470cSBruce Richardson 	/*
245a9de470cSBruce Richardson 	 * get help string written into a buffer smaller than help string
246a9de470cSBruce Richardson 	 * truncation should occur
247a9de470cSBruce Richardson 	 */
248a9de470cSBruce Richardson 	token.string_data.str = NULL;
249a9de470cSBruce Richardson 	if (cmdline_get_help_string(
250a9de470cSBruce Richardson 			(cmdline_parse_token_hdr_t*)&token,
251a9de470cSBruce Richardson 			small_buf, sizeof(small_buf)) == -1) {
252a9de470cSBruce Richardson 		printf("Error: writing help string into too small a buffer failed!\n");
253a9de470cSBruce Richardson 		return -1;
254a9de470cSBruce Richardson 	}
255a9de470cSBruce Richardson 	/* get help string for "any string" so we can compare it with small_buf */
256a9de470cSBruce Richardson 	cmdline_get_help_string((cmdline_parse_token_hdr_t*)&token, help_str,
257a9de470cSBruce Richardson 			sizeof(help_str));
258a9de470cSBruce Richardson 	if (strncmp(small_buf, help_str, sizeof(small_buf) - 1)) {
259a9de470cSBruce Richardson 		printf("Error: help string mismatch!\n");
260a9de470cSBruce Richardson 		return -1;
261a9de470cSBruce Richardson 	}
262a9de470cSBruce Richardson 	/* check null terminator */
263a9de470cSBruce Richardson 	if (small_buf[sizeof(small_buf) - 1] != '\0') {
264a9de470cSBruce Richardson 		printf("Error: small buffer doesn't have a null terminator!\n");
265a9de470cSBruce Richardson 		return -1;
266a9de470cSBruce Richardson 	}
267a9de470cSBruce Richardson 
268a9de470cSBruce Richardson 	/*
269a9de470cSBruce Richardson 	 * try to count tokens in a null token
270a9de470cSBruce Richardson 	 */
271a9de470cSBruce Richardson 	token.string_data.str = NULL;
272a9de470cSBruce Richardson 	if (cmdline_complete_get_nb_string(
273a9de470cSBruce Richardson 			(cmdline_parse_token_hdr_t*)&token) != 0) {
274a9de470cSBruce Richardson 		printf("Error: getting token count from null token succeeded!\n");
275a9de470cSBruce Richardson 		return -1;
276a9de470cSBruce Richardson 	}
277a9de470cSBruce Richardson 
278a9de470cSBruce Richardson 	return 0;
279a9de470cSBruce Richardson }
280a9de470cSBruce Richardson 
281a9de470cSBruce Richardson /* test valid parameters and data */
282a9de470cSBruce Richardson int
test_parse_string_valid(void)283a9de470cSBruce Richardson test_parse_string_valid(void)
284a9de470cSBruce Richardson {
285a9de470cSBruce Richardson 	cmdline_parse_token_string_t token;
286a9de470cSBruce Richardson 	cmdline_parse_token_string_t help_token;
287a9de470cSBruce Richardson 	char buf[CMDLINE_TEST_BUFSIZE];
288a9de470cSBruce Richardson 	char help_str[CMDLINE_TEST_BUFSIZE];
289a9de470cSBruce Richardson 	unsigned i;
290a9de470cSBruce Richardson 
291a9de470cSBruce Richardson 	/* test parsing strings */
292*71bdd8a1SPavan Nikhilesh 	for (i = 0; i < RTE_DIM(string_parse_strs); i++) {
293a9de470cSBruce Richardson 		memset(&token, 0, sizeof(token));
294a9de470cSBruce Richardson 		memset(buf, 0, sizeof(buf));
295a9de470cSBruce Richardson 
296a9de470cSBruce Richardson 		token.string_data.str = string_parse_strs[i].fixed_str;
297a9de470cSBruce Richardson 
298a9de470cSBruce Richardson 		if (cmdline_parse_string((cmdline_parse_token_hdr_t*)&token,
299a9de470cSBruce Richardson 				string_parse_strs[i].str, (void*)buf,
300a9de470cSBruce Richardson 				sizeof(buf)) < 0) {
301a9de470cSBruce Richardson 
302a9de470cSBruce Richardson 			/* clean help data */
303a9de470cSBruce Richardson 			memset(&help_token, 0, sizeof(help_token));
304a9de470cSBruce Richardson 			memset(help_str, 0, sizeof(help_str));
305a9de470cSBruce Richardson 
306a9de470cSBruce Richardson 			/* prepare help token */
307a9de470cSBruce Richardson 			help_token.string_data.str = string_parse_strs[i].fixed_str;
308a9de470cSBruce Richardson 
309a9de470cSBruce Richardson 			/* get help string so that we get an informative error message */
310a9de470cSBruce Richardson 			cmdline_get_help_string((cmdline_parse_token_hdr_t*)&token, help_str,
311a9de470cSBruce Richardson 					sizeof(help_str));
312a9de470cSBruce Richardson 
313a9de470cSBruce Richardson 			printf("Error: parsing %s as %s failed!\n",
314a9de470cSBruce Richardson 					string_parse_strs[i].str, help_str);
315a9de470cSBruce Richardson 			return -1;
316a9de470cSBruce Richardson 		}
317a9de470cSBruce Richardson 		if (strcmp(buf, string_parse_strs[i].result) != 0) {
318a9de470cSBruce Richardson 			printf("Error: result mismatch!\n");
319a9de470cSBruce Richardson 			return -1;
320a9de470cSBruce Richardson 		}
321a9de470cSBruce Richardson 	}
322a9de470cSBruce Richardson 
323a9de470cSBruce Richardson 	/* get number of string tokens and verify it's correct */
324*71bdd8a1SPavan Nikhilesh 	for (i = 0; i < RTE_DIM(string_nb_strs); i++) {
325a9de470cSBruce Richardson 		memset(&token, 0, sizeof(token));
326a9de470cSBruce Richardson 
327a9de470cSBruce Richardson 		token.string_data.str = string_nb_strs[i].str;
328a9de470cSBruce Richardson 
329a9de470cSBruce Richardson 		if (cmdline_complete_get_nb_string(
330a9de470cSBruce Richardson 				(cmdline_parse_token_hdr_t*)&token) <
331a9de470cSBruce Richardson 				string_nb_strs[i].nb_strs) {
332a9de470cSBruce Richardson 			printf("Error: strings count mismatch!\n");
333a9de470cSBruce Richardson 			return -1;
334a9de470cSBruce Richardson 		}
335a9de470cSBruce Richardson 	}
336a9de470cSBruce Richardson 
337a9de470cSBruce Richardson 	/* get token at specified position and verify it's correct */
338*71bdd8a1SPavan Nikhilesh 	for (i = 0; i < RTE_DIM(string_elt_strs); i++) {
339a9de470cSBruce Richardson 		memset(&token, 0, sizeof(token));
340a9de470cSBruce Richardson 		memset(buf, 0, sizeof(buf));
341a9de470cSBruce Richardson 
342a9de470cSBruce Richardson 		token.string_data.str = string_elt_strs[i].str;
343a9de470cSBruce Richardson 
344a9de470cSBruce Richardson 		if (cmdline_complete_get_elt_string(
345a9de470cSBruce Richardson 				(cmdline_parse_token_hdr_t*)&token, string_elt_strs[i].idx,
346a9de470cSBruce Richardson 				buf, sizeof(buf)) < 0) {
347a9de470cSBruce Richardson 			printf("Error: getting string element failed!\n");
348a9de470cSBruce Richardson 			return -1;
349a9de470cSBruce Richardson 		}
350a9de470cSBruce Richardson 		if (strncmp(buf, string_elt_strs[i].result,
351a9de470cSBruce Richardson 				sizeof(buf)) != 0) {
352a9de470cSBruce Richardson 			printf("Error: result mismatch!\n");
353a9de470cSBruce Richardson 			return -1;
354a9de470cSBruce Richardson 		}
355a9de470cSBruce Richardson 	}
356a9de470cSBruce Richardson 
357a9de470cSBruce Richardson 	/* cover all cases with help strings */
358*71bdd8a1SPavan Nikhilesh 	for (i = 0; i < RTE_DIM(string_help_strs); i++) {
359a9de470cSBruce Richardson 		memset(&help_token, 0, sizeof(help_token));
360a9de470cSBruce Richardson 		memset(help_str, 0, sizeof(help_str));
361a9de470cSBruce Richardson 		help_token.string_data.str = string_help_strs[i];
362a9de470cSBruce Richardson 		if (cmdline_get_help_string((cmdline_parse_token_hdr_t*)&help_token,
363a9de470cSBruce Richardson 				help_str, sizeof(help_str)) < 0) {
364a9de470cSBruce Richardson 			printf("Error: help operation failed!\n");
365a9de470cSBruce Richardson 			return -1;
366a9de470cSBruce Richardson 		}
367a9de470cSBruce Richardson 	}
368a9de470cSBruce Richardson 
369a9de470cSBruce Richardson 	return 0;
370a9de470cSBruce Richardson }
371