app: split performance tests
[dpdk.git] / app / test / commands.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2012 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
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 #include <net/socket.h>
44 #endif
45 #include <inttypes.h>
46 #include <errno.h>
47 #include <sys/queue.h>
48
49 #include <rte_common.h>
50 #include <rte_log.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>
58 #include <rte_eal.h>
59 #include <rte_per_lcore.h>
60 #include <rte_lcore.h>
61 #include <rte_atomic.h>
62 #include <rte_branch_prediction.h>
63 #include <rte_ring.h>
64 #include <rte_mempool.h>
65 #include <rte_mbuf.h>
66 #include <rte_timer.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, "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)
139          */
140         if (all || !strcmp(res->autotest, "tailq_autotest"))
141                 ret |= test_tailq();
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"))
151                 ret |= test_alarm();
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"))
157                 ret |= test_ring();
158         if (all || !strcmp(res->autotest, "timer_autotest"))
159                 ret |= test_timer();
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
167         if (ret == 0)
168                 printf("Test OK\n");
169         else
170                 printf("Test Failed\n");
171         fflush(stdout);
172 }
173
174 cmdline_parse_token_string_t cmd_autotest_autotest =
175         TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
176                         "pci_autotest#memory_autotest#"
177                         "per_lcore_autotest#spinlock_autotest#"
178                         "rwlock_autotest#atomic_autotest#"
179                         "byteorder_autotest#prefetch_autotest#"
180                         "cycles_autotest#logs_autotest#"
181                         "memzone_autotest#ring_autotest#"
182                         "mempool_autotest#mbuf_autotest#"
183                         "timer_autotest#malloc_autotest#"
184                         "memcpy_autotest#hash_autotest#"
185                         "lpm_autotest#debug_autotest#"
186                         "errno_autotest#tailq_autotest#"
187                         "string_autotest#multiprocess_autotest#"
188                         "cpuflags_autotest#eal_flags_autotest#"
189                         "alarm_autotest#interrupt_autotest#"
190                         "version_autotest#eal_fs_autotest#"
191                         "cmdline_autotest#"
192                         "mempool_perf_autotest#hash_perf_autotest#"
193                         "memcpy_perf_autotest#"
194                         "all_autotests");
195
196 cmdline_parse_inst_t cmd_autotest = {
197         .f = cmd_autotest_parsed,  /* function to call */
198         .data = NULL,      /* 2nd arg of func */
199         .help_str = "launch autotest",
200         .tokens = {        /* token list, NULL terminated */
201                 (void *)&cmd_autotest_autotest,
202                 NULL,
203         },
204 };
205
206 /****************/
207
208 struct cmd_dump_result {
209         cmdline_fixed_string_t dump;
210 };
211
212 static void
213 dump_struct_sizes(void)
214 {
215 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
216         DUMP_SIZE(struct rte_mbuf);
217         DUMP_SIZE(struct rte_pktmbuf);
218         DUMP_SIZE(struct rte_ctrlmbuf);
219         DUMP_SIZE(struct rte_mempool);
220         DUMP_SIZE(struct rte_ring);
221 #undef DUMP_SIZE
222 }
223
224 static void cmd_dump_parsed(void *parsed_result,
225                             __attribute__((unused)) struct cmdline *cl,
226                             __attribute__((unused)) void *data)
227 {
228         struct cmd_dump_result *res = parsed_result;
229
230         if (!strcmp(res->dump, "dump_physmem"))
231                 rte_dump_physmem_layout();
232         else if (!strcmp(res->dump, "dump_memzone"))
233                 rte_memzone_dump();
234         else if (!strcmp(res->dump, "dump_log_history"))
235                 rte_log_dump_history();
236         else if (!strcmp(res->dump, "dump_struct_sizes"))
237                 dump_struct_sizes();
238         else if (!strcmp(res->dump, "dump_ring"))
239                 rte_ring_list_dump();
240         else if (!strcmp(res->dump, "dump_mempool"))
241                 rte_mempool_list_dump();
242 }
243
244 cmdline_parse_token_string_t cmd_dump_dump =
245         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
246                                  "dump_physmem#dump_memzone#dump_log_history#"
247                                  "dump_struct_sizes#dump_ring#dump_mempool");
248
249 cmdline_parse_inst_t cmd_dump = {
250         .f = cmd_dump_parsed,  /* function to call */
251         .data = NULL,      /* 2nd arg of func */
252         .help_str = "dump status",
253         .tokens = {        /* token list, NULL terminated */
254                 (void *)&cmd_dump_dump,
255                 NULL,
256         },
257 };
258
259 /****************/
260
261 struct cmd_dump_one_result {
262         cmdline_fixed_string_t dump;
263         cmdline_fixed_string_t name;
264 };
265
266 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
267                                 __attribute__((unused)) void *data)
268 {
269         struct cmd_dump_one_result *res = parsed_result;
270
271         if (!strcmp(res->dump, "dump_ring")) {
272                 struct rte_ring *r;
273                 r = rte_ring_lookup(res->name);
274                 if (r == NULL) {
275                         cmdline_printf(cl, "Cannot find ring\n");
276                         return;
277                 }
278                 rte_ring_dump(r);
279         }
280         else if (!strcmp(res->dump, "dump_mempool")) {
281                 struct rte_mempool *mp;
282                 mp = rte_mempool_lookup(res->name);
283                 if (mp == NULL) {
284                         cmdline_printf(cl, "Cannot find mempool\n");
285                         return;
286                 }
287                 rte_mempool_dump(mp);
288         }
289 }
290
291 cmdline_parse_token_string_t cmd_dump_one_dump =
292         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
293                                  "dump_ring#dump_mempool");
294
295 cmdline_parse_token_string_t cmd_dump_one_name =
296         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
297
298 cmdline_parse_inst_t cmd_dump_one = {
299         .f = cmd_dump_one_parsed,  /* function to call */
300         .data = NULL,      /* 2nd arg of func */
301         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
302         .tokens = {        /* token list, NULL terminated */
303                 (void *)&cmd_dump_one_dump,
304                 (void *)&cmd_dump_one_name,
305                 NULL,
306         },
307 };
308
309 /****************/
310
311 struct cmd_set_ring_result {
312         cmdline_fixed_string_t set;
313         cmdline_fixed_string_t name;
314         uint32_t value;
315 };
316
317 static void cmd_set_ring_parsed(void *parsed_result, struct cmdline *cl,
318                                 __attribute__((unused)) void *data)
319 {
320         struct cmd_set_ring_result *res = parsed_result;
321         struct rte_ring *r;
322         int ret;
323
324         r = rte_ring_lookup(res->name);
325         if (r == NULL) {
326                 cmdline_printf(cl, "Cannot find ring\n");
327                 return;
328         }
329
330         if (!strcmp(res->set, "set_quota")) {
331                 ret = rte_ring_set_bulk_count(r, res->value);
332                 if (ret != 0)
333                         cmdline_printf(cl, "Cannot set quota\n");
334         }
335         else if (!strcmp(res->set, "set_watermark")) {
336                 ret = rte_ring_set_water_mark(r, res->value);
337                 if (ret != 0)
338                         cmdline_printf(cl, "Cannot set water mark\n");
339         }
340 }
341
342 cmdline_parse_token_string_t cmd_set_ring_set =
343         TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, set,
344                                  "set_quota#set_watermark");
345
346 cmdline_parse_token_string_t cmd_set_ring_name =
347         TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, name, NULL);
348
349 cmdline_parse_token_num_t cmd_set_ring_value =
350         TOKEN_NUM_INITIALIZER(struct cmd_set_ring_result, value, UINT32);
351
352 cmdline_parse_inst_t cmd_set_ring = {
353         .f = cmd_set_ring_parsed,  /* function to call */
354         .data = NULL,      /* 2nd arg of func */
355         .help_str = "set quota/watermark: "
356                         "set_quota|set_watermark <ring_name> <value>",
357         .tokens = {        /* token list, NULL terminated */
358                 (void *)&cmd_set_ring_set,
359                 (void *)&cmd_set_ring_name,
360                 (void *)&cmd_set_ring_value,
361                 NULL,
362         },
363 };
364
365 /****************/
366
367 struct cmd_quit_result {
368         cmdline_fixed_string_t quit;
369 };
370
371 static void
372 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
373                 struct cmdline *cl,
374                 __attribute__((unused)) void *data)
375 {
376         cmdline_quit(cl);
377 }
378
379 cmdline_parse_token_string_t cmd_quit_quit =
380         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
381                                  "quit");
382
383 cmdline_parse_inst_t cmd_quit = {
384         .f = cmd_quit_parsed,  /* function to call */
385         .data = NULL,      /* 2nd arg of func */
386         .help_str = "exit application",
387         .tokens = {        /* token list, NULL terminated */
388                 (void *)&cmd_quit_quit,
389                 NULL,
390         },
391 };
392
393 /****************/
394
395 cmdline_parse_ctx_t main_ctx[] = {
396         (cmdline_parse_inst_t *)&cmd_autotest,
397         (cmdline_parse_inst_t *)&cmd_dump,
398         (cmdline_parse_inst_t *)&cmd_dump_one,
399         (cmdline_parse_inst_t *)&cmd_set_ring,
400         (cmdline_parse_inst_t *)&cmd_quit,
401         NULL,
402 };
403