app/test: minor updates
[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         int all = 0;
90
91         if (!strcmp(res->autotest, "all_autotests"))
92                 all = 1;
93
94         if (all || !strcmp(res->autotest, "version_autotest"))
95                 ret |= test_version();
96         if (all || !strcmp(res->autotest, "eal_fs_autotest"))
97                 ret |= test_eal_fs();
98         if (all || !strcmp(res->autotest, "debug_autotest"))
99                 ret |= test_debug();
100         if (all || !strcmp(res->autotest, "pci_autotest"))
101                 ret |= test_pci();
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"))
121                 ret |= test_mbuf();
122         if (all || !strcmp(res->autotest, "logs_autotest"))
123                 ret |= test_logs();
124         if (all || !strcmp(res->autotest, "errno_autotest"))
125                 ret |= test_errno();
126         if (all || !strcmp(res->autotest, "hash_autotest"))
127                 ret |= test_hash();
128         if (all || !strcmp(res->autotest, "hash_perf_autotest"))
129                 ret |= test_hash_perf();
130         if (all || !strcmp(res->autotest, "lpm_autotest"))
131                 ret |= test_lpm();
132         if (all || !strcmp(res->autotest, "lpm6_autotest"))
133                 ret |= test_lpm6();
134         if (all || !strcmp(res->autotest, "cpuflags_autotest"))
135                 ret |= test_cpuflags();
136         if (all || !strcmp(res->autotest, "cmdline_autotest"))
137                 ret |= test_cmdline();
138         /* tailq autotest must go after all lpm and hashs tests or any other
139          * tests which need to create tailq objects (ring and mempool are implicitly
140          * created in earlier tests so can go later)
141          */
142         if (all || !strcmp(res->autotest, "tailq_autotest"))
143                 ret |= test_tailq();
144         if (all || !strcmp(res->autotest, "multiprocess_autotest"))
145                 ret |= test_mp_secondary();
146         if (all || !strcmp(res->autotest, "memcpy_autotest"))
147                 ret |= test_memcpy();
148         if (all || !strcmp(res->autotest, "string_autotest"))
149                 ret |= test_string_fns();
150         if (all || !strcmp(res->autotest, "eal_flags_autotest"))
151                 ret |= test_eal_flags();
152         if (all || !strcmp(res->autotest, "alarm_autotest"))
153                 ret |= test_alarm();
154         if (all || !strcmp(res->autotest, "interrupt_autotest"))
155                 ret |= test_interrupt();
156         if (all || !strcmp(res->autotest, "cycles_autotest"))
157                 ret |= test_cycles();
158         if (all || !strcmp(res->autotest, "ring_autotest"))
159                 ret |= test_ring();
160         if (all || !strcmp(res->autotest, "ring_perf_autotest"))
161                 ret |= test_ring_perf();
162         if (all || !strcmp(res->autotest, "timer_autotest"))
163                 ret |= test_timer();
164         if (all || !strcmp(res->autotest, "timer_perf_autotest"))
165                 ret |= test_timer_perf();
166         if (all || !strcmp(res->autotest, "mempool_autotest"))
167                 ret |= test_mempool();
168         if (all || !strcmp(res->autotest, "mempool_perf_autotest"))
169                 ret |= test_mempool_perf();
170         if (all || !strcmp(res->autotest, "memcpy_perf_autotest"))
171                 ret |= test_memcpy_perf();
172         if (all || !strcmp(res->autotest, "func_reentrancy_autotest"))
173                 ret |= test_func_reentrancy();
174         if (all || !strcmp(res->autotest, "red_autotest"))
175                 ret |= test_red();
176         if (all || !strcmp(res->autotest, "sched_autotest"))
177                 ret |= test_sched();
178         if (all || !strcmp(res->autotest, "meter_autotest"))
179                 ret |= test_meter();
180         if (all || !strcmp(res->autotest, "kni_autotest"))
181                 ret |= test_kni();
182         if (all || !strcmp(res->autotest, "power_autotest"))
183                 ret |= test_power();
184         if (all || !strcmp(res->autotest, "common_autotest"))
185                 ret |= test_common();
186         if (all || !strcmp(res->autotest, "ivshmem_autotest"))
187                 ret = test_ivshmem();
188 #ifdef RTE_LIBRTE_PMD_RING
189         if (all || !strcmp(res->autotest, "ring_pmd_autotest"))
190                 ret |= test_pmd_ring();
191 #endif /* RTE_LIBRTE_PMD_RING */
192
193 #ifdef RTE_LIBRTE_ACL
194         if (all || !strcmp(res->autotest, "acl_autotest"))
195                 ret |= test_acl();
196 #endif /* RTE_LIBRTE_ACL */
197
198         if (ret == 0)
199                 printf("Test OK\n");
200         else
201                 printf("Test Failed\n");
202         fflush(stdout);
203 }
204
205 cmdline_parse_token_string_t cmd_autotest_autotest =
206         TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
207                         "pci_autotest#memory_autotest#"
208                         "per_lcore_autotest#spinlock_autotest#"
209                         "rwlock_autotest#atomic_autotest#"
210                         "byteorder_autotest#prefetch_autotest#"
211                         "cycles_autotest#logs_autotest#"
212                         "memzone_autotest#ring_autotest#"
213                         "mempool_autotest#mbuf_autotest#"
214                         "timer_autotest#malloc_autotest#"
215                         "memcpy_autotest#hash_autotest#"
216                         "lpm_autotest#debug_autotest#"
217                         "lpm6_autotest#"
218                         "errno_autotest#tailq_autotest#"
219                         "string_autotest#multiprocess_autotest#"
220                         "cpuflags_autotest#eal_flags_autotest#"
221                         "alarm_autotest#interrupt_autotest#"
222                         "version_autotest#eal_fs_autotest#"
223                         "cmdline_autotest#func_reentrancy_autotest#"
224                         "mempool_perf_autotest#hash_perf_autotest#"
225                         "memcpy_perf_autotest#ring_perf_autotest#"
226                         "red_autotest#meter_autotest#sched_autotest#"
227                         "memcpy_perf_autotest#kni_autotest#"
228                         "pm_autotest#ivshmem_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                         "common_autotest#all_autotests");
238
239 cmdline_parse_inst_t cmd_autotest = {
240         .f = cmd_autotest_parsed,  /* function to call */
241         .data = NULL,      /* 2nd arg of func */
242         .help_str = "launch autotest",
243         .tokens = {        /* token list, NULL terminated */
244                 (void *)&cmd_autotest_autotest,
245                 NULL,
246         },
247 };
248
249 /****************/
250
251 struct cmd_dump_result {
252         cmdline_fixed_string_t dump;
253 };
254
255 static void
256 dump_struct_sizes(void)
257 {
258 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
259         DUMP_SIZE(struct rte_mbuf);
260         DUMP_SIZE(struct rte_pktmbuf);
261         DUMP_SIZE(struct rte_ctrlmbuf);
262         DUMP_SIZE(struct rte_mempool);
263         DUMP_SIZE(struct rte_ring);
264 #undef DUMP_SIZE
265 }
266
267 static void cmd_dump_parsed(void *parsed_result,
268                             __attribute__((unused)) struct cmdline *cl,
269                             __attribute__((unused)) void *data)
270 {
271         struct cmd_dump_result *res = parsed_result;
272
273         if (!strcmp(res->dump, "dump_physmem"))
274                 rte_dump_physmem_layout();
275         else if (!strcmp(res->dump, "dump_memzone"))
276                 rte_memzone_dump();
277         else if (!strcmp(res->dump, "dump_log_history"))
278                 rte_log_dump_history();
279         else if (!strcmp(res->dump, "dump_struct_sizes"))
280                 dump_struct_sizes();
281         else if (!strcmp(res->dump, "dump_ring"))
282                 rte_ring_list_dump();
283         else if (!strcmp(res->dump, "dump_mempool"))
284                 rte_mempool_list_dump();
285 }
286
287 cmdline_parse_token_string_t cmd_dump_dump =
288         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
289                                  "dump_physmem#dump_memzone#dump_log_history#"
290                                  "dump_struct_sizes#dump_ring#dump_mempool");
291
292 cmdline_parse_inst_t cmd_dump = {
293         .f = cmd_dump_parsed,  /* function to call */
294         .data = NULL,      /* 2nd arg of func */
295         .help_str = "dump status",
296         .tokens = {        /* token list, NULL terminated */
297                 (void *)&cmd_dump_dump,
298                 NULL,
299         },
300 };
301
302 /****************/
303
304 struct cmd_dump_one_result {
305         cmdline_fixed_string_t dump;
306         cmdline_fixed_string_t name;
307 };
308
309 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
310                                 __attribute__((unused)) void *data)
311 {
312         struct cmd_dump_one_result *res = parsed_result;
313
314         if (!strcmp(res->dump, "dump_ring")) {
315                 struct rte_ring *r;
316                 r = rte_ring_lookup(res->name);
317                 if (r == NULL) {
318                         cmdline_printf(cl, "Cannot find ring\n");
319                         return;
320                 }
321                 rte_ring_dump(r);
322         }
323         else if (!strcmp(res->dump, "dump_mempool")) {
324                 struct rte_mempool *mp;
325                 mp = rte_mempool_lookup(res->name);
326                 if (mp == NULL) {
327                         cmdline_printf(cl, "Cannot find mempool\n");
328                         return;
329                 }
330                 rte_mempool_dump(mp);
331         }
332 }
333
334 cmdline_parse_token_string_t cmd_dump_one_dump =
335         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
336                                  "dump_ring#dump_mempool");
337
338 cmdline_parse_token_string_t cmd_dump_one_name =
339         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
340
341 cmdline_parse_inst_t cmd_dump_one = {
342         .f = cmd_dump_one_parsed,  /* function to call */
343         .data = NULL,      /* 2nd arg of func */
344         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
345         .tokens = {        /* token list, NULL terminated */
346                 (void *)&cmd_dump_one_dump,
347                 (void *)&cmd_dump_one_name,
348                 NULL,
349         },
350 };
351
352 /****************/
353
354 struct cmd_set_ring_result {
355         cmdline_fixed_string_t set;
356         cmdline_fixed_string_t name;
357         uint32_t value;
358 };
359
360 static void cmd_set_ring_parsed(void *parsed_result, struct cmdline *cl,
361                                 __attribute__((unused)) void *data)
362 {
363         struct cmd_set_ring_result *res = parsed_result;
364         struct rte_ring *r;
365         int ret;
366
367         r = rte_ring_lookup(res->name);
368         if (r == NULL) {
369                 cmdline_printf(cl, "Cannot find ring\n");
370                 return;
371         }
372
373         if (!strcmp(res->set, "set_watermark")) {
374                 ret = rte_ring_set_water_mark(r, res->value);
375                 if (ret != 0)
376                         cmdline_printf(cl, "Cannot set water mark\n");
377         }
378 }
379
380 cmdline_parse_token_string_t cmd_set_ring_set =
381         TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, set,
382                                  "set_watermark");
383
384 cmdline_parse_token_string_t cmd_set_ring_name =
385         TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, name, NULL);
386
387 cmdline_parse_token_num_t cmd_set_ring_value =
388         TOKEN_NUM_INITIALIZER(struct cmd_set_ring_result, value, UINT32);
389
390 cmdline_parse_inst_t cmd_set_ring = {
391         .f = cmd_set_ring_parsed,  /* function to call */
392         .data = NULL,      /* 2nd arg of func */
393         .help_str = "set watermark: "
394                         "set_watermark <ring_name> <value>",
395         .tokens = {        /* token list, NULL terminated */
396                 (void *)&cmd_set_ring_set,
397                 (void *)&cmd_set_ring_name,
398                 (void *)&cmd_set_ring_value,
399                 NULL,
400         },
401 };
402
403 /****************/
404
405 struct cmd_quit_result {
406         cmdline_fixed_string_t quit;
407 };
408
409 static void
410 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
411                 struct cmdline *cl,
412                 __attribute__((unused)) void *data)
413 {
414         cmdline_quit(cl);
415 }
416
417 cmdline_parse_token_string_t cmd_quit_quit =
418         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
419                                  "quit");
420
421 cmdline_parse_inst_t cmd_quit = {
422         .f = cmd_quit_parsed,  /* function to call */
423         .data = NULL,      /* 2nd arg of func */
424         .help_str = "exit application",
425         .tokens = {        /* token list, NULL terminated */
426                 (void *)&cmd_quit_quit,
427                 NULL,
428         },
429 };
430
431 /****************/
432
433 cmdline_parse_ctx_t main_ctx[] = {
434         (cmdline_parse_inst_t *)&cmd_autotest,
435         (cmdline_parse_inst_t *)&cmd_dump,
436         (cmdline_parse_inst_t *)&cmd_dump_one,
437         (cmdline_parse_inst_t *)&cmd_set_ring,
438         (cmdline_parse_inst_t *)&cmd_quit,
439         NULL,
440 };
441