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, "hash_perf_autotest"))
129 ret |= test_hash_perf();
130 if (all || !strcmp(res->autotest, "lpm_autotest"))
132 if (all || !strcmp(res->autotest, "cpuflags_autotest"))
133 ret |= test_cpuflags();
134 if (all || !strcmp(res->autotest, "cmdline_autotest"))
135 ret |= test_cmdline();
136 /* tailq autotest must go after all lpm and hashs tests or any other
137 * tests which need to create tailq objects (ring and mempool are implicitly
138 * created in earlier tests so can go later)
140 if (all || !strcmp(res->autotest, "tailq_autotest"))
142 if (all || !strcmp(res->autotest, "multiprocess_autotest"))
143 ret |= test_mp_secondary();
144 if (all || !strcmp(res->autotest, "memcpy_autotest"))
145 ret |= test_memcpy();
146 if (all || !strcmp(res->autotest, "string_autotest"))
147 ret |= test_string_fns();
148 if (all || !strcmp(res->autotest, "eal_flags_autotest"))
149 ret |= test_eal_flags();
150 if (all || !strcmp(res->autotest, "alarm_autotest"))
152 if (all || !strcmp(res->autotest, "interrupt_autotest"))
153 ret |= test_interrupt();
154 if (all || !strcmp(res->autotest, "cycles_autotest"))
155 ret |= test_cycles();
156 if (all || !strcmp(res->autotest, "ring_autotest"))
158 if (all || !strcmp(res->autotest, "timer_autotest"))
160 if (all || !strcmp(res->autotest, "mempool_autotest"))
161 ret |= test_mempool();
162 if (all || !strcmp(res->autotest, "mempool_perf_autotest"))
163 ret |= test_mempool_perf();
164 if (all || !strcmp(res->autotest, "memcpy_perf_autotest"))
165 ret |= test_memcpy_perf();
166 if (all || !strcmp(res->autotest, "func_reentrancy_autotest"))
167 ret |= test_func_reentrancy();
168 if (all || !strcmp(res->autotest, "pm_autotest"))
169 ret |= test_pmac_pm();
170 if (all || !strcmp(res->autotest, "acl_autotest"))
171 ret |= test_pmac_acl();
176 printf("Test Failed\n");
180 cmdline_parse_token_string_t cmd_autotest_autotest =
181 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
182 "pci_autotest#memory_autotest#"
183 "per_lcore_autotest#spinlock_autotest#"
184 "rwlock_autotest#atomic_autotest#"
185 "byteorder_autotest#prefetch_autotest#"
186 "cycles_autotest#logs_autotest#"
187 "memzone_autotest#ring_autotest#"
188 "mempool_autotest#mbuf_autotest#"
189 "timer_autotest#malloc_autotest#"
190 "memcpy_autotest#hash_autotest#"
191 "lpm_autotest#debug_autotest#"
192 "errno_autotest#tailq_autotest#"
193 "string_autotest#multiprocess_autotest#"
194 "cpuflags_autotest#eal_flags_autotest#"
195 "alarm_autotest#interrupt_autotest#"
196 "version_autotest#eal_fs_autotest#"
197 "cmdline_autotest#func_reentrancy_autotest#"
198 "mempool_perf_autotest#hash_perf_autotest#"
199 "memcpy_perf_autotest#pm_autotest#"
203 cmdline_parse_inst_t cmd_autotest = {
204 .f = cmd_autotest_parsed, /* function to call */
205 .data = NULL, /* 2nd arg of func */
206 .help_str = "launch autotest",
207 .tokens = { /* token list, NULL terminated */
208 (void *)&cmd_autotest_autotest,
215 struct cmd_dump_result {
216 cmdline_fixed_string_t dump;
220 dump_struct_sizes(void)
222 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
223 DUMP_SIZE(struct rte_mbuf);
224 DUMP_SIZE(struct rte_pktmbuf);
225 DUMP_SIZE(struct rte_ctrlmbuf);
226 DUMP_SIZE(struct rte_mempool);
227 DUMP_SIZE(struct rte_ring);
231 static void cmd_dump_parsed(void *parsed_result,
232 __attribute__((unused)) struct cmdline *cl,
233 __attribute__((unused)) void *data)
235 struct cmd_dump_result *res = parsed_result;
237 if (!strcmp(res->dump, "dump_physmem"))
238 rte_dump_physmem_layout();
239 else if (!strcmp(res->dump, "dump_memzone"))
241 else if (!strcmp(res->dump, "dump_log_history"))
242 rte_log_dump_history();
243 else if (!strcmp(res->dump, "dump_struct_sizes"))
245 else if (!strcmp(res->dump, "dump_ring"))
246 rte_ring_list_dump();
247 else if (!strcmp(res->dump, "dump_mempool"))
248 rte_mempool_list_dump();
251 cmdline_parse_token_string_t cmd_dump_dump =
252 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
253 "dump_physmem#dump_memzone#dump_log_history#"
254 "dump_struct_sizes#dump_ring#dump_mempool");
256 cmdline_parse_inst_t cmd_dump = {
257 .f = cmd_dump_parsed, /* function to call */
258 .data = NULL, /* 2nd arg of func */
259 .help_str = "dump status",
260 .tokens = { /* token list, NULL terminated */
261 (void *)&cmd_dump_dump,
268 struct cmd_dump_one_result {
269 cmdline_fixed_string_t dump;
270 cmdline_fixed_string_t name;
273 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
274 __attribute__((unused)) void *data)
276 struct cmd_dump_one_result *res = parsed_result;
278 if (!strcmp(res->dump, "dump_ring")) {
280 r = rte_ring_lookup(res->name);
282 cmdline_printf(cl, "Cannot find ring\n");
287 else if (!strcmp(res->dump, "dump_mempool")) {
288 struct rte_mempool *mp;
289 mp = rte_mempool_lookup(res->name);
291 cmdline_printf(cl, "Cannot find mempool\n");
294 rte_mempool_dump(mp);
298 cmdline_parse_token_string_t cmd_dump_one_dump =
299 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
300 "dump_ring#dump_mempool");
302 cmdline_parse_token_string_t cmd_dump_one_name =
303 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
305 cmdline_parse_inst_t cmd_dump_one = {
306 .f = cmd_dump_one_parsed, /* function to call */
307 .data = NULL, /* 2nd arg of func */
308 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
309 .tokens = { /* token list, NULL terminated */
310 (void *)&cmd_dump_one_dump,
311 (void *)&cmd_dump_one_name,
318 struct cmd_set_ring_result {
319 cmdline_fixed_string_t set;
320 cmdline_fixed_string_t name;
324 static void cmd_set_ring_parsed(void *parsed_result, struct cmdline *cl,
325 __attribute__((unused)) void *data)
327 struct cmd_set_ring_result *res = parsed_result;
331 r = rte_ring_lookup(res->name);
333 cmdline_printf(cl, "Cannot find ring\n");
337 if (!strcmp(res->set, "set_watermark")) {
338 ret = rte_ring_set_water_mark(r, res->value);
340 cmdline_printf(cl, "Cannot set water mark\n");
344 cmdline_parse_token_string_t cmd_set_ring_set =
345 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, set,
348 cmdline_parse_token_string_t cmd_set_ring_name =
349 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, name, NULL);
351 cmdline_parse_token_num_t cmd_set_ring_value =
352 TOKEN_NUM_INITIALIZER(struct cmd_set_ring_result, value, UINT32);
354 cmdline_parse_inst_t cmd_set_ring = {
355 .f = cmd_set_ring_parsed, /* function to call */
356 .data = NULL, /* 2nd arg of func */
357 .help_str = "set watermark: "
358 "set_watermark <ring_name> <value>",
359 .tokens = { /* token list, NULL terminated */
360 (void *)&cmd_set_ring_set,
361 (void *)&cmd_set_ring_name,
362 (void *)&cmd_set_ring_value,
369 struct cmd_quit_result {
370 cmdline_fixed_string_t quit;
374 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
376 __attribute__((unused)) void *data)
381 cmdline_parse_token_string_t cmd_quit_quit =
382 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
385 cmdline_parse_inst_t cmd_quit = {
386 .f = cmd_quit_parsed, /* function to call */
387 .data = NULL, /* 2nd arg of func */
388 .help_str = "exit application",
389 .tokens = { /* token list, NULL terminated */
390 (void *)&cmd_quit_quit,
397 cmdline_parse_ctx_t main_ctx[] = {
398 (cmdline_parse_inst_t *)&cmd_autotest,
399 (cmdline_parse_inst_t *)&cmd_dump,
400 (cmdline_parse_inst_t *)&cmd_dump_one,
401 (cmdline_parse_inst_t *)&cmd_set_ring,
402 (cmdline_parse_inst_t *)&cmd_quit,