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_mempool.h>
67 #include <rte_devargs.h>
69 #include <cmdline_rdline.h>
70 #include <cmdline_parse.h>
71 #include <cmdline_parse_ipaddr.h>
72 #include <cmdline_parse_num.h>
73 #include <cmdline_parse_string.h>
80 static struct test_commands_list commands_list =
81 TAILQ_HEAD_INITIALIZER(commands_list);
84 add_test_command(struct test_command *t)
86 TAILQ_INSERT_TAIL(&commands_list, t, next);
89 struct cmd_autotest_result {
90 cmdline_fixed_string_t autotest;
93 static void cmd_autotest_parsed(void *parsed_result,
94 __attribute__((unused)) struct cmdline *cl,
95 __attribute__((unused)) void *data)
97 struct test_command *t;
98 struct cmd_autotest_result *res = parsed_result;
101 TAILQ_FOREACH(t, &commands_list, next) {
102 if (!strcmp(res->autotest, t->command))
106 last_test_result = ret;
110 printf("Test Failed\n");
114 cmdline_parse_token_string_t cmd_autotest_autotest =
115 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
118 cmdline_parse_inst_t cmd_autotest = {
119 .f = cmd_autotest_parsed, /* function to call */
120 .data = NULL, /* 2nd arg of func */
121 .help_str = "launch autotest",
122 .tokens = { /* token list, NULL terminated */
123 (void *)&cmd_autotest_autotest,
130 struct cmd_dump_result {
131 cmdline_fixed_string_t dump;
135 dump_struct_sizes(void)
137 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
138 DUMP_SIZE(struct rte_mbuf);
139 DUMP_SIZE(struct rte_mempool);
140 DUMP_SIZE(struct rte_ring);
144 static void cmd_dump_parsed(void *parsed_result,
145 __attribute__((unused)) struct cmdline *cl,
146 __attribute__((unused)) void *data)
148 struct cmd_dump_result *res = parsed_result;
150 if (!strcmp(res->dump, "dump_physmem"))
151 rte_dump_physmem_layout(stdout);
152 else if (!strcmp(res->dump, "dump_memzone"))
153 rte_memzone_dump(stdout);
154 else if (!strcmp(res->dump, "dump_struct_sizes"))
156 else if (!strcmp(res->dump, "dump_ring"))
157 rte_ring_list_dump(stdout);
158 else if (!strcmp(res->dump, "dump_mempool"))
159 rte_mempool_list_dump(stdout);
160 else if (!strcmp(res->dump, "dump_devargs"))
161 rte_eal_devargs_dump(stdout);
162 else if (!strcmp(res->dump, "dump_log_types"))
163 rte_log_dump(stdout);
166 cmdline_parse_token_string_t cmd_dump_dump =
167 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
168 "dump_physmem#dump_memzone#"
169 "dump_struct_sizes#dump_ring#dump_mempool#"
170 "dump_devargs#dump_log_types");
172 cmdline_parse_inst_t cmd_dump = {
173 .f = cmd_dump_parsed, /* function to call */
174 .data = NULL, /* 2nd arg of func */
175 .help_str = "dump status",
176 .tokens = { /* token list, NULL terminated */
177 (void *)&cmd_dump_dump,
184 struct cmd_dump_one_result {
185 cmdline_fixed_string_t dump;
186 cmdline_fixed_string_t name;
189 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
190 __attribute__((unused)) void *data)
192 struct cmd_dump_one_result *res = parsed_result;
194 if (!strcmp(res->dump, "dump_ring")) {
196 r = rte_ring_lookup(res->name);
198 cmdline_printf(cl, "Cannot find ring\n");
201 rte_ring_dump(stdout, r);
203 else if (!strcmp(res->dump, "dump_mempool")) {
204 struct rte_mempool *mp;
205 mp = rte_mempool_lookup(res->name);
207 cmdline_printf(cl, "Cannot find mempool\n");
210 rte_mempool_dump(stdout, mp);
214 cmdline_parse_token_string_t cmd_dump_one_dump =
215 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
216 "dump_ring#dump_mempool");
218 cmdline_parse_token_string_t cmd_dump_one_name =
219 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
221 cmdline_parse_inst_t cmd_dump_one = {
222 .f = cmd_dump_one_parsed, /* function to call */
223 .data = NULL, /* 2nd arg of func */
224 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
225 .tokens = { /* token list, NULL terminated */
226 (void *)&cmd_dump_one_dump,
227 (void *)&cmd_dump_one_name,
234 struct cmd_quit_result {
235 cmdline_fixed_string_t quit;
239 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
241 __attribute__((unused)) void *data)
246 cmdline_parse_token_string_t cmd_quit_quit =
247 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
250 cmdline_parse_inst_t cmd_quit = {
251 .f = cmd_quit_parsed, /* function to call */
252 .data = NULL, /* 2nd arg of func */
253 .help_str = "exit application",
254 .tokens = { /* token list, NULL terminated */
255 (void *)&cmd_quit_quit,
262 struct cmd_set_rxtx_result {
263 cmdline_fixed_string_t set;
264 cmdline_fixed_string_t mode;
267 static void cmd_set_rxtx_parsed(void *parsed_result, struct cmdline *cl,
268 __attribute__((unused)) void *data)
270 struct cmd_set_rxtx_result *res = parsed_result;
271 if (test_set_rxtx_conf(res->mode) < 0)
272 cmdline_printf(cl, "Cannot find such mode\n");
275 cmdline_parse_token_string_t cmd_set_rxtx_set =
276 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, set,
279 cmdline_parse_token_string_t cmd_set_rxtx_mode =
280 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_result, mode, NULL);
282 cmdline_parse_inst_t cmd_set_rxtx = {
283 .f = cmd_set_rxtx_parsed, /* function to call */
284 .data = NULL, /* 2nd arg of func */
285 .help_str = "set rxtx routine: "
287 .tokens = { /* token list, NULL terminated */
288 (void *)&cmd_set_rxtx_set,
289 (void *)&cmd_set_rxtx_mode,
296 struct cmd_set_rxtx_anchor {
297 cmdline_fixed_string_t set;
298 cmdline_fixed_string_t type;
302 cmd_set_rxtx_anchor_parsed(void *parsed_result,
304 __attribute__((unused)) void *data)
306 struct cmd_set_rxtx_anchor *res = parsed_result;
307 if (test_set_rxtx_anchor(res->type) < 0)
308 cmdline_printf(cl, "Cannot find such anchor\n");
311 cmdline_parse_token_string_t cmd_set_rxtx_anchor_set =
312 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, set,
315 cmdline_parse_token_string_t cmd_set_rxtx_anchor_type =
316 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, type, NULL);
318 cmdline_parse_inst_t cmd_set_rxtx_anchor = {
319 .f = cmd_set_rxtx_anchor_parsed, /* function to call */
320 .data = NULL, /* 2nd arg of func */
321 .help_str = "set rxtx anchor: "
322 "set_rxtx_anchor <type>",
323 .tokens = { /* token list, NULL terminated */
324 (void *)&cmd_set_rxtx_anchor_set,
325 (void *)&cmd_set_rxtx_anchor_type,
332 /* for stream control */
333 struct cmd_set_rxtx_sc {
334 cmdline_fixed_string_t set;
335 cmdline_fixed_string_t type;
339 cmd_set_rxtx_sc_parsed(void *parsed_result,
341 __attribute__((unused)) void *data)
343 struct cmd_set_rxtx_sc *res = parsed_result;
344 if (test_set_rxtx_sc(res->type) < 0)
345 cmdline_printf(cl, "Cannot find such stream control\n");
348 cmdline_parse_token_string_t cmd_set_rxtx_sc_set =
349 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, set,
352 cmdline_parse_token_string_t cmd_set_rxtx_sc_type =
353 TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_sc, type, NULL);
355 cmdline_parse_inst_t cmd_set_rxtx_sc = {
356 .f = cmd_set_rxtx_sc_parsed, /* function to call */
357 .data = NULL, /* 2nd arg of func */
358 .help_str = "set rxtx stream control: "
359 "set_rxtx_sc <type>",
360 .tokens = { /* token list, NULL terminated */
361 (void *)&cmd_set_rxtx_sc_set,
362 (void *)&cmd_set_rxtx_sc_type,
370 cmdline_parse_ctx_t main_ctx[] = {
371 (cmdline_parse_inst_t *)&cmd_autotest,
372 (cmdline_parse_inst_t *)&cmd_dump,
373 (cmdline_parse_inst_t *)&cmd_dump_one,
374 (cmdline_parse_inst_t *)&cmd_quit,
375 (cmdline_parse_inst_t *)&cmd_set_rxtx,
376 (cmdline_parse_inst_t *)&cmd_set_rxtx_anchor,
377 (cmdline_parse_inst_t *)&cmd_set_rxtx_sc,
381 int commands_init(void)
383 struct test_command *t;
384 char *commands, *ptr;
385 int commands_len = 0;
387 TAILQ_FOREACH(t, &commands_list, next) {
388 commands_len += strlen(t->command) + 1;
391 commands = malloc(commands_len + 1);
396 TAILQ_FOREACH(t, &commands_list, next) {
397 ptr += sprintf(ptr, "%s#", t->command);
402 cmd_autotest_autotest.string_data.str = commands;