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>
59 #include <rte_tailq.h>
61 #include <rte_per_lcore.h>
62 #include <rte_lcore.h>
63 #include <rte_atomic.h>
64 #include <rte_branch_prediction.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))
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_pktmbuf);
140 DUMP_SIZE(struct rte_ctrlmbuf);
141 DUMP_SIZE(struct rte_mempool);
142 DUMP_SIZE(struct rte_ring);
146 static void cmd_dump_parsed(void *parsed_result,
147 __attribute__((unused)) struct cmdline *cl,
148 __attribute__((unused)) void *data)
150 struct cmd_dump_result *res = parsed_result;
152 if (!strcmp(res->dump, "dump_physmem"))
153 rte_dump_physmem_layout(stdout);
154 else if (!strcmp(res->dump, "dump_memzone"))
155 rte_memzone_dump(stdout);
156 else if (!strcmp(res->dump, "dump_log_history"))
157 rte_log_dump_history(stdout);
158 else if (!strcmp(res->dump, "dump_struct_sizes"))
160 else if (!strcmp(res->dump, "dump_ring"))
161 rte_ring_list_dump(stdout);
162 else if (!strcmp(res->dump, "dump_mempool"))
163 rte_mempool_list_dump(stdout);
164 else if (!strcmp(res->dump, "dump_devargs"))
165 rte_eal_devargs_dump(stdout);
168 cmdline_parse_token_string_t cmd_dump_dump =
169 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
170 "dump_physmem#dump_memzone#dump_log_history#"
171 "dump_struct_sizes#dump_ring#dump_mempool#"
174 cmdline_parse_inst_t cmd_dump = {
175 .f = cmd_dump_parsed, /* function to call */
176 .data = NULL, /* 2nd arg of func */
177 .help_str = "dump status",
178 .tokens = { /* token list, NULL terminated */
179 (void *)&cmd_dump_dump,
186 struct cmd_dump_one_result {
187 cmdline_fixed_string_t dump;
188 cmdline_fixed_string_t name;
191 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
192 __attribute__((unused)) void *data)
194 struct cmd_dump_one_result *res = parsed_result;
196 if (!strcmp(res->dump, "dump_ring")) {
198 r = rte_ring_lookup(res->name);
200 cmdline_printf(cl, "Cannot find ring\n");
203 rte_ring_dump(stdout, r);
205 else if (!strcmp(res->dump, "dump_mempool")) {
206 struct rte_mempool *mp;
207 mp = rte_mempool_lookup(res->name);
209 cmdline_printf(cl, "Cannot find mempool\n");
212 rte_mempool_dump(stdout, mp);
216 cmdline_parse_token_string_t cmd_dump_one_dump =
217 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
218 "dump_ring#dump_mempool");
220 cmdline_parse_token_string_t cmd_dump_one_name =
221 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
223 cmdline_parse_inst_t cmd_dump_one = {
224 .f = cmd_dump_one_parsed, /* function to call */
225 .data = NULL, /* 2nd arg of func */
226 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
227 .tokens = { /* token list, NULL terminated */
228 (void *)&cmd_dump_one_dump,
229 (void *)&cmd_dump_one_name,
236 struct cmd_set_ring_result {
237 cmdline_fixed_string_t set;
238 cmdline_fixed_string_t name;
242 static void cmd_set_ring_parsed(void *parsed_result, struct cmdline *cl,
243 __attribute__((unused)) void *data)
245 struct cmd_set_ring_result *res = parsed_result;
249 r = rte_ring_lookup(res->name);
251 cmdline_printf(cl, "Cannot find ring\n");
255 if (!strcmp(res->set, "set_watermark")) {
256 ret = rte_ring_set_water_mark(r, res->value);
258 cmdline_printf(cl, "Cannot set water mark\n");
262 cmdline_parse_token_string_t cmd_set_ring_set =
263 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, set,
266 cmdline_parse_token_string_t cmd_set_ring_name =
267 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, name, NULL);
269 cmdline_parse_token_num_t cmd_set_ring_value =
270 TOKEN_NUM_INITIALIZER(struct cmd_set_ring_result, value, UINT32);
272 cmdline_parse_inst_t cmd_set_ring = {
273 .f = cmd_set_ring_parsed, /* function to call */
274 .data = NULL, /* 2nd arg of func */
275 .help_str = "set watermark: "
276 "set_watermark <ring_name> <value>",
277 .tokens = { /* token list, NULL terminated */
278 (void *)&cmd_set_ring_set,
279 (void *)&cmd_set_ring_name,
280 (void *)&cmd_set_ring_value,
287 struct cmd_quit_result {
288 cmdline_fixed_string_t quit;
292 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
294 __attribute__((unused)) void *data)
299 cmdline_parse_token_string_t cmd_quit_quit =
300 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
303 cmdline_parse_inst_t cmd_quit = {
304 .f = cmd_quit_parsed, /* function to call */
305 .data = NULL, /* 2nd arg of func */
306 .help_str = "exit application",
307 .tokens = { /* token list, NULL terminated */
308 (void *)&cmd_quit_quit,
315 cmdline_parse_ctx_t main_ctx[] = {
316 (cmdline_parse_inst_t *)&cmd_autotest,
317 (cmdline_parse_inst_t *)&cmd_dump,
318 (cmdline_parse_inst_t *)&cmd_dump_one,
319 (cmdline_parse_inst_t *)&cmd_set_ring,
320 (cmdline_parse_inst_t *)&cmd_quit,
324 int commands_init(void)
326 struct test_command *t;
327 char *commands, *ptr;
328 int commands_len = 0;
330 TAILQ_FOREACH(t, &commands_list, next) {
331 commands_len += strlen(t->command) + 1;
334 commands = malloc(commands_len);
339 TAILQ_FOREACH(t, &commands_list, next) {
340 ptr += sprintf(ptr, "%s#", t->command);
345 cmd_autotest_autotest.string_data.str = commands;