1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
13 #include <sys/queue.h>
15 #include <rte_common.h>
17 #include <rte_debug.h>
18 #include <rte_memory.h>
19 #include <rte_memcpy.h>
20 #include <rte_memzone.h>
21 #include <rte_launch.h>
22 #include <rte_cycles.h>
24 #include <rte_per_lcore.h>
25 #include <rte_lcore.h>
26 #include <rte_branch_prediction.h>
28 #include <rte_malloc.h>
29 #include <rte_mempool.h>
31 #include <rte_devargs.h>
33 #include <cmdline_rdline.h>
34 #include <cmdline_parse.h>
35 #include <cmdline_parse_ipaddr.h>
36 #include <cmdline_parse_num.h>
37 #include <cmdline_parse_string.h>
39 #include <rte_string_fns.h>
45 static struct test_commands_list commands_list =
46 TAILQ_HEAD_INITIALIZER(commands_list);
49 add_test_command(struct test_command *t)
51 TAILQ_INSERT_TAIL(&commands_list, t, next);
54 struct cmd_autotest_result {
55 cmdline_fixed_string_t autotest;
58 static void cmd_autotest_parsed(void *parsed_result,
59 __rte_unused struct cmdline *cl,
60 __rte_unused void *data)
62 struct test_command *t;
63 struct cmd_autotest_result *res = parsed_result;
66 TAILQ_FOREACH(t, &commands_list, next) {
67 if (!strcmp(res->autotest, t->command))
71 last_test_result = ret;
74 else if (ret == TEST_SKIPPED)
75 printf("Test Skipped\n");
77 printf("Test Failed\n");
81 cmdline_parse_token_string_t cmd_autotest_autotest =
82 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
85 cmdline_parse_inst_t cmd_autotest = {
86 .f = cmd_autotest_parsed, /* function to call */
87 .data = NULL, /* 2nd arg of func */
88 .help_str = "launch autotest",
89 .tokens = { /* token list, NULL terminated */
90 (void *)&cmd_autotest_autotest,
97 struct cmd_dump_result {
98 cmdline_fixed_string_t dump;
102 dump_struct_sizes(void)
104 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
105 DUMP_SIZE(struct rte_mbuf);
106 DUMP_SIZE(struct rte_mempool);
107 DUMP_SIZE(struct rte_ring);
111 static void cmd_dump_parsed(void *parsed_result,
112 __rte_unused struct cmdline *cl,
113 __rte_unused void *data)
115 struct cmd_dump_result *res = parsed_result;
117 if (!strcmp(res->dump, "dump_physmem"))
118 rte_dump_physmem_layout(stdout);
119 else if (!strcmp(res->dump, "dump_memzone"))
120 rte_memzone_dump(stdout);
121 else if (!strcmp(res->dump, "dump_struct_sizes"))
123 else if (!strcmp(res->dump, "dump_ring"))
124 rte_ring_list_dump(stdout);
125 else if (!strcmp(res->dump, "dump_mempool"))
126 rte_mempool_list_dump(stdout);
127 else if (!strcmp(res->dump, "dump_devargs"))
128 rte_devargs_dump(stdout);
129 else if (!strcmp(res->dump, "dump_log_types"))
130 rte_log_dump(stdout);
131 else if (!strcmp(res->dump, "dump_malloc_stats"))
132 rte_malloc_dump_stats(stdout, NULL);
133 else if (!strcmp(res->dump, "dump_malloc_heaps"))
134 rte_malloc_dump_heaps(stdout);
137 cmdline_parse_token_string_t cmd_dump_dump =
138 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
149 cmdline_parse_inst_t cmd_dump = {
150 .f = cmd_dump_parsed, /* function to call */
151 .data = NULL, /* 2nd arg of func */
152 .help_str = "dump status",
153 .tokens = { /* token list, NULL terminated */
154 (void *)&cmd_dump_dump,
161 struct cmd_dump_one_result {
162 cmdline_fixed_string_t dump;
163 cmdline_fixed_string_t name;
166 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
167 __rte_unused void *data)
169 struct cmd_dump_one_result *res = parsed_result;
171 if (!strcmp(res->dump, "dump_ring")) {
173 r = rte_ring_lookup(res->name);
175 cmdline_printf(cl, "Cannot find ring\n");
178 rte_ring_dump(stdout, r);
180 else if (!strcmp(res->dump, "dump_mempool")) {
181 struct rte_mempool *mp;
182 mp = rte_mempool_lookup(res->name);
184 cmdline_printf(cl, "Cannot find mempool\n");
187 rte_mempool_dump(stdout, mp);
191 cmdline_parse_token_string_t cmd_dump_one_dump =
192 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
193 "dump_ring#dump_mempool");
195 cmdline_parse_token_string_t cmd_dump_one_name =
196 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
198 cmdline_parse_inst_t cmd_dump_one = {
199 .f = cmd_dump_one_parsed, /* function to call */
200 .data = NULL, /* 2nd arg of func */
201 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
202 .tokens = { /* token list, NULL terminated */
203 (void *)&cmd_dump_one_dump,
204 (void *)&cmd_dump_one_name,
211 struct cmd_quit_result {
212 cmdline_fixed_string_t quit;
216 cmd_quit_parsed(__rte_unused void *parsed_result,
218 __rte_unused void *data)
223 cmdline_parse_token_string_t cmd_quit_quit =
224 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
227 cmdline_parse_inst_t cmd_quit = {
228 .f = cmd_quit_parsed, /* function to call */
229 .data = NULL, /* 2nd arg of func */
230 .help_str = "exit application",
231 .tokens = { /* token list, NULL terminated */
232 (void *)&cmd_quit_quit,
239 struct cmd_set_rxtx_result {
240 cmdline_fixed_string_t set;
241 cmdline_fixed_string_t mode;
244 static void cmd_set_rxtx_parsed(void *parsed_result, struct cmdline *cl,
245 __rte_unused void *data)
247 struct cmd_set_rxtx_result *res = parsed_result;
248 if (test_set_rxtx_conf(res->mode) < 0)
249 cmdline_printf(cl, "Cannot find such mode\n");
252 cmdline_parse_token_string_t cmd_set_rxtx_set =
253 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, set,
256 cmdline_parse_token_string_t cmd_set_rxtx_mode =
257 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, mode, NULL);
259 cmdline_parse_inst_t cmd_set_rxtx = {
260 .f = cmd_set_rxtx_parsed, /* function to call */
261 .data = NULL, /* 2nd arg of func */
262 .help_str = "set rxtx routine: "
264 .tokens = { /* token list, NULL terminated */
265 (void *)&cmd_set_rxtx_set,
266 (void *)&cmd_set_rxtx_mode,
273 struct cmd_set_rxtx_anchor {
274 cmdline_fixed_string_t set;
275 cmdline_fixed_string_t type;
279 cmd_set_rxtx_anchor_parsed(void *parsed_result,
281 __rte_unused void *data)
283 struct cmd_set_rxtx_anchor *res = parsed_result;
284 if (test_set_rxtx_anchor(res->type) < 0)
285 cmdline_printf(cl, "Cannot find such anchor\n");
288 cmdline_parse_token_string_t cmd_set_rxtx_anchor_set =
289 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, set,
292 cmdline_parse_token_string_t cmd_set_rxtx_anchor_type =
293 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, type, NULL);
295 cmdline_parse_inst_t cmd_set_rxtx_anchor = {
296 .f = cmd_set_rxtx_anchor_parsed, /* function to call */
297 .data = NULL, /* 2nd arg of func */
298 .help_str = "set rxtx anchor: "
299 "set_rxtx_anchor <type>",
300 .tokens = { /* token list, NULL terminated */
301 (void *)&cmd_set_rxtx_anchor_set,
302 (void *)&cmd_set_rxtx_anchor_type,
309 /* for stream control */
310 struct cmd_set_rxtx_sc {
311 cmdline_fixed_string_t set;
312 cmdline_fixed_string_t type;
316 cmd_set_rxtx_sc_parsed(void *parsed_result,
318 __rte_unused void *data)
320 struct cmd_set_rxtx_sc *res = parsed_result;
321 if (test_set_rxtx_sc(res->type) < 0)
322 cmdline_printf(cl, "Cannot find such stream control\n");
325 cmdline_parse_token_string_t cmd_set_rxtx_sc_set =
326 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, set,
329 cmdline_parse_token_string_t cmd_set_rxtx_sc_type =
330 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, type, NULL);
332 cmdline_parse_inst_t cmd_set_rxtx_sc = {
333 .f = cmd_set_rxtx_sc_parsed, /* function to call */
334 .data = NULL, /* 2nd arg of func */
335 .help_str = "set rxtx stream control: "
336 "set_rxtx_sc <type>",
337 .tokens = { /* token list, NULL terminated */
338 (void *)&cmd_set_rxtx_sc_set,
339 (void *)&cmd_set_rxtx_sc_type,
347 cmdline_parse_ctx_t main_ctx[] = {
348 (cmdline_parse_inst_t *)&cmd_autotest,
349 (cmdline_parse_inst_t *)&cmd_dump,
350 (cmdline_parse_inst_t *)&cmd_dump_one,
351 (cmdline_parse_inst_t *)&cmd_quit,
352 (cmdline_parse_inst_t *)&cmd_set_rxtx,
353 (cmdline_parse_inst_t *)&cmd_set_rxtx_anchor,
354 (cmdline_parse_inst_t *)&cmd_set_rxtx_sc,
358 int commands_init(void)
360 struct test_command *t;
362 int commands_len = 0;
364 TAILQ_FOREACH(t, &commands_list, next) {
365 commands_len += strlen(t->command) + 1;
368 commands = (char *)calloc(commands_len, sizeof(char));
372 TAILQ_FOREACH(t, &commands_list, next) {
373 strlcat(commands, t->command, commands_len);
374 if (TAILQ_NEXT(t, next) != NULL)
375 strlcat(commands, "#", commands_len);
378 cmd_autotest_autotest.string_data.str = commands;
382 int command_valid(const char *cmd)
384 struct test_command *t;
386 TAILQ_FOREACH(t, &commands_list, next) {
387 if (strcmp(t->command, cmd) == 0)