4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 * Copyright(c) 2014 6WIND S.A.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <netinet/in.h>
44 #include <net/socket.h>
49 #include <sys/queue.h>
51 #include <rte_common.h>
53 #include <rte_debug.h>
54 #include <rte_memory.h>
55 #include <rte_memcpy.h>
56 #include <rte_memzone.h>
57 #include <rte_launch.h>
58 #include <rte_cycles.h>
60 #include <rte_per_lcore.h>
61 #include <rte_lcore.h>
62 #include <rte_atomic.h>
63 #include <rte_branch_prediction.h>
65 #include <rte_mempool.h>
67 #include <rte_devargs.h>
69 #include <cmdline_rdline.h>
70 #include <cmdline_parse.h>
71 #include <cmdline_parse_ipaddr.h>
72 #include <cmdline_parse_num.h>
73 #include <cmdline_parse_string.h>
80 static struct test_commands_list commands_list =
81 TAILQ_HEAD_INITIALIZER(commands_list);
84 add_test_command(struct test_command *t)
86 TAILQ_INSERT_TAIL(&commands_list, t, next);
89 struct cmd_autotest_result {
90 cmdline_fixed_string_t autotest;
93 static void cmd_autotest_parsed(void *parsed_result,
94 __attribute__((unused)) struct cmdline *cl,
95 __attribute__((unused)) void *data)
97 struct test_command *t;
98 struct cmd_autotest_result *res = parsed_result;
101 TAILQ_FOREACH(t, &commands_list, next) {
102 if (!strcmp(res->autotest, t->command))
109 printf("Test Failed\n");
113 cmdline_parse_token_string_t cmd_autotest_autotest =
114 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
117 cmdline_parse_inst_t cmd_autotest = {
118 .f = cmd_autotest_parsed, /* function to call */
119 .data = NULL, /* 2nd arg of func */
120 .help_str = "launch autotest",
121 .tokens = { /* token list, NULL terminated */
122 (void *)&cmd_autotest_autotest,
129 struct cmd_dump_result {
130 cmdline_fixed_string_t dump;
134 dump_struct_sizes(void)
136 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
137 DUMP_SIZE(struct rte_mbuf);
138 DUMP_SIZE(struct rte_mempool);
139 DUMP_SIZE(struct rte_ring);
143 static void cmd_dump_parsed(void *parsed_result,
144 __attribute__((unused)) struct cmdline *cl,
145 __attribute__((unused)) void *data)
147 struct cmd_dump_result *res = parsed_result;
149 if (!strcmp(res->dump, "dump_physmem"))
150 rte_dump_physmem_layout(stdout);
151 else if (!strcmp(res->dump, "dump_memzone"))
152 rte_memzone_dump(stdout);
153 else if (!strcmp(res->dump, "dump_struct_sizes"))
155 else if (!strcmp(res->dump, "dump_ring"))
156 rte_ring_list_dump(stdout);
157 else if (!strcmp(res->dump, "dump_mempool"))
158 rte_mempool_list_dump(stdout);
159 else if (!strcmp(res->dump, "dump_devargs"))
160 rte_eal_devargs_dump(stdout);
161 else if (!strcmp(res->dump, "dump_log_types"))
162 rte_log_dump(stdout);
165 cmdline_parse_token_string_t cmd_dump_dump =
166 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
167 "dump_physmem#dump_memzone#"
168 "dump_struct_sizes#dump_ring#dump_mempool#"
169 "dump_devargs#dump_log_types");
171 cmdline_parse_inst_t cmd_dump = {
172 .f = cmd_dump_parsed, /* function to call */
173 .data = NULL, /* 2nd arg of func */
174 .help_str = "dump status",
175 .tokens = { /* token list, NULL terminated */
176 (void *)&cmd_dump_dump,
183 struct cmd_dump_one_result {
184 cmdline_fixed_string_t dump;
185 cmdline_fixed_string_t name;
188 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
189 __attribute__((unused)) void *data)
191 struct cmd_dump_one_result *res = parsed_result;
193 if (!strcmp(res->dump, "dump_ring")) {
195 r = rte_ring_lookup(res->name);
197 cmdline_printf(cl, "Cannot find ring\n");
200 rte_ring_dump(stdout, r);
202 else if (!strcmp(res->dump, "dump_mempool")) {
203 struct rte_mempool *mp;
204 mp = rte_mempool_lookup(res->name);
206 cmdline_printf(cl, "Cannot find mempool\n");
209 rte_mempool_dump(stdout, mp);
213 cmdline_parse_token_string_t cmd_dump_one_dump =
214 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
215 "dump_ring#dump_mempool");
217 cmdline_parse_token_string_t cmd_dump_one_name =
218 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
220 cmdline_parse_inst_t cmd_dump_one = {
221 .f = cmd_dump_one_parsed, /* function to call */
222 .data = NULL, /* 2nd arg of func */
223 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
224 .tokens = { /* token list, NULL terminated */
225 (void *)&cmd_dump_one_dump,
226 (void *)&cmd_dump_one_name,
233 struct cmd_quit_result {
234 cmdline_fixed_string_t quit;
238 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
240 __attribute__((unused)) void *data)
245 cmdline_parse_token_string_t cmd_quit_quit =
246 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
249 cmdline_parse_inst_t cmd_quit = {
250 .f = cmd_quit_parsed, /* function to call */
251 .data = NULL, /* 2nd arg of func */
252 .help_str = "exit application",
253 .tokens = { /* token list, NULL terminated */
254 (void *)&cmd_quit_quit,
261 struct cmd_set_rxtx_result {
262 cmdline_fixed_string_t set;
263 cmdline_fixed_string_t mode;
266 static void cmd_set_rxtx_parsed(void *parsed_result, struct cmdline *cl,
267 __attribute__((unused)) void *data)
269 struct cmd_set_rxtx_result *res = parsed_result;
270 if (test_set_rxtx_conf(res->mode) < 0)
271 cmdline_printf(cl, "Cannot find such mode\n");
274 cmdline_parse_token_string_t cmd_set_rxtx_set =
275 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, set,
278 cmdline_parse_token_string_t cmd_set_rxtx_mode =
279 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, mode, NULL);
281 cmdline_parse_inst_t cmd_set_rxtx = {
282 .f = cmd_set_rxtx_parsed, /* function to call */
283 .data = NULL, /* 2nd arg of func */
284 .help_str = "set rxtx routine: "
286 .tokens = { /* token list, NULL terminated */
287 (void *)&cmd_set_rxtx_set,
288 (void *)&cmd_set_rxtx_mode,
295 struct cmd_set_rxtx_anchor {
296 cmdline_fixed_string_t set;
297 cmdline_fixed_string_t type;
301 cmd_set_rxtx_anchor_parsed(void *parsed_result,
303 __attribute__((unused)) void *data)
305 struct cmd_set_rxtx_anchor *res = parsed_result;
306 if (test_set_rxtx_anchor(res->type) < 0)
307 cmdline_printf(cl, "Cannot find such anchor\n");
310 cmdline_parse_token_string_t cmd_set_rxtx_anchor_set =
311 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, set,
314 cmdline_parse_token_string_t cmd_set_rxtx_anchor_type =
315 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, type, NULL);
317 cmdline_parse_inst_t cmd_set_rxtx_anchor = {
318 .f = cmd_set_rxtx_anchor_parsed, /* function to call */
319 .data = NULL, /* 2nd arg of func */
320 .help_str = "set rxtx anchor: "
321 "set_rxtx_anchor <type>",
322 .tokens = { /* token list, NULL terminated */
323 (void *)&cmd_set_rxtx_anchor_set,
324 (void *)&cmd_set_rxtx_anchor_type,
331 /* for stream control */
332 struct cmd_set_rxtx_sc {
333 cmdline_fixed_string_t set;
334 cmdline_fixed_string_t type;
338 cmd_set_rxtx_sc_parsed(void *parsed_result,
340 __attribute__((unused)) void *data)
342 struct cmd_set_rxtx_sc *res = parsed_result;
343 if (test_set_rxtx_sc(res->type) < 0)
344 cmdline_printf(cl, "Cannot find such stream control\n");
347 cmdline_parse_token_string_t cmd_set_rxtx_sc_set =
348 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, set,
351 cmdline_parse_token_string_t cmd_set_rxtx_sc_type =
352 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, type, NULL);
354 cmdline_parse_inst_t cmd_set_rxtx_sc = {
355 .f = cmd_set_rxtx_sc_parsed, /* function to call */
356 .data = NULL, /* 2nd arg of func */
357 .help_str = "set rxtx stream control: "
358 "set_rxtx_sc <type>",
359 .tokens = { /* token list, NULL terminated */
360 (void *)&cmd_set_rxtx_sc_set,
361 (void *)&cmd_set_rxtx_sc_type,
369 cmdline_parse_ctx_t main_ctx[] = {
370 (cmdline_parse_inst_t *)&cmd_autotest,
371 (cmdline_parse_inst_t *)&cmd_dump,
372 (cmdline_parse_inst_t *)&cmd_dump_one,
373 (cmdline_parse_inst_t *)&cmd_quit,
374 (cmdline_parse_inst_t *)&cmd_set_rxtx,
375 (cmdline_parse_inst_t *)&cmd_set_rxtx_anchor,
376 (cmdline_parse_inst_t *)&cmd_set_rxtx_sc,
380 int commands_init(void)
382 struct test_command *t;
383 char *commands, *ptr;
384 int commands_len = 0;
386 TAILQ_FOREACH(t, &commands_list, next) {
387 commands_len += strlen(t->command) + 1;
390 commands = malloc(commands_len + 1);
395 TAILQ_FOREACH(t, &commands_list, next) {
396 ptr += sprintf(ptr, "%s#", t->command);
401 cmd_autotest_autotest.string_data.str = commands;