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 <sys/queue.h>
17 #include <rte_common.h>
19 #include <rte_debug.h>
20 #include <rte_memory.h>
21 #include <rte_memcpy.h>
22 #include <rte_memzone.h>
23 #include <rte_launch.h>
24 #include <rte_cycles.h>
26 #include <rte_per_lcore.h>
27 #include <rte_lcore.h>
28 #include <rte_atomic.h>
29 #include <rte_branch_prediction.h>
31 #include <rte_malloc.h>
32 #include <rte_mempool.h>
34 #include <rte_devargs.h>
36 #include <cmdline_rdline.h>
37 #include <cmdline_parse.h>
38 #include <cmdline_parse_ipaddr.h>
39 #include <cmdline_parse_num.h>
40 #include <cmdline_parse_string.h>
42 #include <rte_string_fns.h>
48 static struct test_commands_list commands_list =
49 TAILQ_HEAD_INITIALIZER(commands_list);
52 add_test_command(struct test_command *t)
54 TAILQ_INSERT_TAIL(&commands_list, t, next);
57 struct cmd_autotest_result {
58 cmdline_fixed_string_t autotest;
61 static void cmd_autotest_parsed(void *parsed_result,
62 __rte_unused struct cmdline *cl,
63 __rte_unused void *data)
65 struct test_command *t;
66 struct cmd_autotest_result *res = parsed_result;
69 TAILQ_FOREACH(t, &commands_list, next) {
70 if (!strcmp(res->autotest, t->command))
74 last_test_result = ret;
77 else if (ret == TEST_SKIPPED)
78 printf("Test Skipped\n");
80 printf("Test Failed\n");
84 cmdline_parse_token_string_t cmd_autotest_autotest =
85 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
88 cmdline_parse_inst_t cmd_autotest = {
89 .f = cmd_autotest_parsed, /* function to call */
90 .data = NULL, /* 2nd arg of func */
91 .help_str = "launch autotest",
92 .tokens = { /* token list, NULL terminated */
93 (void *)&cmd_autotest_autotest,
100 struct cmd_dump_result {
101 cmdline_fixed_string_t dump;
105 dump_struct_sizes(void)
107 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
108 DUMP_SIZE(struct rte_mbuf);
109 DUMP_SIZE(struct rte_mempool);
110 DUMP_SIZE(struct rte_ring);
114 static void cmd_dump_parsed(void *parsed_result,
115 __rte_unused struct cmdline *cl,
116 __rte_unused void *data)
118 struct cmd_dump_result *res = parsed_result;
120 if (!strcmp(res->dump, "dump_physmem"))
121 rte_dump_physmem_layout(stdout);
122 else if (!strcmp(res->dump, "dump_memzone"))
123 rte_memzone_dump(stdout);
124 else if (!strcmp(res->dump, "dump_struct_sizes"))
126 else if (!strcmp(res->dump, "dump_ring"))
127 rte_ring_list_dump(stdout);
128 else if (!strcmp(res->dump, "dump_mempool"))
129 rte_mempool_list_dump(stdout);
130 else if (!strcmp(res->dump, "dump_devargs"))
131 rte_devargs_dump(stdout);
132 else if (!strcmp(res->dump, "dump_log_types"))
133 rte_log_dump(stdout);
134 else if (!strcmp(res->dump, "dump_malloc_stats"))
135 rte_malloc_dump_stats(stdout, NULL);
136 else if (!strcmp(res->dump, "dump_malloc_heaps"))
137 rte_malloc_dump_heaps(stdout);
140 cmdline_parse_token_string_t cmd_dump_dump =
141 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
152 cmdline_parse_inst_t cmd_dump = {
153 .f = cmd_dump_parsed, /* function to call */
154 .data = NULL, /* 2nd arg of func */
155 .help_str = "dump status",
156 .tokens = { /* token list, NULL terminated */
157 (void *)&cmd_dump_dump,
164 struct cmd_dump_one_result {
165 cmdline_fixed_string_t dump;
166 cmdline_fixed_string_t name;
169 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
170 __rte_unused void *data)
172 struct cmd_dump_one_result *res = parsed_result;
174 if (!strcmp(res->dump, "dump_ring")) {
176 r = rte_ring_lookup(res->name);
178 cmdline_printf(cl, "Cannot find ring\n");
181 rte_ring_dump(stdout, r);
183 else if (!strcmp(res->dump, "dump_mempool")) {
184 struct rte_mempool *mp;
185 mp = rte_mempool_lookup(res->name);
187 cmdline_printf(cl, "Cannot find mempool\n");
190 rte_mempool_dump(stdout, mp);
194 cmdline_parse_token_string_t cmd_dump_one_dump =
195 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
196 "dump_ring#dump_mempool");
198 cmdline_parse_token_string_t cmd_dump_one_name =
199 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
201 cmdline_parse_inst_t cmd_dump_one = {
202 .f = cmd_dump_one_parsed, /* function to call */
203 .data = NULL, /* 2nd arg of func */
204 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
205 .tokens = { /* token list, NULL terminated */
206 (void *)&cmd_dump_one_dump,
207 (void *)&cmd_dump_one_name,
214 struct cmd_quit_result {
215 cmdline_fixed_string_t quit;
219 cmd_quit_parsed(__rte_unused void *parsed_result,
221 __rte_unused void *data)
226 cmdline_parse_token_string_t cmd_quit_quit =
227 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
230 cmdline_parse_inst_t cmd_quit = {
231 .f = cmd_quit_parsed, /* function to call */
232 .data = NULL, /* 2nd arg of func */
233 .help_str = "exit application",
234 .tokens = { /* token list, NULL terminated */
235 (void *)&cmd_quit_quit,
242 struct cmd_set_rxtx_result {
243 cmdline_fixed_string_t set;
244 cmdline_fixed_string_t mode;
247 static void cmd_set_rxtx_parsed(void *parsed_result, struct cmdline *cl,
248 __rte_unused void *data)
250 struct cmd_set_rxtx_result *res = parsed_result;
251 if (test_set_rxtx_conf(res->mode) < 0)
252 cmdline_printf(cl, "Cannot find such mode\n");
255 cmdline_parse_token_string_t cmd_set_rxtx_set =
256 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, set,
259 cmdline_parse_token_string_t cmd_set_rxtx_mode =
260 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, mode, NULL);
262 cmdline_parse_inst_t cmd_set_rxtx = {
263 .f = cmd_set_rxtx_parsed, /* function to call */
264 .data = NULL, /* 2nd arg of func */
265 .help_str = "set rxtx routine: "
267 .tokens = { /* token list, NULL terminated */
268 (void *)&cmd_set_rxtx_set,
269 (void *)&cmd_set_rxtx_mode,
276 struct cmd_set_rxtx_anchor {
277 cmdline_fixed_string_t set;
278 cmdline_fixed_string_t type;
282 cmd_set_rxtx_anchor_parsed(void *parsed_result,
284 __rte_unused void *data)
286 struct cmd_set_rxtx_anchor *res = parsed_result;
287 if (test_set_rxtx_anchor(res->type) < 0)
288 cmdline_printf(cl, "Cannot find such anchor\n");
291 cmdline_parse_token_string_t cmd_set_rxtx_anchor_set =
292 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, set,
295 cmdline_parse_token_string_t cmd_set_rxtx_anchor_type =
296 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, type, NULL);
298 cmdline_parse_inst_t cmd_set_rxtx_anchor = {
299 .f = cmd_set_rxtx_anchor_parsed, /* function to call */
300 .data = NULL, /* 2nd arg of func */
301 .help_str = "set rxtx anchor: "
302 "set_rxtx_anchor <type>",
303 .tokens = { /* token list, NULL terminated */
304 (void *)&cmd_set_rxtx_anchor_set,
305 (void *)&cmd_set_rxtx_anchor_type,
312 /* for stream control */
313 struct cmd_set_rxtx_sc {
314 cmdline_fixed_string_t set;
315 cmdline_fixed_string_t type;
319 cmd_set_rxtx_sc_parsed(void *parsed_result,
321 __rte_unused void *data)
323 struct cmd_set_rxtx_sc *res = parsed_result;
324 if (test_set_rxtx_sc(res->type) < 0)
325 cmdline_printf(cl, "Cannot find such stream control\n");
328 cmdline_parse_token_string_t cmd_set_rxtx_sc_set =
329 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, set,
332 cmdline_parse_token_string_t cmd_set_rxtx_sc_type =
333 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, type, NULL);
335 cmdline_parse_inst_t cmd_set_rxtx_sc = {
336 .f = cmd_set_rxtx_sc_parsed, /* function to call */
337 .data = NULL, /* 2nd arg of func */
338 .help_str = "set rxtx stream control: "
339 "set_rxtx_sc <type>",
340 .tokens = { /* token list, NULL terminated */
341 (void *)&cmd_set_rxtx_sc_set,
342 (void *)&cmd_set_rxtx_sc_type,
350 cmdline_parse_ctx_t main_ctx[] = {
351 (cmdline_parse_inst_t *)&cmd_autotest,
352 (cmdline_parse_inst_t *)&cmd_dump,
353 (cmdline_parse_inst_t *)&cmd_dump_one,
354 (cmdline_parse_inst_t *)&cmd_quit,
355 (cmdline_parse_inst_t *)&cmd_set_rxtx,
356 (cmdline_parse_inst_t *)&cmd_set_rxtx_anchor,
357 (cmdline_parse_inst_t *)&cmd_set_rxtx_sc,
361 int commands_init(void)
363 struct test_command *t;
365 int commands_len = 0;
367 TAILQ_FOREACH(t, &commands_list, next) {
368 commands_len += strlen(t->command) + 1;
371 commands = (char *)calloc(commands_len, sizeof(char));
375 TAILQ_FOREACH(t, &commands_list, next) {
376 strlcat(commands, t->command, commands_len);
377 if (TAILQ_NEXT(t, next) != NULL)
378 strlcat(commands, "#", commands_len);
381 cmd_autotest_autotest.string_data.str = commands;