4 * Copyright(c) 2010-2013 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>
42 #include <net/socket.h>
46 #include <sys/queue.h>
48 #include <rte_common.h>
50 #include <rte_debug.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
55 #include <rte_cycles.h>
56 #include <rte_tailq.h>
58 #include <rte_per_lcore.h>
59 #include <rte_lcore.h>
60 #include <rte_atomic.h>
61 #include <rte_branch_prediction.h>
63 #include <rte_mempool.h>
65 #include <rte_timer.h>
67 #include <cmdline_rdline.h>
68 #include <cmdline_parse.h>
69 #include <cmdline_parse_ipaddr.h>
70 #include <cmdline_parse_num.h>
71 #include <cmdline_parse_string.h>
78 struct cmd_autotest_result {
79 cmdline_fixed_string_t autotest;
82 static void cmd_autotest_parsed(void *parsed_result,
83 __attribute__((unused)) struct cmdline *cl,
84 __attribute__((unused)) void *data)
86 struct cmd_autotest_result *res = parsed_result;
90 if (!strcmp(res->autotest, "all_autotests"))
93 if (all || !strcmp(res->autotest, "version_autotest"))
94 ret |= test_version();
95 if (all || !strcmp(res->autotest, "eal_fs_autotest"))
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, "hash_perf_autotest"))
128 ret |= test_hash_perf();
129 if (all || !strcmp(res->autotest, "lpm_autotest"))
131 if (all || !strcmp(res->autotest, "lpm6_autotest"))
133 if (all || !strcmp(res->autotest, "cpuflags_autotest"))
134 ret |= test_cpuflags();
135 if (all || !strcmp(res->autotest, "cmdline_autotest"))
136 ret |= test_cmdline();
137 /* tailq autotest must go after all lpm and hashs tests or any other
138 * tests which need to create tailq objects (ring and mempool are implicitly
139 * created in earlier tests so can go later)
141 if (all || !strcmp(res->autotest, "tailq_autotest"))
143 if (all || !strcmp(res->autotest, "multiprocess_autotest"))
144 ret |= test_mp_secondary();
145 if (all || !strcmp(res->autotest, "memcpy_autotest"))
146 ret |= test_memcpy();
147 if (all || !strcmp(res->autotest, "string_autotest"))
148 ret |= test_string_fns();
149 if (all || !strcmp(res->autotest, "eal_flags_autotest"))
150 ret |= test_eal_flags();
151 if (all || !strcmp(res->autotest, "alarm_autotest"))
153 if (all || !strcmp(res->autotest, "interrupt_autotest"))
154 ret |= test_interrupt();
155 if (all || !strcmp(res->autotest, "cycles_autotest"))
156 ret |= test_cycles();
157 if (all || !strcmp(res->autotest, "ring_autotest"))
159 if (all || !strcmp(res->autotest, "ring_perf_autotest"))
160 ret |= test_ring_perf();
161 if (all || !strcmp(res->autotest, "timer_autotest"))
163 if (all || !strcmp(res->autotest, "mempool_autotest"))
164 ret |= test_mempool();
165 if (all || !strcmp(res->autotest, "mempool_perf_autotest"))
166 ret |= test_mempool_perf();
167 if (all || !strcmp(res->autotest, "memcpy_perf_autotest"))
168 ret |= test_memcpy_perf();
169 if (all || !strcmp(res->autotest, "func_reentrancy_autotest"))
170 ret |= test_func_reentrancy();
171 if (all || !strcmp(res->autotest, "red_autotest"))
173 if (all || !strcmp(res->autotest, "sched_autotest"))
175 if (all || !strcmp(res->autotest, "meter_autotest"))
177 if (all || !strcmp(res->autotest, "kni_autotest"))
179 if (all || !strcmp(res->autotest, "acl_autotest"))
180 ret |= test_pmac_acl();
181 if (all || !strcmp(res->autotest, "power_autotest"))
183 if (all || !strcmp(res->autotest, "common_autotest"))
184 ret |= test_common();
189 printf("Test Failed\n");
193 cmdline_parse_token_string_t cmd_autotest_autotest =
194 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
195 "pci_autotest#memory_autotest#"
196 "per_lcore_autotest#spinlock_autotest#"
197 "rwlock_autotest#atomic_autotest#"
198 "byteorder_autotest#prefetch_autotest#"
199 "cycles_autotest#logs_autotest#"
200 "memzone_autotest#ring_autotest#"
201 "mempool_autotest#mbuf_autotest#"
202 "timer_autotest#malloc_autotest#"
203 "memcpy_autotest#hash_autotest#"
204 "lpm_autotest#debug_autotest#"
205 "lpm6_autotest#debug_autotest#"
206 "errno_autotest#tailq_autotest#"
207 "string_autotest#multiprocess_autotest#"
208 "cpuflags_autotest#eal_flags_autotest#"
209 "alarm_autotest#interrupt_autotest#"
210 "version_autotest#eal_fs_autotest#"
211 "cmdline_autotest#func_reentrancy_autotest#"
212 "mempool_perf_autotest#hash_perf_autotest#"
213 "memcpy_perf_autotest#ring_perf_autotest#"
214 "red_autotest#meter_autotest#sched_autotest#"
215 "memcpy_perf_autotest#kni_autotest#"
216 "pm_autotest#acl_autotest#power_autotest#"
217 "common_autotest#all_autotests");
219 cmdline_parse_inst_t cmd_autotest = {
220 .f = cmd_autotest_parsed, /* function to call */
221 .data = NULL, /* 2nd arg of func */
222 .help_str = "launch autotest",
223 .tokens = { /* token list, NULL terminated */
224 (void *)&cmd_autotest_autotest,
231 struct cmd_dump_result {
232 cmdline_fixed_string_t dump;
236 dump_struct_sizes(void)
238 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
239 DUMP_SIZE(struct rte_mbuf);
240 DUMP_SIZE(struct rte_pktmbuf);
241 DUMP_SIZE(struct rte_ctrlmbuf);
242 DUMP_SIZE(struct rte_mempool);
243 DUMP_SIZE(struct rte_ring);
247 static void cmd_dump_parsed(void *parsed_result,
248 __attribute__((unused)) struct cmdline *cl,
249 __attribute__((unused)) void *data)
251 struct cmd_dump_result *res = parsed_result;
253 if (!strcmp(res->dump, "dump_physmem"))
254 rte_dump_physmem_layout();
255 else if (!strcmp(res->dump, "dump_memzone"))
257 else if (!strcmp(res->dump, "dump_log_history"))
258 rte_log_dump_history();
259 else if (!strcmp(res->dump, "dump_struct_sizes"))
261 else if (!strcmp(res->dump, "dump_ring"))
262 rte_ring_list_dump();
263 else if (!strcmp(res->dump, "dump_mempool"))
264 rte_mempool_list_dump();
267 cmdline_parse_token_string_t cmd_dump_dump =
268 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
269 "dump_physmem#dump_memzone#dump_log_history#"
270 "dump_struct_sizes#dump_ring#dump_mempool");
272 cmdline_parse_inst_t cmd_dump = {
273 .f = cmd_dump_parsed, /* function to call */
274 .data = NULL, /* 2nd arg of func */
275 .help_str = "dump status",
276 .tokens = { /* token list, NULL terminated */
277 (void *)&cmd_dump_dump,
284 struct cmd_dump_one_result {
285 cmdline_fixed_string_t dump;
286 cmdline_fixed_string_t name;
289 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
290 __attribute__((unused)) void *data)
292 struct cmd_dump_one_result *res = parsed_result;
294 if (!strcmp(res->dump, "dump_ring")) {
296 r = rte_ring_lookup(res->name);
298 cmdline_printf(cl, "Cannot find ring\n");
303 else if (!strcmp(res->dump, "dump_mempool")) {
304 struct rte_mempool *mp;
305 mp = rte_mempool_lookup(res->name);
307 cmdline_printf(cl, "Cannot find mempool\n");
310 rte_mempool_dump(mp);
314 cmdline_parse_token_string_t cmd_dump_one_dump =
315 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
316 "dump_ring#dump_mempool");
318 cmdline_parse_token_string_t cmd_dump_one_name =
319 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
321 cmdline_parse_inst_t cmd_dump_one = {
322 .f = cmd_dump_one_parsed, /* function to call */
323 .data = NULL, /* 2nd arg of func */
324 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
325 .tokens = { /* token list, NULL terminated */
326 (void *)&cmd_dump_one_dump,
327 (void *)&cmd_dump_one_name,
334 struct cmd_set_ring_result {
335 cmdline_fixed_string_t set;
336 cmdline_fixed_string_t name;
340 static void cmd_set_ring_parsed(void *parsed_result, struct cmdline *cl,
341 __attribute__((unused)) void *data)
343 struct cmd_set_ring_result *res = parsed_result;
347 r = rte_ring_lookup(res->name);
349 cmdline_printf(cl, "Cannot find ring\n");
353 if (!strcmp(res->set, "set_watermark")) {
354 ret = rte_ring_set_water_mark(r, res->value);
356 cmdline_printf(cl, "Cannot set water mark\n");
360 cmdline_parse_token_string_t cmd_set_ring_set =
361 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, set,
364 cmdline_parse_token_string_t cmd_set_ring_name =
365 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, name, NULL);
367 cmdline_parse_token_num_t cmd_set_ring_value =
368 TOKEN_NUM_INITIALIZER(struct cmd_set_ring_result, value, UINT32);
370 cmdline_parse_inst_t cmd_set_ring = {
371 .f = cmd_set_ring_parsed, /* function to call */
372 .data = NULL, /* 2nd arg of func */
373 .help_str = "set watermark: "
374 "set_watermark <ring_name> <value>",
375 .tokens = { /* token list, NULL terminated */
376 (void *)&cmd_set_ring_set,
377 (void *)&cmd_set_ring_name,
378 (void *)&cmd_set_ring_value,
385 struct cmd_quit_result {
386 cmdline_fixed_string_t quit;
390 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
392 __attribute__((unused)) void *data)
397 cmdline_parse_token_string_t cmd_quit_quit =
398 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
401 cmdline_parse_inst_t cmd_quit = {
402 .f = cmd_quit_parsed, /* function to call */
403 .data = NULL, /* 2nd arg of func */
404 .help_str = "exit application",
405 .tokens = { /* token list, NULL terminated */
406 (void *)&cmd_quit_quit,
413 cmdline_parse_ctx_t main_ctx[] = {
414 (cmdline_parse_inst_t *)&cmd_autotest,
415 (cmdline_parse_inst_t *)&cmd_dump,
416 (cmdline_parse_inst_t *)&cmd_dump_one,
417 (cmdline_parse_inst_t *)&cmd_set_ring,
418 (cmdline_parse_inst_t *)&cmd_quit,