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