4 * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <netinet/in.h>
43 #include <net/socket.h>
47 #include <sys/queue.h>
49 #include <rte_common.h>
51 #include <rte_debug.h>
52 #include <rte_memory.h>
53 #include <rte_memcpy.h>
54 #include <rte_memzone.h>
55 #include <rte_launch.h>
56 #include <rte_cycles.h>
57 #include <rte_tailq.h>
59 #include <rte_per_lcore.h>
60 #include <rte_lcore.h>
61 #include <rte_atomic.h>
62 #include <rte_branch_prediction.h>
64 #include <rte_mempool.h>
66 #include <rte_timer.h>
68 #include <cmdline_rdline.h>
69 #include <cmdline_parse.h>
70 #include <cmdline_parse_ipaddr.h>
71 #include <cmdline_parse_num.h>
72 #include <cmdline_parse_string.h>
79 struct cmd_autotest_result {
80 cmdline_fixed_string_t autotest;
83 static void cmd_autotest_parsed(void *parsed_result,
84 __attribute__((unused)) struct cmdline *cl,
85 __attribute__((unused)) void *data)
87 struct cmd_autotest_result *res = parsed_result;
91 if (!strcmp(res->autotest, "all_autotests"))
94 if (all || !strcmp(res->autotest, "version_autotest"))
95 ret |= test_version();
96 if (all || !strcmp(res->autotest, "eal_fs_autotest"))
98 if (all || !strcmp(res->autotest, "debug_autotest"))
100 if (all || !strcmp(res->autotest, "pci_autotest"))
102 if (all || !strcmp(res->autotest, "prefetch_autotest"))
103 ret |= test_prefetch();
104 if (all || !strcmp(res->autotest, "byteorder_autotest"))
105 ret |= test_byteorder();
106 if (all || !strcmp(res->autotest, "per_lcore_autotest"))
107 ret |= test_per_lcore();
108 if (all || !strcmp(res->autotest, "atomic_autotest"))
109 ret |= test_atomic();
110 if (all || !strcmp(res->autotest, "malloc_autotest"))
111 ret |= test_malloc();
112 if (all || !strcmp(res->autotest, "spinlock_autotest"))
113 ret |= test_spinlock();
114 if (all || !strcmp(res->autotest, "memory_autotest"))
115 ret |= test_memory();
116 if (all || !strcmp(res->autotest, "memzone_autotest"))
117 ret |= test_memzone();
118 if (all || !strcmp(res->autotest, "rwlock_autotest"))
119 ret |= test_rwlock();
120 if (all || !strcmp(res->autotest, "mbuf_autotest"))
122 if (all || !strcmp(res->autotest, "logs_autotest"))
124 if (all || !strcmp(res->autotest, "errno_autotest"))
126 if (all || !strcmp(res->autotest, "hash_autotest"))
128 if (all || !strcmp(res->autotest, "lpm_autotest"))
130 if (all || !strcmp(res->autotest, "cpuflags_autotest"))
131 ret |= test_cpuflags();
132 if (all || !strcmp(res->autotest, "cmdline_autotest"))
133 ret |= test_cmdline();
134 /* tailq autotest must go after all lpm and hashs tests or any other
135 * tests which need to create tailq objects (ring and mempool are implicitly
136 * created in earlier tests so can go later)
138 if (all || !strcmp(res->autotest, "tailq_autotest"))
140 if (all || !strcmp(res->autotest, "multiprocess_autotest"))
141 ret |= test_mp_secondary();
142 if (all || !strcmp(res->autotest, "memcpy_autotest"))
143 ret |= test_memcpy();
144 if (all || !strcmp(res->autotest, "string_autotest"))
145 ret |= test_string_fns();
146 if (all || !strcmp(res->autotest, "eal_flags_autotest"))
147 ret |= test_eal_flags();
148 if (all || !strcmp(res->autotest, "alarm_autotest"))
150 if (all || !strcmp(res->autotest, "interrupt_autotest"))
151 ret |= test_interrupt();
152 if (all || !strcmp(res->autotest, "cycles_autotest"))
153 ret |= test_cycles();
154 if (all || !strcmp(res->autotest, "ring_autotest"))
156 if (all || !strcmp(res->autotest, "timer_autotest"))
158 if (all || !strcmp(res->autotest, "mempool_autotest"))
159 ret |= test_mempool();
164 printf("Test Failed\n");
168 cmdline_parse_token_string_t cmd_autotest_autotest =
169 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
170 "pci_autotest#memory_autotest#"
171 "per_lcore_autotest#spinlock_autotest#"
172 "rwlock_autotest#atomic_autotest#"
173 "byteorder_autotest#prefetch_autotest#"
174 "cycles_autotest#logs_autotest#"
175 "memzone_autotest#ring_autotest#"
176 "mempool_autotest#mbuf_autotest#"
177 "timer_autotest#malloc_autotest#"
178 "memcpy_autotest#hash_autotest#"
179 "lpm_autotest#debug_autotest#"
180 "errno_autotest#tailq_autotest#"
181 "string_autotest#multiprocess_autotest#"
182 "cpuflags_autotest#eal_flags_autotest#"
183 "alarm_autotest#interrupt_autotest#"
184 "version_autotest#eal_fs_autotest#"
188 cmdline_parse_inst_t cmd_autotest = {
189 .f = cmd_autotest_parsed, /* function to call */
190 .data = NULL, /* 2nd arg of func */
191 .help_str = "launch autotest",
192 .tokens = { /* token list, NULL terminated */
193 (void *)&cmd_autotest_autotest,
200 struct cmd_dump_result {
201 cmdline_fixed_string_t dump;
205 dump_struct_sizes(void)
207 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
208 DUMP_SIZE(struct rte_mbuf);
209 DUMP_SIZE(struct rte_pktmbuf);
210 DUMP_SIZE(struct rte_ctrlmbuf);
211 DUMP_SIZE(struct rte_mempool);
212 DUMP_SIZE(struct rte_ring);
216 static void cmd_dump_parsed(void *parsed_result,
217 __attribute__((unused)) struct cmdline *cl,
218 __attribute__((unused)) void *data)
220 struct cmd_dump_result *res = parsed_result;
222 if (!strcmp(res->dump, "dump_physmem"))
223 rte_dump_physmem_layout();
224 else if (!strcmp(res->dump, "dump_memzone"))
226 else if (!strcmp(res->dump, "dump_log_history"))
227 rte_log_dump_history();
228 else if (!strcmp(res->dump, "dump_struct_sizes"))
230 else if (!strcmp(res->dump, "dump_ring"))
231 rte_ring_list_dump();
232 else if (!strcmp(res->dump, "dump_mempool"))
233 rte_mempool_list_dump();
236 cmdline_parse_token_string_t cmd_dump_dump =
237 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
238 "dump_physmem#dump_memzone#dump_log_history#"
239 "dump_struct_sizes#dump_ring#dump_mempool");
241 cmdline_parse_inst_t cmd_dump = {
242 .f = cmd_dump_parsed, /* function to call */
243 .data = NULL, /* 2nd arg of func */
244 .help_str = "dump status",
245 .tokens = { /* token list, NULL terminated */
246 (void *)&cmd_dump_dump,
253 struct cmd_dump_one_result {
254 cmdline_fixed_string_t dump;
255 cmdline_fixed_string_t name;
258 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
259 __attribute__((unused)) void *data)
261 struct cmd_dump_one_result *res = parsed_result;
263 if (!strcmp(res->dump, "dump_ring")) {
265 r = rte_ring_lookup(res->name);
267 cmdline_printf(cl, "Cannot find ring\n");
272 else if (!strcmp(res->dump, "dump_mempool")) {
273 struct rte_mempool *mp;
274 mp = rte_mempool_lookup(res->name);
276 cmdline_printf(cl, "Cannot find mempool\n");
279 rte_mempool_dump(mp);
283 cmdline_parse_token_string_t cmd_dump_one_dump =
284 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
285 "dump_ring#dump_mempool");
287 cmdline_parse_token_string_t cmd_dump_one_name =
288 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
290 cmdline_parse_inst_t cmd_dump_one = {
291 .f = cmd_dump_one_parsed, /* function to call */
292 .data = NULL, /* 2nd arg of func */
293 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
294 .tokens = { /* token list, NULL terminated */
295 (void *)&cmd_dump_one_dump,
296 (void *)&cmd_dump_one_name,
303 struct cmd_set_ring_result {
304 cmdline_fixed_string_t set;
305 cmdline_fixed_string_t name;
309 static void cmd_set_ring_parsed(void *parsed_result, struct cmdline *cl,
310 __attribute__((unused)) void *data)
312 struct cmd_set_ring_result *res = parsed_result;
316 r = rte_ring_lookup(res->name);
318 cmdline_printf(cl, "Cannot find ring\n");
322 if (!strcmp(res->set, "set_quota")) {
323 ret = rte_ring_set_bulk_count(r, res->value);
325 cmdline_printf(cl, "Cannot set quota\n");
327 else if (!strcmp(res->set, "set_watermark")) {
328 ret = rte_ring_set_water_mark(r, res->value);
330 cmdline_printf(cl, "Cannot set water mark\n");
334 cmdline_parse_token_string_t cmd_set_ring_set =
335 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, set,
336 "set_quota#set_watermark");
338 cmdline_parse_token_string_t cmd_set_ring_name =
339 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, name, NULL);
341 cmdline_parse_token_num_t cmd_set_ring_value =
342 TOKEN_NUM_INITIALIZER(struct cmd_set_ring_result, value, UINT32);
344 cmdline_parse_inst_t cmd_set_ring = {
345 .f = cmd_set_ring_parsed, /* function to call */
346 .data = NULL, /* 2nd arg of func */
347 .help_str = "set quota/watermark: "
348 "set_quota|set_watermark <ring_name> <value>",
349 .tokens = { /* token list, NULL terminated */
350 (void *)&cmd_set_ring_set,
351 (void *)&cmd_set_ring_name,
352 (void *)&cmd_set_ring_value,
359 struct cmd_quit_result {
360 cmdline_fixed_string_t quit;
364 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
366 __attribute__((unused)) void *data)
371 cmdline_parse_token_string_t cmd_quit_quit =
372 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
375 cmdline_parse_inst_t cmd_quit = {
376 .f = cmd_quit_parsed, /* function to call */
377 .data = NULL, /* 2nd arg of func */
378 .help_str = "exit application",
379 .tokens = { /* token list, NULL terminated */
380 (void *)&cmd_quit_quit,
387 cmdline_parse_ctx_t main_ctx[] = {
388 (cmdline_parse_inst_t *)&cmd_autotest,
389 (cmdline_parse_inst_t *)&cmd_dump,
390 (cmdline_parse_inst_t *)&cmd_dump_one,
391 (cmdline_parse_inst_t *)&cmd_set_ring,
392 (cmdline_parse_inst_t *)&cmd_quit,