1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
11 #include <netinet/in.h>
15 #include <net/socket.h>
20 #include <sys/queue.h>
22 #include <rte_common.h>
24 #include <rte_debug.h>
25 #include <rte_memory.h>
26 #include <rte_memcpy.h>
27 #include <rte_memzone.h>
28 #include <rte_launch.h>
29 #include <rte_cycles.h>
31 #include <rte_per_lcore.h>
32 #include <rte_lcore.h>
33 #include <rte_atomic.h>
34 #include <rte_branch_prediction.h>
36 #include <rte_malloc.h>
37 #include <rte_mempool.h>
39 #include <rte_devargs.h>
41 #include <cmdline_rdline.h>
42 #include <cmdline_parse.h>
43 #include <cmdline_parse_ipaddr.h>
44 #include <cmdline_parse_num.h>
45 #include <cmdline_parse_string.h>
52 static struct test_commands_list commands_list =
53 TAILQ_HEAD_INITIALIZER(commands_list);
56 add_test_command(struct test_command *t)
58 TAILQ_INSERT_TAIL(&commands_list, t, next);
61 struct cmd_autotest_result {
62 cmdline_fixed_string_t autotest;
65 static void cmd_autotest_parsed(void *parsed_result,
66 __attribute__((unused)) struct cmdline *cl,
67 __attribute__((unused)) void *data)
69 struct test_command *t;
70 struct cmd_autotest_result *res = parsed_result;
73 TAILQ_FOREACH(t, &commands_list, next) {
74 if (!strcmp(res->autotest, t->command))
78 last_test_result = ret;
81 else if (ret == TEST_SKIPPED)
82 printf("Test Skipped\n");
84 printf("Test Failed\n");
88 cmdline_parse_token_string_t cmd_autotest_autotest =
89 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
92 cmdline_parse_inst_t cmd_autotest = {
93 .f = cmd_autotest_parsed, /* function to call */
94 .data = NULL, /* 2nd arg of func */
95 .help_str = "launch autotest",
96 .tokens = { /* token list, NULL terminated */
97 (void *)&cmd_autotest_autotest,
104 struct cmd_dump_result {
105 cmdline_fixed_string_t dump;
109 dump_struct_sizes(void)
111 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
112 DUMP_SIZE(struct rte_mbuf);
113 DUMP_SIZE(struct rte_mempool);
114 DUMP_SIZE(struct rte_ring);
118 static void cmd_dump_parsed(void *parsed_result,
119 __attribute__((unused)) struct cmdline *cl,
120 __attribute__((unused)) void *data)
122 struct cmd_dump_result *res = parsed_result;
124 if (!strcmp(res->dump, "dump_physmem"))
125 rte_dump_physmem_layout(stdout);
126 else if (!strcmp(res->dump, "dump_memzone"))
127 rte_memzone_dump(stdout);
128 else if (!strcmp(res->dump, "dump_struct_sizes"))
130 else if (!strcmp(res->dump, "dump_ring"))
131 rte_ring_list_dump(stdout);
132 else if (!strcmp(res->dump, "dump_mempool"))
133 rte_mempool_list_dump(stdout);
134 else if (!strcmp(res->dump, "dump_devargs"))
135 rte_eal_devargs_dump(stdout);
136 else if (!strcmp(res->dump, "dump_log_types"))
137 rte_log_dump(stdout);
138 else if (!strcmp(res->dump, "dump_malloc_stats"))
139 rte_malloc_dump_stats(stdout, NULL);
142 cmdline_parse_token_string_t cmd_dump_dump =
143 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
153 cmdline_parse_inst_t cmd_dump = {
154 .f = cmd_dump_parsed, /* function to call */
155 .data = NULL, /* 2nd arg of func */
156 .help_str = "dump status",
157 .tokens = { /* token list, NULL terminated */
158 (void *)&cmd_dump_dump,
165 struct cmd_dump_one_result {
166 cmdline_fixed_string_t dump;
167 cmdline_fixed_string_t name;
170 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
171 __attribute__((unused)) void *data)
173 struct cmd_dump_one_result *res = parsed_result;
175 if (!strcmp(res->dump, "dump_ring")) {
177 r = rte_ring_lookup(res->name);
179 cmdline_printf(cl, "Cannot find ring\n");
182 rte_ring_dump(stdout, r);
184 else if (!strcmp(res->dump, "dump_mempool")) {
185 struct rte_mempool *mp;
186 mp = rte_mempool_lookup(res->name);
188 cmdline_printf(cl, "Cannot find mempool\n");
191 rte_mempool_dump(stdout, mp);
195 cmdline_parse_token_string_t cmd_dump_one_dump =
196 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
197 "dump_ring#dump_mempool");
199 cmdline_parse_token_string_t cmd_dump_one_name =
200 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
202 cmdline_parse_inst_t cmd_dump_one = {
203 .f = cmd_dump_one_parsed, /* function to call */
204 .data = NULL, /* 2nd arg of func */
205 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
206 .tokens = { /* token list, NULL terminated */
207 (void *)&cmd_dump_one_dump,
208 (void *)&cmd_dump_one_name,
215 struct cmd_quit_result {
216 cmdline_fixed_string_t quit;
220 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
222 __attribute__((unused)) void *data)
227 cmdline_parse_token_string_t cmd_quit_quit =
228 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
231 cmdline_parse_inst_t cmd_quit = {
232 .f = cmd_quit_parsed, /* function to call */
233 .data = NULL, /* 2nd arg of func */
234 .help_str = "exit application",
235 .tokens = { /* token list, NULL terminated */
236 (void *)&cmd_quit_quit,
243 struct cmd_set_rxtx_result {
244 cmdline_fixed_string_t set;
245 cmdline_fixed_string_t mode;
248 static void cmd_set_rxtx_parsed(void *parsed_result, struct cmdline *cl,
249 __attribute__((unused)) void *data)
251 struct cmd_set_rxtx_result *res = parsed_result;
252 if (test_set_rxtx_conf(res->mode) < 0)
253 cmdline_printf(cl, "Cannot find such mode\n");
256 cmdline_parse_token_string_t cmd_set_rxtx_set =
257 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, set,
260 cmdline_parse_token_string_t cmd_set_rxtx_mode =
261 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, mode, NULL);
263 cmdline_parse_inst_t cmd_set_rxtx = {
264 .f = cmd_set_rxtx_parsed, /* function to call */
265 .data = NULL, /* 2nd arg of func */
266 .help_str = "set rxtx routine: "
268 .tokens = { /* token list, NULL terminated */
269 (void *)&cmd_set_rxtx_set,
270 (void *)&cmd_set_rxtx_mode,
277 struct cmd_set_rxtx_anchor {
278 cmdline_fixed_string_t set;
279 cmdline_fixed_string_t type;
283 cmd_set_rxtx_anchor_parsed(void *parsed_result,
285 __attribute__((unused)) void *data)
287 struct cmd_set_rxtx_anchor *res = parsed_result;
288 if (test_set_rxtx_anchor(res->type) < 0)
289 cmdline_printf(cl, "Cannot find such anchor\n");
292 cmdline_parse_token_string_t cmd_set_rxtx_anchor_set =
293 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, set,
296 cmdline_parse_token_string_t cmd_set_rxtx_anchor_type =
297 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, type, NULL);
299 cmdline_parse_inst_t cmd_set_rxtx_anchor = {
300 .f = cmd_set_rxtx_anchor_parsed, /* function to call */
301 .data = NULL, /* 2nd arg of func */
302 .help_str = "set rxtx anchor: "
303 "set_rxtx_anchor <type>",
304 .tokens = { /* token list, NULL terminated */
305 (void *)&cmd_set_rxtx_anchor_set,
306 (void *)&cmd_set_rxtx_anchor_type,
313 /* for stream control */
314 struct cmd_set_rxtx_sc {
315 cmdline_fixed_string_t set;
316 cmdline_fixed_string_t type;
320 cmd_set_rxtx_sc_parsed(void *parsed_result,
322 __attribute__((unused)) void *data)
324 struct cmd_set_rxtx_sc *res = parsed_result;
325 if (test_set_rxtx_sc(res->type) < 0)
326 cmdline_printf(cl, "Cannot find such stream control\n");
329 cmdline_parse_token_string_t cmd_set_rxtx_sc_set =
330 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, set,
333 cmdline_parse_token_string_t cmd_set_rxtx_sc_type =
334 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, type, NULL);
336 cmdline_parse_inst_t cmd_set_rxtx_sc = {
337 .f = cmd_set_rxtx_sc_parsed, /* function to call */
338 .data = NULL, /* 2nd arg of func */
339 .help_str = "set rxtx stream control: "
340 "set_rxtx_sc <type>",
341 .tokens = { /* token list, NULL terminated */
342 (void *)&cmd_set_rxtx_sc_set,
343 (void *)&cmd_set_rxtx_sc_type,
351 cmdline_parse_ctx_t main_ctx[] = {
352 (cmdline_parse_inst_t *)&cmd_autotest,
353 (cmdline_parse_inst_t *)&cmd_dump,
354 (cmdline_parse_inst_t *)&cmd_dump_one,
355 (cmdline_parse_inst_t *)&cmd_quit,
356 (cmdline_parse_inst_t *)&cmd_set_rxtx,
357 (cmdline_parse_inst_t *)&cmd_set_rxtx_anchor,
358 (cmdline_parse_inst_t *)&cmd_set_rxtx_sc,
362 int commands_init(void)
364 struct test_command *t;
365 char *commands, *ptr;
366 int commands_len = 0;
368 TAILQ_FOREACH(t, &commands_list, next) {
369 commands_len += strlen(t->command) + 1;
372 commands = malloc(commands_len + 1);
377 TAILQ_FOREACH(t, &commands_list, next) {
378 ptr += sprintf(ptr, "%s#", t->command);
383 cmd_autotest_autotest.string_data.str = commands;