7595b4c76a937f918b788a8e186d701c1a140b1e
[dpdk.git] / app / test / commands.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  * 
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  * 
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  * 
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdio.h>
36 #include <stdarg.h>
37 #include <stdint.h>
38 #include <string.h>
39 #include <stdlib.h>
40 #include <netinet/in.h>
41 #include <termios.h>
42 #ifndef __linux__
43 #ifndef __FreeBSD__
44 #include <net/socket.h>
45 #endif
46 #endif
47 #include <inttypes.h>
48 #include <errno.h>
49 #include <sys/queue.h>
50
51 #include <rte_common.h>
52 #include <rte_log.h>
53 #include <rte_debug.h>
54 #include <rte_memory.h>
55 #include <rte_memcpy.h>
56 #include <rte_memzone.h>
57 #include <rte_launch.h>
58 #include <rte_cycles.h>
59 #include <rte_tailq.h>
60 #include <rte_eal.h>
61 #include <rte_per_lcore.h>
62 #include <rte_lcore.h>
63 #include <rte_atomic.h>
64 #include <rte_branch_prediction.h>
65 #include <rte_ring.h>
66 #include <rte_mempool.h>
67 #include <rte_mbuf.h>
68
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>
74 #include <cmdline.h>
75
76 #include "test.h"
77
78 /****************/
79
80 struct cmd_autotest_result {
81         cmdline_fixed_string_t autotest;
82 };
83
84 static void cmd_autotest_parsed(void *parsed_result,
85                                 __attribute__((unused)) struct cmdline *cl,
86                                 __attribute__((unused)) void *data)
87 {
88         struct cmd_autotest_result *res = parsed_result;
89         int ret = 0;
90
91         if (!strcmp(res->autotest, "version_autotest"))
92                 ret = test_version();
93         if (!strcmp(res->autotest, "eal_fs_autotest"))
94                 ret = test_eal_fs();
95         if (!strcmp(res->autotest, "debug_autotest"))
96                 ret = test_debug();
97         if (!strcmp(res->autotest, "pci_autotest"))
98                 ret = test_pci();
99         if (!strcmp(res->autotest, "prefetch_autotest"))
100                 ret = test_prefetch();
101         if (!strcmp(res->autotest, "byteorder_autotest"))
102                 ret = test_byteorder();
103         if (!strcmp(res->autotest, "per_lcore_autotest"))
104                 ret = test_per_lcore();
105         if (!strcmp(res->autotest, "atomic_autotest"))
106                 ret = test_atomic();
107         if (!strcmp(res->autotest, "malloc_autotest"))
108                 ret = test_malloc();
109         if (!strcmp(res->autotest, "spinlock_autotest"))
110                 ret = test_spinlock();
111         if (!strcmp(res->autotest, "memory_autotest"))
112                 ret = test_memory();
113         if (!strcmp(res->autotest, "memzone_autotest"))
114                 ret = test_memzone();
115         if (!strcmp(res->autotest, "rwlock_autotest"))
116                 ret = test_rwlock();
117         if (!strcmp(res->autotest, "mbuf_autotest"))
118                 ret = test_mbuf();
119         if (!strcmp(res->autotest, "logs_autotest"))
120                 ret = test_logs();
121         if (!strcmp(res->autotest, "errno_autotest"))
122                 ret = test_errno();
123         if (!strcmp(res->autotest, "hash_autotest"))
124                 ret = test_hash();
125         if (!strcmp(res->autotest, "hash_perf_autotest"))
126                 ret = test_hash_perf();
127         if (!strcmp(res->autotest, "lpm_autotest"))
128                 ret = test_lpm();
129         if (!strcmp(res->autotest, "lpm6_autotest"))
130                 ret = test_lpm6();
131         if (!strcmp(res->autotest, "cpuflags_autotest"))
132                 ret = test_cpuflags();
133         if (!strcmp(res->autotest, "cmdline_autotest"))
134                 ret = test_cmdline();
135         if (!strcmp(res->autotest, "tailq_autotest"))
136                 ret = test_tailq();
137         if (!strcmp(res->autotest, "multiprocess_autotest"))
138                 ret = test_mp_secondary();
139         if (!strcmp(res->autotest, "memcpy_autotest"))
140                 ret = test_memcpy();
141         if (!strcmp(res->autotest, "string_autotest"))
142                 ret = test_string_fns();
143         if (!strcmp(res->autotest, "eal_flags_autotest"))
144                 ret = test_eal_flags();
145         if (!strcmp(res->autotest, "alarm_autotest"))
146                 ret = test_alarm();
147         if (!strcmp(res->autotest, "interrupt_autotest"))
148                 ret = test_interrupt();
149         if (!strcmp(res->autotest, "cycles_autotest"))
150                 ret = test_cycles();
151         if (!strcmp(res->autotest, "ring_autotest"))
152                 ret = test_ring();
153         if (!strcmp(res->autotest, "ring_perf_autotest"))
154                 ret = test_ring_perf();
155         if (!strcmp(res->autotest, "timer_autotest"))
156                 ret = test_timer();
157         if (!strcmp(res->autotest, "timer_perf_autotest"))
158                 ret = test_timer_perf();
159         if (!strcmp(res->autotest, "mempool_autotest"))
160                 ret = test_mempool();
161         if (!strcmp(res->autotest, "mempool_perf_autotest"))
162                 ret = test_mempool_perf();
163         if (!strcmp(res->autotest, "memcpy_perf_autotest"))
164                 ret = test_memcpy_perf();
165         if (!strcmp(res->autotest, "func_reentrancy_autotest"))
166                 ret = test_func_reentrancy();
167         if (!strcmp(res->autotest, "red_autotest"))
168                 ret = test_red();
169         if (!strcmp(res->autotest, "sched_autotest"))
170                 ret = test_sched();
171         if (!strcmp(res->autotest, "meter_autotest"))
172                 ret = test_meter();
173         if (!strcmp(res->autotest, "kni_autotest"))
174                 ret = test_kni();
175         if (!strcmp(res->autotest, "power_autotest"))
176                 ret = test_power();
177         if (!strcmp(res->autotest, "common_autotest"))
178                 ret = test_common();
179         if (!strcmp(res->autotest, "ivshmem_autotest"))
180                 ret = test_ivshmem();
181         if (!strcmp(res->autotest, "devargs_autotest"))
182                 ret = test_devargs();
183 #ifdef RTE_LIBRTE_PMD_RING
184         if (!strcmp(res->autotest, "ring_pmd_autotest"))
185                 ret = test_pmd_ring();
186 #endif /* RTE_LIBRTE_PMD_RING */
187
188 #ifdef RTE_LIBRTE_ACL
189         if (!strcmp(res->autotest, "acl_autotest"))
190                 ret = test_acl();
191 #endif /* RTE_LIBRTE_ACL */
192 #ifdef RTE_LIBRTE_KVARGS
193         if (!strcmp(res->autotest, "kvargs_autotest"))
194                 ret |= test_kvargs();
195 #endif /* RTE_LIBRTE_KVARGS */
196
197         if (ret == 0)
198                 printf("Test OK\n");
199         else
200                 printf("Test Failed\n");
201         fflush(stdout);
202 }
203
204 cmdline_parse_token_string_t cmd_autotest_autotest =
205         TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
206                         "pci_autotest#memory_autotest#"
207                         "per_lcore_autotest#spinlock_autotest#"
208                         "rwlock_autotest#atomic_autotest#"
209                         "byteorder_autotest#prefetch_autotest#"
210                         "cycles_autotest#logs_autotest#"
211                         "memzone_autotest#ring_autotest#"
212                         "mempool_autotest#mbuf_autotest#"
213                         "timer_autotest#malloc_autotest#"
214                         "memcpy_autotest#hash_autotest#"
215                         "lpm_autotest#debug_autotest#"
216                         "lpm6_autotest#"
217                         "errno_autotest#tailq_autotest#"
218                         "string_autotest#multiprocess_autotest#"
219                         "cpuflags_autotest#eal_flags_autotest#"
220                         "alarm_autotest#interrupt_autotest#"
221                         "version_autotest#eal_fs_autotest#"
222                         "cmdline_autotest#func_reentrancy_autotest#"
223                         "mempool_perf_autotest#hash_perf_autotest#"
224                         "memcpy_perf_autotest#ring_perf_autotest#"
225                         "red_autotest#meter_autotest#sched_autotest#"
226                         "memcpy_perf_autotest#kni_autotest#"
227                         "pm_autotest#ivshmem_autotest#"
228                         "devargs_autotest#"
229 #ifdef RTE_LIBRTE_ACL
230                         "acl_autotest#"
231 #endif
232                         "power_autotest#"
233                         "timer_perf_autotest#"
234 #ifdef RTE_LIBRTE_PMD_RING
235                         "ring_pmd_autotest#"
236 #endif
237 #ifdef RTE_LIBRTE_KVARGS
238                         "kvargs_autotest#"
239 #endif
240                         "common_autotest");
241
242 cmdline_parse_inst_t cmd_autotest = {
243         .f = cmd_autotest_parsed,  /* function to call */
244         .data = NULL,      /* 2nd arg of func */
245         .help_str = "launch autotest",
246         .tokens = {        /* token list, NULL terminated */
247                 (void *)&cmd_autotest_autotest,
248                 NULL,
249         },
250 };
251
252 /****************/
253
254 struct cmd_dump_result {
255         cmdline_fixed_string_t dump;
256 };
257
258 static void
259 dump_struct_sizes(void)
260 {
261 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
262         DUMP_SIZE(struct rte_mbuf);
263         DUMP_SIZE(struct rte_pktmbuf);
264         DUMP_SIZE(struct rte_ctrlmbuf);
265         DUMP_SIZE(struct rte_mempool);
266         DUMP_SIZE(struct rte_ring);
267 #undef DUMP_SIZE
268 }
269
270 static void cmd_dump_parsed(void *parsed_result,
271                             __attribute__((unused)) struct cmdline *cl,
272                             __attribute__((unused)) void *data)
273 {
274         struct cmd_dump_result *res = parsed_result;
275
276         if (!strcmp(res->dump, "dump_physmem"))
277                 rte_dump_physmem_layout();
278         else if (!strcmp(res->dump, "dump_memzone"))
279                 rte_memzone_dump();
280         else if (!strcmp(res->dump, "dump_log_history"))
281                 rte_log_dump_history();
282         else if (!strcmp(res->dump, "dump_struct_sizes"))
283                 dump_struct_sizes();
284         else if (!strcmp(res->dump, "dump_ring"))
285                 rte_ring_list_dump();
286         else if (!strcmp(res->dump, "dump_mempool"))
287                 rte_mempool_list_dump();
288 }
289
290 cmdline_parse_token_string_t cmd_dump_dump =
291         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
292                                  "dump_physmem#dump_memzone#dump_log_history#"
293                                  "dump_struct_sizes#dump_ring#dump_mempool");
294
295 cmdline_parse_inst_t cmd_dump = {
296         .f = cmd_dump_parsed,  /* function to call */
297         .data = NULL,      /* 2nd arg of func */
298         .help_str = "dump status",
299         .tokens = {        /* token list, NULL terminated */
300                 (void *)&cmd_dump_dump,
301                 NULL,
302         },
303 };
304
305 /****************/
306
307 struct cmd_dump_one_result {
308         cmdline_fixed_string_t dump;
309         cmdline_fixed_string_t name;
310 };
311
312 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
313                                 __attribute__((unused)) void *data)
314 {
315         struct cmd_dump_one_result *res = parsed_result;
316
317         if (!strcmp(res->dump, "dump_ring")) {
318                 struct rte_ring *r;
319                 r = rte_ring_lookup(res->name);
320                 if (r == NULL) {
321                         cmdline_printf(cl, "Cannot find ring\n");
322                         return;
323                 }
324                 rte_ring_dump(r);
325         }
326         else if (!strcmp(res->dump, "dump_mempool")) {
327                 struct rte_mempool *mp;
328                 mp = rte_mempool_lookup(res->name);
329                 if (mp == NULL) {
330                         cmdline_printf(cl, "Cannot find mempool\n");
331                         return;
332                 }
333                 rte_mempool_dump(mp);
334         }
335 }
336
337 cmdline_parse_token_string_t cmd_dump_one_dump =
338         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
339                                  "dump_ring#dump_mempool");
340
341 cmdline_parse_token_string_t cmd_dump_one_name =
342         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
343
344 cmdline_parse_inst_t cmd_dump_one = {
345         .f = cmd_dump_one_parsed,  /* function to call */
346         .data = NULL,      /* 2nd arg of func */
347         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
348         .tokens = {        /* token list, NULL terminated */
349                 (void *)&cmd_dump_one_dump,
350                 (void *)&cmd_dump_one_name,
351                 NULL,
352         },
353 };
354
355 /****************/
356
357 struct cmd_set_ring_result {
358         cmdline_fixed_string_t set;
359         cmdline_fixed_string_t name;
360         uint32_t value;
361 };
362
363 static void cmd_set_ring_parsed(void *parsed_result, struct cmdline *cl,
364                                 __attribute__((unused)) void *data)
365 {
366         struct cmd_set_ring_result *res = parsed_result;
367         struct rte_ring *r;
368         int ret;
369
370         r = rte_ring_lookup(res->name);
371         if (r == NULL) {
372                 cmdline_printf(cl, "Cannot find ring\n");
373                 return;
374         }
375
376         if (!strcmp(res->set, "set_watermark")) {
377                 ret = rte_ring_set_water_mark(r, res->value);
378                 if (ret != 0)
379                         cmdline_printf(cl, "Cannot set water mark\n");
380         }
381 }
382
383 cmdline_parse_token_string_t cmd_set_ring_set =
384         TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, set,
385                                  "set_watermark");
386
387 cmdline_parse_token_string_t cmd_set_ring_name =
388         TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, name, NULL);
389
390 cmdline_parse_token_num_t cmd_set_ring_value =
391         TOKEN_NUM_INITIALIZER(struct cmd_set_ring_result, value, UINT32);
392
393 cmdline_parse_inst_t cmd_set_ring = {
394         .f = cmd_set_ring_parsed,  /* function to call */
395         .data = NULL,      /* 2nd arg of func */
396         .help_str = "set watermark: "
397                         "set_watermark <ring_name> <value>",
398         .tokens = {        /* token list, NULL terminated */
399                 (void *)&cmd_set_ring_set,
400                 (void *)&cmd_set_ring_name,
401                 (void *)&cmd_set_ring_value,
402                 NULL,
403         },
404 };
405
406 /****************/
407
408 struct cmd_quit_result {
409         cmdline_fixed_string_t quit;
410 };
411
412 static void
413 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
414                 struct cmdline *cl,
415                 __attribute__((unused)) void *data)
416 {
417         cmdline_quit(cl);
418 }
419
420 cmdline_parse_token_string_t cmd_quit_quit =
421         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
422                                  "quit");
423
424 cmdline_parse_inst_t cmd_quit = {
425         .f = cmd_quit_parsed,  /* function to call */
426         .data = NULL,      /* 2nd arg of func */
427         .help_str = "exit application",
428         .tokens = {        /* token list, NULL terminated */
429                 (void *)&cmd_quit_quit,
430                 NULL,
431         },
432 };
433
434 /****************/
435
436 cmdline_parse_ctx_t main_ctx[] = {
437         (cmdline_parse_inst_t *)&cmd_autotest,
438         (cmdline_parse_inst_t *)&cmd_dump,
439         (cmdline_parse_inst_t *)&cmd_dump_one,
440         (cmdline_parse_inst_t *)&cmd_set_ring,
441         (cmdline_parse_inst_t *)&cmd_quit,
442         NULL,
443 };
444