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_malloc.h>
66 #include <rte_mempool.h>
68 #include <rte_devargs.h>
70 #include <cmdline_rdline.h>
71 #include <cmdline_parse.h>
72 #include <cmdline_parse_ipaddr.h>
73 #include <cmdline_parse_num.h>
74 #include <cmdline_parse_string.h>
81 static struct test_commands_list commands_list =
82 TAILQ_HEAD_INITIALIZER(commands_list);
85 add_test_command(struct test_command *t)
87 TAILQ_INSERT_TAIL(&commands_list, t, next);
90 struct cmd_autotest_result {
91 cmdline_fixed_string_t autotest;
94 static void cmd_autotest_parsed(void *parsed_result,
95 __attribute__((unused)) struct cmdline *cl,
96 __attribute__((unused)) void *data)
98 struct test_command *t;
99 struct cmd_autotest_result *res = parsed_result;
102 TAILQ_FOREACH(t, &commands_list, next) {
103 if (!strcmp(res->autotest, t->command))
107 last_test_result = ret;
110 else if (ret == TEST_SKIPPED)
111 printf("Test Skipped\n");
113 printf("Test Failed\n");
117 cmdline_parse_token_string_t cmd_autotest_autotest =
118 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
121 cmdline_parse_inst_t cmd_autotest = {
122 .f = cmd_autotest_parsed, /* function to call */
123 .data = NULL, /* 2nd arg of func */
124 .help_str = "launch autotest",
125 .tokens = { /* token list, NULL terminated */
126 (void *)&cmd_autotest_autotest,
133 struct cmd_dump_result {
134 cmdline_fixed_string_t dump;
138 dump_struct_sizes(void)
140 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
141 DUMP_SIZE(struct rte_mbuf);
142 DUMP_SIZE(struct rte_mempool);
143 DUMP_SIZE(struct rte_ring);
147 static void cmd_dump_parsed(void *parsed_result,
148 __attribute__((unused)) struct cmdline *cl,
149 __attribute__((unused)) void *data)
151 struct cmd_dump_result *res = parsed_result;
153 if (!strcmp(res->dump, "dump_physmem"))
154 rte_dump_physmem_layout(stdout);
155 else if (!strcmp(res->dump, "dump_memzone"))
156 rte_memzone_dump(stdout);
157 else if (!strcmp(res->dump, "dump_struct_sizes"))
159 else if (!strcmp(res->dump, "dump_ring"))
160 rte_ring_list_dump(stdout);
161 else if (!strcmp(res->dump, "dump_mempool"))
162 rte_mempool_list_dump(stdout);
163 else if (!strcmp(res->dump, "dump_devargs"))
164 rte_eal_devargs_dump(stdout);
165 else if (!strcmp(res->dump, "dump_log_types"))
166 rte_log_dump(stdout);
167 else if (!strcmp(res->dump, "dump_malloc_stats"))
168 rte_malloc_dump_stats(stdout, NULL);
171 cmdline_parse_token_string_t cmd_dump_dump =
172 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
182 cmdline_parse_inst_t cmd_dump = {
183 .f = cmd_dump_parsed, /* function to call */
184 .data = NULL, /* 2nd arg of func */
185 .help_str = "dump status",
186 .tokens = { /* token list, NULL terminated */
187 (void *)&cmd_dump_dump,
194 struct cmd_dump_one_result {
195 cmdline_fixed_string_t dump;
196 cmdline_fixed_string_t name;
199 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
200 __attribute__((unused)) void *data)
202 struct cmd_dump_one_result *res = parsed_result;
204 if (!strcmp(res->dump, "dump_ring")) {
206 r = rte_ring_lookup(res->name);
208 cmdline_printf(cl, "Cannot find ring\n");
211 rte_ring_dump(stdout, r);
213 else if (!strcmp(res->dump, "dump_mempool")) {
214 struct rte_mempool *mp;
215 mp = rte_mempool_lookup(res->name);
217 cmdline_printf(cl, "Cannot find mempool\n");
220 rte_mempool_dump(stdout, mp);
224 cmdline_parse_token_string_t cmd_dump_one_dump =
225 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
226 "dump_ring#dump_mempool");
228 cmdline_parse_token_string_t cmd_dump_one_name =
229 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
231 cmdline_parse_inst_t cmd_dump_one = {
232 .f = cmd_dump_one_parsed, /* function to call */
233 .data = NULL, /* 2nd arg of func */
234 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
235 .tokens = { /* token list, NULL terminated */
236 (void *)&cmd_dump_one_dump,
237 (void *)&cmd_dump_one_name,
244 struct cmd_quit_result {
245 cmdline_fixed_string_t quit;
249 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
251 __attribute__((unused)) void *data)
256 cmdline_parse_token_string_t cmd_quit_quit =
257 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
260 cmdline_parse_inst_t cmd_quit = {
261 .f = cmd_quit_parsed, /* function to call */
262 .data = NULL, /* 2nd arg of func */
263 .help_str = "exit application",
264 .tokens = { /* token list, NULL terminated */
265 (void *)&cmd_quit_quit,
272 struct cmd_set_rxtx_result {
273 cmdline_fixed_string_t set;
274 cmdline_fixed_string_t mode;
277 static void cmd_set_rxtx_parsed(void *parsed_result, struct cmdline *cl,
278 __attribute__((unused)) void *data)
280 struct cmd_set_rxtx_result *res = parsed_result;
281 if (test_set_rxtx_conf(res->mode) < 0)
282 cmdline_printf(cl, "Cannot find such mode\n");
285 cmdline_parse_token_string_t cmd_set_rxtx_set =
286 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, set,
289 cmdline_parse_token_string_t cmd_set_rxtx_mode =
290 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, mode, NULL);
292 cmdline_parse_inst_t cmd_set_rxtx = {
293 .f = cmd_set_rxtx_parsed, /* function to call */
294 .data = NULL, /* 2nd arg of func */
295 .help_str = "set rxtx routine: "
297 .tokens = { /* token list, NULL terminated */
298 (void *)&cmd_set_rxtx_set,
299 (void *)&cmd_set_rxtx_mode,
306 struct cmd_set_rxtx_anchor {
307 cmdline_fixed_string_t set;
308 cmdline_fixed_string_t type;
312 cmd_set_rxtx_anchor_parsed(void *parsed_result,
314 __attribute__((unused)) void *data)
316 struct cmd_set_rxtx_anchor *res = parsed_result;
317 if (test_set_rxtx_anchor(res->type) < 0)
318 cmdline_printf(cl, "Cannot find such anchor\n");
321 cmdline_parse_token_string_t cmd_set_rxtx_anchor_set =
322 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, set,
325 cmdline_parse_token_string_t cmd_set_rxtx_anchor_type =
326 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, type, NULL);
328 cmdline_parse_inst_t cmd_set_rxtx_anchor = {
329 .f = cmd_set_rxtx_anchor_parsed, /* function to call */
330 .data = NULL, /* 2nd arg of func */
331 .help_str = "set rxtx anchor: "
332 "set_rxtx_anchor <type>",
333 .tokens = { /* token list, NULL terminated */
334 (void *)&cmd_set_rxtx_anchor_set,
335 (void *)&cmd_set_rxtx_anchor_type,
342 /* for stream control */
343 struct cmd_set_rxtx_sc {
344 cmdline_fixed_string_t set;
345 cmdline_fixed_string_t type;
349 cmd_set_rxtx_sc_parsed(void *parsed_result,
351 __attribute__((unused)) void *data)
353 struct cmd_set_rxtx_sc *res = parsed_result;
354 if (test_set_rxtx_sc(res->type) < 0)
355 cmdline_printf(cl, "Cannot find such stream control\n");
358 cmdline_parse_token_string_t cmd_set_rxtx_sc_set =
359 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, set,
362 cmdline_parse_token_string_t cmd_set_rxtx_sc_type =
363 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, type, NULL);
365 cmdline_parse_inst_t cmd_set_rxtx_sc = {
366 .f = cmd_set_rxtx_sc_parsed, /* function to call */
367 .data = NULL, /* 2nd arg of func */
368 .help_str = "set rxtx stream control: "
369 "set_rxtx_sc <type>",
370 .tokens = { /* token list, NULL terminated */
371 (void *)&cmd_set_rxtx_sc_set,
372 (void *)&cmd_set_rxtx_sc_type,
380 cmdline_parse_ctx_t main_ctx[] = {
381 (cmdline_parse_inst_t *)&cmd_autotest,
382 (cmdline_parse_inst_t *)&cmd_dump,
383 (cmdline_parse_inst_t *)&cmd_dump_one,
384 (cmdline_parse_inst_t *)&cmd_quit,
385 (cmdline_parse_inst_t *)&cmd_set_rxtx,
386 (cmdline_parse_inst_t *)&cmd_set_rxtx_anchor,
387 (cmdline_parse_inst_t *)&cmd_set_rxtx_sc,
391 int commands_init(void)
393 struct test_command *t;
394 char *commands, *ptr;
395 int commands_len = 0;
397 TAILQ_FOREACH(t, &commands_list, next) {
398 commands_len += strlen(t->command) + 1;
401 commands = malloc(commands_len + 1);
406 TAILQ_FOREACH(t, &commands_list, next) {
407 ptr += sprintf(ptr, "%s#", t->command);
412 cmd_autotest_autotest.string_data.str = commands;