1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
9 #include <rte_common.h>
11 #include <cmdline_parse.h>
12 #include <cmdline_parse_portlist.h>
14 #include "test_cmdline.h"
22 const struct portlist_str portlist_valid_strs[] = {
30 {"31,0-10,15", 0x800087FFU},
32 {"00,01,02,03", 0xFU},
33 {"000,001,002,003", 0xFU},
36 /* valid strings but with garbage at the end.
37 * these strings should still be valid because parser checks
38 * for end of token, which is either a space/tab, a newline/return,
42 const char * portlist_garbage_strs[] = {
51 "0,1,2,3-31\0garbage",
52 "0,1,2,3-31\ngarbage",
53 "0,1,2,3-31\rgarbage",
54 "0,1,2,3-31\tgarbage",
64 const char * portlist_invalid_strs[] = {
65 /* valid syntax, invalid chars */
71 /* valid chars, invalid syntax */
89 "0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,"
90 "0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,2",
93 /* test invalid parameters */
95 test_parse_portlist_invalid_param(void)
97 cmdline_portlist_t result;
98 char buf[CMDLINE_TEST_BUFSIZE];
101 memset(&buf, 0, sizeof(buf));
102 memset(&result, 0, sizeof(cmdline_portlist_t));
105 ret = cmdline_parse_portlist(NULL, NULL, NULL, 0);
107 printf("Error: parser accepted null parameters!\n");
112 ret = cmdline_parse_portlist(NULL, NULL, (void*)&result,
115 printf("Error: parser accepted null string!\n");
119 /* try null result */
120 ret = cmdline_parse_portlist(NULL, portlist_valid_strs[0].str, NULL, 0);
122 printf("Error: parser rejected null result!\n");
126 /* token is not used in ether_parse anyway so there's no point in
129 /* test help function */
132 ret = cmdline_get_help_portlist(NULL, buf, sizeof(buf));
134 printf("Error: help function failed with valid parameters!\n");
141 /* test valid parameters but invalid data */
143 test_parse_portlist_invalid_data(void)
147 cmdline_portlist_t result;
149 /* test invalid strings */
150 for (i = 0; i < RTE_DIM(portlist_invalid_strs); i++) {
152 memset(&result, 0, sizeof(cmdline_portlist_t));
154 ret = cmdline_parse_portlist(NULL, portlist_invalid_strs[i],
155 (void*)&result, sizeof(result));
157 printf("Error: parsing %s succeeded!\n",
158 portlist_invalid_strs[i]);
166 /* test valid parameters and data */
168 test_parse_portlist_valid(void)
172 cmdline_portlist_t result;
174 /* test full strings */
175 for (i = 0; i < RTE_DIM(portlist_valid_strs); i++) {
177 memset(&result, 0, sizeof(cmdline_portlist_t));
179 ret = cmdline_parse_portlist(NULL, portlist_valid_strs[i].str,
180 (void*)&result, sizeof(result));
182 printf("Error: parsing %s failed!\n",
183 portlist_valid_strs[i].str);
186 if (result.map != portlist_valid_strs[i].portmap) {
187 printf("Error: parsing %s failed: map mismatch!\n",
188 portlist_valid_strs[i].str);
193 /* test garbage strings */
194 for (i = 0; i < RTE_DIM(portlist_garbage_strs); i++) {
196 memset(&result, 0, sizeof(cmdline_portlist_t));
198 ret = cmdline_parse_portlist(NULL, portlist_garbage_strs[i],
199 (void*)&result, sizeof(result));
201 printf("Error: parsing %s failed!\n",
202 portlist_garbage_strs[i]);
205 if (result.map != UINT32_MAX) {
206 printf("Error: parsing %s failed: map mismatch!\n",
207 portlist_garbage_strs[i]);