59fcc9d245635be4a9e170b3a6b76007d28c91af
[dpdk.git] / app / test / test.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 <string.h>
35 #include <stdio.h>
36 #include <stdint.h>
37 #include <stdarg.h>
38 #include <stdlib.h>
39 #include <errno.h>
40 #include <termios.h>
41 #include <ctype.h>
42 #include <sys/queue.h>
43
44 #include <cmdline_rdline.h>
45 #include <cmdline_parse.h>
46 #include <cmdline_socket.h>
47 #include <cmdline.h>
48
49 #include <rte_memory.h>
50 #include <rte_memzone.h>
51 #include <rte_tailq.h>
52 #include <rte_eal.h>
53 #include <rte_cycles.h>
54 #include <rte_log.h>
55 #include <rte_string_fns.h>
56 #ifdef RTE_LIBRTE_TIMER
57 #include <rte_timer.h>
58 #endif
59
60 #include "test.h"
61
62 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
63
64 const char *prgname; /* to be set to argv[0] */
65
66 #ifndef RTE_EXEC_ENV_BAREMETAL
67 static const char *recursive_call; /* used in linuxapp for MP and other tests */
68
69 static int
70 no_action(void){ return 0; }
71
72 static int
73 do_recursive_call(void)
74 {
75         unsigned i;
76         struct {
77                 const char *env_var;
78                 int (*action_fn)(void);
79         } actions[] =  {
80                         { "run_secondary_instances", test_mp_secondary },
81                         { "test_missing_c_flag", no_action },
82                         { "test_missing_n_flag", no_action },
83                         { "test_no_hpet_flag", no_action },
84                         { "test_whitelist_flag", no_action },
85                         { "test_invalid_b_flag", no_action },
86                         { "test_invalid_r_flag", no_action },
87 #ifdef RTE_LIBRTE_XEN_DOM0
88                         { "test_dom0_misc_flags", no_action },
89 #else
90                         { "test_misc_flags", no_action },
91 #endif
92                         { "test_memory_flags", no_action },
93                         { "test_file_prefix", no_action },
94                         { "test_no_huge_flag", no_action },
95                         { "test_ivshmem", test_ivshmem },
96         };
97
98         if (recursive_call == NULL)
99                 return -1;
100         for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
101                 if (strcmp(actions[i].env_var, recursive_call) == 0)
102                         return (actions[i].action_fn)();
103         }
104         printf("ERROR - missing action to take for %s\n", recursive_call);
105         return -1;
106 }
107 #endif
108
109 int
110 main(int argc, char **argv)
111 {
112         struct cmdline *cl;
113         int ret;
114
115         ret = rte_eal_init(argc, argv);
116         if (ret < 0)
117                 return -1;
118
119 #ifdef RTE_LIBRTE_TIMER
120         rte_timer_subsystem_init();
121 #endif
122
123         argv += ret;
124
125         prgname = argv[0];
126
127 #ifndef RTE_EXEC_ENV_BAREMETAL
128         if ((recursive_call = getenv(RECURSIVE_ENV_VAR)) != NULL)
129                 return do_recursive_call();
130 #endif
131
132 #ifdef RTE_LIBEAL_USE_HPET
133         if (rte_eal_hpet_init(1) < 0)
134 #endif
135                 RTE_LOG(INFO, APP,
136                                 "HPET is not enabled, using TSC as default timer\n");
137
138
139
140         cl = cmdline_stdin_new(main_ctx, "RTE>>");
141         if (cl == NULL) {
142                 return -1;
143         }
144         cmdline_interact(cl);
145         cmdline_stdin_exit(cl);
146
147         return 0;
148 }