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.
33 * version: DPDK.L.1.2.3-3
41 #include <netinet/in.h>
44 #include <net/socket.h>
48 #include <sys/queue.h>
50 #include <rte_common.h>
52 #include <rte_debug.h>
53 #include <rte_memory.h>
54 #include <rte_memcpy.h>
55 #include <rte_memzone.h>
56 #include <rte_launch.h>
57 #include <rte_cycles.h>
58 #include <rte_tailq.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_timer.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 struct cmd_autotest_result {
81 cmdline_fixed_string_t autotest;
84 static void cmd_autotest_parsed(void *parsed_result,
85 __attribute__((unused)) struct cmdline *cl,
86 __attribute__((unused)) void *data)
88 struct cmd_autotest_result *res = parsed_result;
92 if (!strcmp(res->autotest, "all_autotests"))
95 if (all || !strcmp(res->autotest, "version_autotest"))
96 ret |= test_version();
97 if (all || !strcmp(res->autotest, "debug_autotest"))
99 if (all || !strcmp(res->autotest, "pci_autotest"))
101 if (all || !strcmp(res->autotest, "prefetch_autotest"))
102 ret |= test_prefetch();
103 if (all || !strcmp(res->autotest, "byteorder_autotest"))
104 ret |= test_byteorder();
105 if (all || !strcmp(res->autotest, "per_lcore_autotest"))
106 ret |= test_per_lcore();
107 if (all || !strcmp(res->autotest, "atomic_autotest"))
108 ret |= test_atomic();
109 if (all || !strcmp(res->autotest, "malloc_autotest"))
110 ret |= test_malloc();
111 if (all || !strcmp(res->autotest, "spinlock_autotest"))
112 ret |= test_spinlock();
113 if (all || !strcmp(res->autotest, "memory_autotest"))
114 ret |= test_memory();
115 if (all || !strcmp(res->autotest, "memzone_autotest"))
116 ret |= test_memzone();
117 if (all || !strcmp(res->autotest, "rwlock_autotest"))
118 ret |= test_rwlock();
119 if (all || !strcmp(res->autotest, "mbuf_autotest"))
121 if (all || !strcmp(res->autotest, "logs_autotest"))
123 if (all || !strcmp(res->autotest, "errno_autotest"))
125 if (all || !strcmp(res->autotest, "hash_autotest"))
127 if (all || !strcmp(res->autotest, "lpm_autotest"))
129 if (all || !strcmp(res->autotest, "cpuflags_autotest"))
130 ret |= test_cpuflags();
131 /* tailq autotest must go after all lpm and hashs tests or any other
132 * tests which need to create tailq objects (ring and mempool are implicitly
133 * created in earlier tests so can go later)
135 if (all || !strcmp(res->autotest, "tailq_autotest"))
137 if (all || !strcmp(res->autotest, "multiprocess_autotest"))
138 ret |= test_mp_secondary();
139 if (all || !strcmp(res->autotest, "memcpy_autotest"))
140 ret |= test_memcpy();
141 if (all || !strcmp(res->autotest, "string_autotest"))
142 ret |= test_string_fns();
143 if (all || !strcmp(res->autotest, "eal_flags_autotest"))
144 ret |= test_eal_flags();
145 if (all || !strcmp(res->autotest, "alarm_autotest"))
147 if (all || !strcmp(res->autotest, "interrupt_autotest"))
148 ret |= test_interrupt();
149 if (all || !strcmp(res->autotest, "cycles_autotest"))
150 ret |= test_cycles();
151 if (all || !strcmp(res->autotest, "ring_autotest"))
153 if (all || !strcmp(res->autotest, "timer_autotest"))
155 if (all || !strcmp(res->autotest, "mempool_autotest"))
156 ret |= test_mempool();
161 printf("Test Failed\n");
165 cmdline_parse_token_string_t cmd_autotest_autotest =
166 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
167 "pci_autotest#memory_autotest#"
168 "per_lcore_autotest#spinlock_autotest#"
169 "rwlock_autotest#atomic_autotest#"
170 "byteorder_autotest#prefetch_autotest#"
171 "cycles_autotest#logs_autotest#"
172 "memzone_autotest#ring_autotest#"
173 "mempool_autotest#mbuf_autotest#"
174 "timer_autotest#malloc_autotest#"
175 "memcpy_autotest#hash_autotest#"
176 "lpm_autotest#debug_autotest#"
177 "errno_autotest#tailq_autotest#"
178 "string_autotest#multiprocess_autotest#"
179 "cpuflags_autotest#eal_flags_autotest#"
180 "alarm_autotest#interrupt_autotest#"
184 cmdline_parse_inst_t cmd_autotest = {
185 .f = cmd_autotest_parsed, /* function to call */
186 .data = NULL, /* 2nd arg of func */
187 .help_str = "launch autotest",
188 .tokens = { /* token list, NULL terminated */
189 (void *)&cmd_autotest_autotest,
196 struct cmd_dump_result {
197 cmdline_fixed_string_t dump;
201 dump_struct_sizes(void)
203 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
204 DUMP_SIZE(struct rte_mbuf);
205 DUMP_SIZE(struct rte_pktmbuf);
206 DUMP_SIZE(struct rte_ctrlmbuf);
207 DUMP_SIZE(struct rte_mempool);
208 DUMP_SIZE(struct rte_ring);
212 static void cmd_dump_parsed(void *parsed_result,
213 __attribute__((unused)) struct cmdline *cl,
214 __attribute__((unused)) void *data)
216 struct cmd_dump_result *res = parsed_result;
218 if (!strcmp(res->dump, "dump_physmem"))
219 rte_dump_physmem_layout();
220 else if (!strcmp(res->dump, "dump_memzone"))
222 else if (!strcmp(res->dump, "dump_log_history"))
223 rte_log_dump_history();
224 else if (!strcmp(res->dump, "dump_struct_sizes"))
226 else if (!strcmp(res->dump, "dump_ring"))
227 rte_ring_list_dump();
228 else if (!strcmp(res->dump, "dump_mempool"))
229 rte_mempool_list_dump();
232 cmdline_parse_token_string_t cmd_dump_dump =
233 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
234 "dump_physmem#dump_memzone#dump_log_history#"
235 "dump_struct_sizes#dump_ring#dump_mempool");
237 cmdline_parse_inst_t cmd_dump = {
238 .f = cmd_dump_parsed, /* function to call */
239 .data = NULL, /* 2nd arg of func */
240 .help_str = "dump status",
241 .tokens = { /* token list, NULL terminated */
242 (void *)&cmd_dump_dump,
249 struct cmd_dump_one_result {
250 cmdline_fixed_string_t dump;
251 cmdline_fixed_string_t name;
254 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
255 __attribute__((unused)) void *data)
257 struct cmd_dump_one_result *res = parsed_result;
259 if (!strcmp(res->dump, "dump_ring")) {
261 r = rte_ring_lookup(res->name);
263 cmdline_printf(cl, "Cannot find ring\n");
268 else if (!strcmp(res->dump, "dump_mempool")) {
269 struct rte_mempool *mp;
270 mp = rte_mempool_lookup(res->name);
272 cmdline_printf(cl, "Cannot find mempool\n");
275 rte_mempool_dump(mp);
279 cmdline_parse_token_string_t cmd_dump_one_dump =
280 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
281 "dump_ring#dump_mempool");
283 cmdline_parse_token_string_t cmd_dump_one_name =
284 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
286 cmdline_parse_inst_t cmd_dump_one = {
287 .f = cmd_dump_one_parsed, /* function to call */
288 .data = NULL, /* 2nd arg of func */
289 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
290 .tokens = { /* token list, NULL terminated */
291 (void *)&cmd_dump_one_dump,
292 (void *)&cmd_dump_one_name,
299 struct cmd_set_ring_result {
300 cmdline_fixed_string_t set;
301 cmdline_fixed_string_t name;
305 static void cmd_set_ring_parsed(void *parsed_result, struct cmdline *cl,
306 __attribute__((unused)) void *data)
308 struct cmd_set_ring_result *res = parsed_result;
312 r = rte_ring_lookup(res->name);
314 cmdline_printf(cl, "Cannot find ring\n");
318 if (!strcmp(res->set, "set_quota")) {
319 ret = rte_ring_set_bulk_count(r, res->value);
321 cmdline_printf(cl, "Cannot set quota\n");
323 else if (!strcmp(res->set, "set_watermark")) {
324 ret = rte_ring_set_water_mark(r, res->value);
326 cmdline_printf(cl, "Cannot set water mark\n");
330 cmdline_parse_token_string_t cmd_set_ring_set =
331 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, set,
332 "set_quota#set_watermark");
334 cmdline_parse_token_string_t cmd_set_ring_name =
335 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, name, NULL);
337 cmdline_parse_token_num_t cmd_set_ring_value =
338 TOKEN_NUM_INITIALIZER(struct cmd_set_ring_result, value, UINT32);
340 cmdline_parse_inst_t cmd_set_ring = {
341 .f = cmd_set_ring_parsed, /* function to call */
342 .data = NULL, /* 2nd arg of func */
343 .help_str = "set quota/watermark: "
344 "set_quota|set_watermark <ring_name> <value>",
345 .tokens = { /* token list, NULL terminated */
346 (void *)&cmd_set_ring_set,
347 (void *)&cmd_set_ring_name,
348 (void *)&cmd_set_ring_value,
355 struct cmd_quit_result {
356 cmdline_fixed_string_t quit;
360 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
362 __attribute__((unused)) void *data)
367 cmdline_parse_token_string_t cmd_quit_quit =
368 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
371 cmdline_parse_inst_t cmd_quit = {
372 .f = cmd_quit_parsed, /* function to call */
373 .data = NULL, /* 2nd arg of func */
374 .help_str = "exit application",
375 .tokens = { /* token list, NULL terminated */
376 (void *)&cmd_quit_quit,
383 cmdline_parse_ctx_t main_ctx[] = {
384 (cmdline_parse_inst_t *)&cmd_autotest,
385 (cmdline_parse_inst_t *)&cmd_dump,
386 (cmdline_parse_inst_t *)&cmd_dump_one,
387 (cmdline_parse_inst_t *)&cmd_set_ring,
388 (cmdline_parse_inst_t *)&cmd_quit,