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_branch_prediction.h>
30 #include <rte_malloc.h>
31 #include <rte_mempool.h>
33 #include <rte_devargs.h>
35 #include <cmdline_rdline.h>
36 #include <cmdline_parse.h>
37 #include <cmdline_parse_ipaddr.h>
38 #include <cmdline_parse_num.h>
39 #include <cmdline_parse_string.h>
41 #include <rte_string_fns.h>
47 static struct test_commands_list commands_list =
48 TAILQ_HEAD_INITIALIZER(commands_list);
51 add_test_command(struct test_command *t)
53 TAILQ_INSERT_TAIL(&commands_list, t, next);
56 struct cmd_autotest_result {
57 cmdline_fixed_string_t autotest;
60 static void cmd_autotest_parsed(void *parsed_result,
61 __rte_unused struct cmdline *cl,
62 __rte_unused void *data)
64 struct test_command *t;
65 struct cmd_autotest_result *res = parsed_result;
68 TAILQ_FOREACH(t, &commands_list, next) {
69 if (!strcmp(res->autotest, t->command))
73 last_test_result = ret;
76 else if (ret == TEST_SKIPPED)
77 printf("Test Skipped\n");
79 printf("Test Failed\n");
83 cmdline_parse_token_string_t cmd_autotest_autotest =
84 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
87 cmdline_parse_inst_t cmd_autotest = {
88 .f = cmd_autotest_parsed, /* function to call */
89 .data = NULL, /* 2nd arg of func */
90 .help_str = "launch autotest",
91 .tokens = { /* token list, NULL terminated */
92 (void *)&cmd_autotest_autotest,
99 struct cmd_dump_result {
100 cmdline_fixed_string_t dump;
104 dump_struct_sizes(void)
106 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
107 DUMP_SIZE(struct rte_mbuf);
108 DUMP_SIZE(struct rte_mempool);
109 DUMP_SIZE(struct rte_ring);
113 static void cmd_dump_parsed(void *parsed_result,
114 __rte_unused struct cmdline *cl,
115 __rte_unused void *data)
117 struct cmd_dump_result *res = parsed_result;
119 if (!strcmp(res->dump, "dump_physmem"))
120 rte_dump_physmem_layout(stdout);
121 else if (!strcmp(res->dump, "dump_memzone"))
122 rte_memzone_dump(stdout);
123 else if (!strcmp(res->dump, "dump_struct_sizes"))
125 else if (!strcmp(res->dump, "dump_ring"))
126 rte_ring_list_dump(stdout);
127 else if (!strcmp(res->dump, "dump_mempool"))
128 rte_mempool_list_dump(stdout);
129 else if (!strcmp(res->dump, "dump_devargs"))
130 rte_devargs_dump(stdout);
131 else if (!strcmp(res->dump, "dump_log_types"))
132 rte_log_dump(stdout);
133 else if (!strcmp(res->dump, "dump_malloc_stats"))
134 rte_malloc_dump_stats(stdout, NULL);
135 else if (!strcmp(res->dump, "dump_malloc_heaps"))
136 rte_malloc_dump_heaps(stdout);
139 cmdline_parse_token_string_t cmd_dump_dump =
140 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
151 cmdline_parse_inst_t cmd_dump = {
152 .f = cmd_dump_parsed, /* function to call */
153 .data = NULL, /* 2nd arg of func */
154 .help_str = "dump status",
155 .tokens = { /* token list, NULL terminated */
156 (void *)&cmd_dump_dump,
163 struct cmd_dump_one_result {
164 cmdline_fixed_string_t dump;
165 cmdline_fixed_string_t name;
168 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
169 __rte_unused void *data)
171 struct cmd_dump_one_result *res = parsed_result;
173 if (!strcmp(res->dump, "dump_ring")) {
175 r = rte_ring_lookup(res->name);
177 cmdline_printf(cl, "Cannot find ring\n");
180 rte_ring_dump(stdout, r);
182 else if (!strcmp(res->dump, "dump_mempool")) {
183 struct rte_mempool *mp;
184 mp = rte_mempool_lookup(res->name);
186 cmdline_printf(cl, "Cannot find mempool\n");
189 rte_mempool_dump(stdout, mp);
193 cmdline_parse_token_string_t cmd_dump_one_dump =
194 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
195 "dump_ring#dump_mempool");
197 cmdline_parse_token_string_t cmd_dump_one_name =
198 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
200 cmdline_parse_inst_t cmd_dump_one = {
201 .f = cmd_dump_one_parsed, /* function to call */
202 .data = NULL, /* 2nd arg of func */
203 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
204 .tokens = { /* token list, NULL terminated */
205 (void *)&cmd_dump_one_dump,
206 (void *)&cmd_dump_one_name,
213 struct cmd_quit_result {
214 cmdline_fixed_string_t quit;
218 cmd_quit_parsed(__rte_unused void *parsed_result,
220 __rte_unused void *data)
225 cmdline_parse_token_string_t cmd_quit_quit =
226 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
229 cmdline_parse_inst_t cmd_quit = {
230 .f = cmd_quit_parsed, /* function to call */
231 .data = NULL, /* 2nd arg of func */
232 .help_str = "exit application",
233 .tokens = { /* token list, NULL terminated */
234 (void *)&cmd_quit_quit,
241 struct cmd_set_rxtx_result {
242 cmdline_fixed_string_t set;
243 cmdline_fixed_string_t mode;
246 static void cmd_set_rxtx_parsed(void *parsed_result, struct cmdline *cl,
247 __rte_unused void *data)
249 struct cmd_set_rxtx_result *res = parsed_result;
250 if (test_set_rxtx_conf(res->mode) < 0)
251 cmdline_printf(cl, "Cannot find such mode\n");
254 cmdline_parse_token_string_t cmd_set_rxtx_set =
255 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, set,
258 cmdline_parse_token_string_t cmd_set_rxtx_mode =
259 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, mode, NULL);
261 cmdline_parse_inst_t cmd_set_rxtx = {
262 .f = cmd_set_rxtx_parsed, /* function to call */
263 .data = NULL, /* 2nd arg of func */
264 .help_str = "set rxtx routine: "
266 .tokens = { /* token list, NULL terminated */
267 (void *)&cmd_set_rxtx_set,
268 (void *)&cmd_set_rxtx_mode,
275 struct cmd_set_rxtx_anchor {
276 cmdline_fixed_string_t set;
277 cmdline_fixed_string_t type;
281 cmd_set_rxtx_anchor_parsed(void *parsed_result,
283 __rte_unused void *data)
285 struct cmd_set_rxtx_anchor *res = parsed_result;
286 if (test_set_rxtx_anchor(res->type) < 0)
287 cmdline_printf(cl, "Cannot find such anchor\n");
290 cmdline_parse_token_string_t cmd_set_rxtx_anchor_set =
291 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, set,
294 cmdline_parse_token_string_t cmd_set_rxtx_anchor_type =
295 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, type, NULL);
297 cmdline_parse_inst_t cmd_set_rxtx_anchor = {
298 .f = cmd_set_rxtx_anchor_parsed, /* function to call */
299 .data = NULL, /* 2nd arg of func */
300 .help_str = "set rxtx anchor: "
301 "set_rxtx_anchor <type>",
302 .tokens = { /* token list, NULL terminated */
303 (void *)&cmd_set_rxtx_anchor_set,
304 (void *)&cmd_set_rxtx_anchor_type,
311 /* for stream control */
312 struct cmd_set_rxtx_sc {
313 cmdline_fixed_string_t set;
314 cmdline_fixed_string_t type;
318 cmd_set_rxtx_sc_parsed(void *parsed_result,
320 __rte_unused void *data)
322 struct cmd_set_rxtx_sc *res = parsed_result;
323 if (test_set_rxtx_sc(res->type) < 0)
324 cmdline_printf(cl, "Cannot find such stream control\n");
327 cmdline_parse_token_string_t cmd_set_rxtx_sc_set =
328 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, set,
331 cmdline_parse_token_string_t cmd_set_rxtx_sc_type =
332 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, type, NULL);
334 cmdline_parse_inst_t cmd_set_rxtx_sc = {
335 .f = cmd_set_rxtx_sc_parsed, /* function to call */
336 .data = NULL, /* 2nd arg of func */
337 .help_str = "set rxtx stream control: "
338 "set_rxtx_sc <type>",
339 .tokens = { /* token list, NULL terminated */
340 (void *)&cmd_set_rxtx_sc_set,
341 (void *)&cmd_set_rxtx_sc_type,
349 cmdline_parse_ctx_t main_ctx[] = {
350 (cmdline_parse_inst_t *)&cmd_autotest,
351 (cmdline_parse_inst_t *)&cmd_dump,
352 (cmdline_parse_inst_t *)&cmd_dump_one,
353 (cmdline_parse_inst_t *)&cmd_quit,
354 (cmdline_parse_inst_t *)&cmd_set_rxtx,
355 (cmdline_parse_inst_t *)&cmd_set_rxtx_anchor,
356 (cmdline_parse_inst_t *)&cmd_set_rxtx_sc,
360 int commands_init(void)
362 struct test_command *t;
364 int commands_len = 0;
366 TAILQ_FOREACH(t, &commands_list, next) {
367 commands_len += strlen(t->command) + 1;
370 commands = (char *)calloc(commands_len, sizeof(char));
374 TAILQ_FOREACH(t, &commands_list, next) {
375 strlcat(commands, t->command, commands_len);
376 if (TAILQ_NEXT(t, next) != NULL)
377 strlcat(commands, "#", commands_len);
380 cmd_autotest_autotest.string_data.str = commands;
384 int command_valid(const char *cmd)
386 struct test_command *t;
388 TAILQ_FOREACH(t, &commands_list, next) {
389 if (strcmp(t->command, cmd) == 0)