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