4 * Copyright(c) 2010-2014 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.
39 #include <netinet/in.h>
43 #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, "eal_fs_autotest"))
99 if (all || !strcmp(res->autotest, "debug_autotest"))
101 if (all || !strcmp(res->autotest, "pci_autotest"))
103 if (all || !strcmp(res->autotest, "prefetch_autotest"))
104 ret |= test_prefetch();
105 if (all || !strcmp(res->autotest, "byteorder_autotest"))
106 ret |= test_byteorder();
107 if (all || !strcmp(res->autotest, "per_lcore_autotest"))
108 ret |= test_per_lcore();
109 if (all || !strcmp(res->autotest, "atomic_autotest"))
110 ret |= test_atomic();
111 if (all || !strcmp(res->autotest, "malloc_autotest"))
112 ret |= test_malloc();
113 if (all || !strcmp(res->autotest, "spinlock_autotest"))
114 ret |= test_spinlock();
115 if (all || !strcmp(res->autotest, "memory_autotest"))
116 ret |= test_memory();
117 if (all || !strcmp(res->autotest, "memzone_autotest"))
118 ret |= test_memzone();
119 if (all || !strcmp(res->autotest, "rwlock_autotest"))
120 ret |= test_rwlock();
121 if (all || !strcmp(res->autotest, "mbuf_autotest"))
123 if (all || !strcmp(res->autotest, "logs_autotest"))
125 if (all || !strcmp(res->autotest, "errno_autotest"))
127 if (all || !strcmp(res->autotest, "hash_autotest"))
129 if (all || !strcmp(res->autotest, "hash_perf_autotest"))
130 ret |= test_hash_perf();
131 if (all || !strcmp(res->autotest, "lpm_autotest"))
133 if (all || !strcmp(res->autotest, "lpm6_autotest"))
135 if (all || !strcmp(res->autotest, "cpuflags_autotest"))
136 ret |= test_cpuflags();
137 if (all || !strcmp(res->autotest, "cmdline_autotest"))
138 ret |= test_cmdline();
139 /* tailq autotest must go after all lpm and hashs tests or any other
140 * tests which need to create tailq objects (ring and mempool are implicitly
141 * created in earlier tests so can go later)
143 if (all || !strcmp(res->autotest, "tailq_autotest"))
145 if (all || !strcmp(res->autotest, "multiprocess_autotest"))
146 ret |= test_mp_secondary();
147 if (all || !strcmp(res->autotest, "memcpy_autotest"))
148 ret |= test_memcpy();
149 if (all || !strcmp(res->autotest, "string_autotest"))
150 ret |= test_string_fns();
151 if (all || !strcmp(res->autotest, "eal_flags_autotest"))
152 ret |= test_eal_flags();
153 if (all || !strcmp(res->autotest, "alarm_autotest"))
155 if (all || !strcmp(res->autotest, "interrupt_autotest"))
156 ret |= test_interrupt();
157 if (all || !strcmp(res->autotest, "cycles_autotest"))
158 ret |= test_cycles();
159 if (all || !strcmp(res->autotest, "ring_autotest"))
161 if (all || !strcmp(res->autotest, "ring_perf_autotest"))
162 ret |= test_ring_perf();
163 if (all || !strcmp(res->autotest, "timer_autotest"))
165 if (all || !strcmp(res->autotest, "timer_perf_autotest"))
166 ret |= test_timer_perf();
167 if (all || !strcmp(res->autotest, "mempool_autotest"))
168 ret |= test_mempool();
169 if (all || !strcmp(res->autotest, "mempool_perf_autotest"))
170 ret |= test_mempool_perf();
171 if (all || !strcmp(res->autotest, "memcpy_perf_autotest"))
172 ret |= test_memcpy_perf();
173 if (all || !strcmp(res->autotest, "func_reentrancy_autotest"))
174 ret |= test_func_reentrancy();
175 if (all || !strcmp(res->autotest, "red_autotest"))
177 if (all || !strcmp(res->autotest, "sched_autotest"))
179 if (all || !strcmp(res->autotest, "meter_autotest"))
181 if (all || !strcmp(res->autotest, "kni_autotest"))
183 if (all || !strcmp(res->autotest, "power_autotest"))
185 if (all || !strcmp(res->autotest, "common_autotest"))
186 ret |= test_common();
187 if (all || !strcmp(res->autotest, "ivshmem_autotest"))
188 ret = test_ivshmem();
189 #ifdef RTE_LIBRTE_PMD_RING
190 if (all || !strcmp(res->autotest, "ring_pmd_autotest"))
191 ret |= test_pmd_ring();
192 #endif /* RTE_LIBRTE_PMD_RING */
194 #ifdef RTE_LIBRTE_ACL
195 if (all || !strcmp(res->autotest, "acl_autotest"))
197 #endif /* RTE_LIBRTE_ACL */
202 printf("Test Failed\n");
206 cmdline_parse_token_string_t cmd_autotest_autotest =
207 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
208 "pci_autotest#memory_autotest#"
209 "per_lcore_autotest#spinlock_autotest#"
210 "rwlock_autotest#atomic_autotest#"
211 "byteorder_autotest#prefetch_autotest#"
212 "cycles_autotest#logs_autotest#"
213 "memzone_autotest#ring_autotest#"
214 "mempool_autotest#mbuf_autotest#"
215 "timer_autotest#malloc_autotest#"
216 "memcpy_autotest#hash_autotest#"
217 "lpm_autotest#debug_autotest#"
218 "lpm6_autotest#debug_autotest#"
219 "errno_autotest#tailq_autotest#"
220 "string_autotest#multiprocess_autotest#"
221 "cpuflags_autotest#eal_flags_autotest#"
222 "alarm_autotest#interrupt_autotest#"
223 "version_autotest#eal_fs_autotest#"
224 "cmdline_autotest#func_reentrancy_autotest#"
225 "mempool_perf_autotest#hash_perf_autotest#"
226 "memcpy_perf_autotest#ring_perf_autotest#"
227 "red_autotest#meter_autotest#sched_autotest#"
228 "memcpy_perf_autotest#kni_autotest#"
229 "pm_autotest#ivshmem_autotest#"
230 #ifdef RTE_LIBRTE_ACL
234 "timer_perf_autotest#"
235 #ifdef RTE_LIBRTE_PMD_RING
238 "common_autotest#all_autotests");
240 cmdline_parse_inst_t cmd_autotest = {
241 .f = cmd_autotest_parsed, /* function to call */
242 .data = NULL, /* 2nd arg of func */
243 .help_str = "launch autotest",
244 .tokens = { /* token list, NULL terminated */
245 (void *)&cmd_autotest_autotest,
252 struct cmd_dump_result {
253 cmdline_fixed_string_t dump;
257 dump_struct_sizes(void)
259 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
260 DUMP_SIZE(struct rte_mbuf);
261 DUMP_SIZE(struct rte_pktmbuf);
262 DUMP_SIZE(struct rte_ctrlmbuf);
263 DUMP_SIZE(struct rte_mempool);
264 DUMP_SIZE(struct rte_ring);
268 static void cmd_dump_parsed(void *parsed_result,
269 __attribute__((unused)) struct cmdline *cl,
270 __attribute__((unused)) void *data)
272 struct cmd_dump_result *res = parsed_result;
274 if (!strcmp(res->dump, "dump_physmem"))
275 rte_dump_physmem_layout();
276 else if (!strcmp(res->dump, "dump_memzone"))
278 else if (!strcmp(res->dump, "dump_log_history"))
279 rte_log_dump_history();
280 else if (!strcmp(res->dump, "dump_struct_sizes"))
282 else if (!strcmp(res->dump, "dump_ring"))
283 rte_ring_list_dump();
284 else if (!strcmp(res->dump, "dump_mempool"))
285 rte_mempool_list_dump();
288 cmdline_parse_token_string_t cmd_dump_dump =
289 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
290 "dump_physmem#dump_memzone#dump_log_history#"
291 "dump_struct_sizes#dump_ring#dump_mempool");
293 cmdline_parse_inst_t cmd_dump = {
294 .f = cmd_dump_parsed, /* function to call */
295 .data = NULL, /* 2nd arg of func */
296 .help_str = "dump status",
297 .tokens = { /* token list, NULL terminated */
298 (void *)&cmd_dump_dump,
305 struct cmd_dump_one_result {
306 cmdline_fixed_string_t dump;
307 cmdline_fixed_string_t name;
310 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
311 __attribute__((unused)) void *data)
313 struct cmd_dump_one_result *res = parsed_result;
315 if (!strcmp(res->dump, "dump_ring")) {
317 r = rte_ring_lookup(res->name);
319 cmdline_printf(cl, "Cannot find ring\n");
324 else if (!strcmp(res->dump, "dump_mempool")) {
325 struct rte_mempool *mp;
326 mp = rte_mempool_lookup(res->name);
328 cmdline_printf(cl, "Cannot find mempool\n");
331 rte_mempool_dump(mp);
335 cmdline_parse_token_string_t cmd_dump_one_dump =
336 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
337 "dump_ring#dump_mempool");
339 cmdline_parse_token_string_t cmd_dump_one_name =
340 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
342 cmdline_parse_inst_t cmd_dump_one = {
343 .f = cmd_dump_one_parsed, /* function to call */
344 .data = NULL, /* 2nd arg of func */
345 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
346 .tokens = { /* token list, NULL terminated */
347 (void *)&cmd_dump_one_dump,
348 (void *)&cmd_dump_one_name,
355 struct cmd_set_ring_result {
356 cmdline_fixed_string_t set;
357 cmdline_fixed_string_t name;
361 static void cmd_set_ring_parsed(void *parsed_result, struct cmdline *cl,
362 __attribute__((unused)) void *data)
364 struct cmd_set_ring_result *res = parsed_result;
368 r = rte_ring_lookup(res->name);
370 cmdline_printf(cl, "Cannot find ring\n");
374 if (!strcmp(res->set, "set_watermark")) {
375 ret = rte_ring_set_water_mark(r, res->value);
377 cmdline_printf(cl, "Cannot set water mark\n");
381 cmdline_parse_token_string_t cmd_set_ring_set =
382 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, set,
385 cmdline_parse_token_string_t cmd_set_ring_name =
386 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, name, NULL);
388 cmdline_parse_token_num_t cmd_set_ring_value =
389 TOKEN_NUM_INITIALIZER(struct cmd_set_ring_result, value, UINT32);
391 cmdline_parse_inst_t cmd_set_ring = {
392 .f = cmd_set_ring_parsed, /* function to call */
393 .data = NULL, /* 2nd arg of func */
394 .help_str = "set watermark: "
395 "set_watermark <ring_name> <value>",
396 .tokens = { /* token list, NULL terminated */
397 (void *)&cmd_set_ring_set,
398 (void *)&cmd_set_ring_name,
399 (void *)&cmd_set_ring_value,
406 struct cmd_quit_result {
407 cmdline_fixed_string_t quit;
411 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
413 __attribute__((unused)) void *data)
418 cmdline_parse_token_string_t cmd_quit_quit =
419 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
422 cmdline_parse_inst_t cmd_quit = {
423 .f = cmd_quit_parsed, /* function to call */
424 .data = NULL, /* 2nd arg of func */
425 .help_str = "exit application",
426 .tokens = { /* token list, NULL terminated */
427 (void *)&cmd_quit_quit,
434 cmdline_parse_ctx_t main_ctx[] = {
435 (cmdline_parse_inst_t *)&cmd_autotest,
436 (cmdline_parse_inst_t *)&cmd_dump,
437 (cmdline_parse_inst_t *)&cmd_dump_one,
438 (cmdline_parse_inst_t *)&cmd_set_ring,
439 (cmdline_parse_inst_t *)&cmd_quit,